From e22af55452991e796c20e6f1e4095fcb438d05a4 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Demonte Date: Mon, 2 Jan 2017 23:42:54 +0100 Subject: [PATCH] Distinguish files & directories in "list" --- README.md | 1 + lib/list.js | 23 +++++++++++++++-------- package.json | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8a75580..830ea5f 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ Default overwrite mode is set to "Overwrite All existing files without prompt" u * `data.method` string * `data.solid` string * `data.blocks` number + * `data.directories` array (same as `data.files`) * `data.files` array * `data.files[].attr` string diff --git a/lib/list.js b/lib/list.js index c653c89..0e04e37 100644 --- a/lib/list.js +++ b/lib/list.js @@ -21,10 +21,11 @@ function ArchiveInfo() { this.method = undefined; this.solid = undefined; this.blocks = undefined; + this.directories = []; this.files = []; } -function ArchiveFile() { +function ArchiveEntry() { this.attr = undefined; this.compressed = undefined; this.date = undefined; @@ -54,13 +55,19 @@ module.exports = function (archive, switches) { lines.forEach(function (line) { var res = regex.exec(line); if (res) { - var file = new ArchiveFile(); - file.date = new Date(res[1]); - file.attr = res[2]; - file.size = parseInt(res[3], 10) || 0; - file.compressed = parseInt(res[4]) || 0; - file.name = res[5]; - info.files.push(file); + var entry = new ArchiveEntry(); + entry.date = new Date(res[1]); + entry.attr = res[2]; + entry.size = parseInt(res[3], 10) || 0; + entry.compressed = parseInt(res[4]) || 0; + entry.name = res[5]; + + if (~(entry.attr || '').indexOf('D')) { + info.directories.push(entry); + } else { + info.files.push(entry); + } + } else { properties.some(function (property) { if (tools.start(line, property + ' = ')) { diff --git a/package.json b/package.json index b8239b4..83e94fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "p7zip", - "version": "2.0.0", + "version": "2.1.0", "description": "A node wrapper for 7z including latest version of 7za", "main": "index.js", "scripts": {