From 7cf54681ea5c0c32996dfe242a495a7d1e66f373 Mon Sep 17 00:00:00 2001 From: John Gleason Date: Tue, 18 Aug 2015 19:20:42 -0500 Subject: [PATCH 1/6] support for .zip archives with unknown extensions at runtime, such as .docx, .pptx, and .idml. --- spec/fixtures/word.docx | Bin 0 -> 14641 bytes spec/zip-spec.coffee | 13 +++++++++++++ src/ls-archive.coffee | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/word.docx diff --git a/spec/fixtures/word.docx b/spec/fixtures/word.docx new file mode 100644 index 0000000000000000000000000000000000000000..5d59308f698949d89a366b8b2d0d2ad59290d14f GIT binary patch literal 14641 zcmeHub#xS4v+qn?fVjK6yAXFH?(Xic#EE-|y9;qb+}(}1D-b2b6Y?g<;BdbC*1hkq zx7Iy-rn-BkyK1WTRQ3MtUDfi^;1H+)C;$w=y8~G~m3{iy3J3tSLjnLO02nYWVLMxA z6I*9JWeh5jGS+dOx_5rH66T_j1ko@ zkWCs2wf5KW9_i2Tvfd^XskiKoMSF7`eNG5JNlg0DKUdPU4P8RdXFN03ju_f^^~mZ(%@oZgl3@hG_t?W4hNH~IAXTvXN@tF z<<6xJ;H#YxQhvZ+zAGJa2<4Puzku%r~d-+LSNX>6J=fb?!M)Qus z<*lQdmQ$kaDB7JU(IwK|xss4glZ+V1RCRj>ZhXN2alzk&6vz41F3r|BO-~Xaoga z{lB|4BuLBkFd~Lj8G5|RK&6CXJAy)A6(arkjzx}kEA)_RvaV)BLK}#p>o80#H0)@~ z`*<}}yRNINmTtBhCw?lZp)^fALIotTu9Q)lemR^V-K0-}FHYHUGp{-RjuYVe&j}BlO zhL)l}#_5drb*oJg9ePh+y8f{^v6||ICahgxQVMK&$0@-=1QR*}UXWMtQB)$K{UAXM za$KKC+@p?I41PK3y`damzs_~v)vj5c1ZlF9l!R6FR*Nm+*BL3=@%?)DfYsHh8C+JB zgu1mLvUS^s7k_sp*A3}DIncem4+;Q40(r=9uJp4L6{_giE;BxB56`{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91Bn4(NI-BT;A1a<0000& zg0y{7_>Tqz1BZZw0;vQC54xZM5u`piI2cG-NC*hf)jpu}00<;VWFjU(C=>+)XkrIc zX8*Wc7!skHE;PldQ&JW~#{gJ3bPP-^Y%+2RN-AnrHg*n9E^c8FQ894|Nhu{|6;(BL z4NW6s6H_yD3riQaVd3!!iAl+CQ&Q9N@(T)!ic3n%YU}D7-Zy?| zYVPjo?du;H92%aUnVtJMzp%KpxwXBsySIPv>GRpw^KTcISJyYUPj&$T;J=&omu0`$ zg#@w-4D=sBKtI_91akusI1&UT5fc=$paQgk0}3&-KMbl+Ty9MlED4L^DVm|<6dXD! z>n7RRlWD(M_TMus;Qz_8zYP0f*An0vI1u#bfg=I<0T1_i;go=X>EAy1*9ZRffq#AA z{|g@ge_WK827=Lna^U~@ajri{*+2LH;o+{I1^n|_lRp`s_649ynxCFL`I+&b_3%G4 za)GkW|F`P+UnTuo4*f$`5U7ynAH~r>v;U`p)*tM^XMeE&THgAzi2qbL^h3l7XqNe# z20xb({mlNK$`gLDH=zH){!6jKuM&Pu*8h<33FA)%{!{AyXF2~|_WvOT0N4kCvA00M9`$Igq=Lu|0kIKXIY6%>V!Z literal 0 HcmV?d00001 diff --git a/spec/zip-spec.coffee b/spec/zip-spec.coffee index 1b78de5..841a431 100644 --- a/spec/zip-spec.coffee +++ b/spec/zip-spec.coffee @@ -116,3 +116,16 @@ describe "zip files", -> archive.readFile(archivePath, "folder#{path.sep}", callback) waitsFor -> pathError? runs -> expect(pathError.message.length).toBeGreaterThan 0 + + describe "when the forceZip option is enabled", -> + it "returns files and folders in the docx archive", -> + zipPaths = null + callback = (error, paths) -> zipPaths = paths + archive.list(path.join(fixturesRoot, 'word.docx'), forceZip: true, callback) + waitsFor -> zipPaths? + runs -> + expect(zipPaths.length).toBe 1 + expect(zipPaths[0].path).toBe '[Content_Types].xml' + expect(zipPaths[0].isDirectory()).toBe false + expect(zipPaths[0].isFile()).toBe true + expect(zipPaths[0].isSymbolicLink()).toBe false diff --git a/src/ls-archive.coffee b/src/ls-archive.coffee index af732c3..c3f380b 100644 --- a/src/ls-archive.coffee +++ b/src/ls-archive.coffee @@ -197,7 +197,7 @@ module.exports = listTar(archivePath, options, wrapCallback(callback)) else if isGzipPath(archivePath) listGzip(archivePath, options, wrapCallback(callback)) - else if isZipPath(archivePath) + else if isZipPath(archivePath) or options.forceZip listZip(archivePath, options, wrapCallback(callback)) else callback(new Error("'#{path.extname(archivePath)}' files are not supported")) From 350e59865f5e765785f9c0e7f0c96a7e23a6eb9e Mon Sep 17 00:00:00 2001 From: John Gleason Date: Wed, 19 Aug 2015 10:42:29 -0500 Subject: [PATCH 2/6] fixed failing test --- spec/zip-spec.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/zip-spec.coffee b/spec/zip-spec.coffee index 841a431..ae6fe0e 100644 --- a/spec/zip-spec.coffee +++ b/spec/zip-spec.coffee @@ -124,7 +124,7 @@ describe "zip files", -> archive.list(path.join(fixturesRoot, 'word.docx'), forceZip: true, callback) waitsFor -> zipPaths? runs -> - expect(zipPaths.length).toBe 1 + expect(zipPaths.length).toBe 13 expect(zipPaths[0].path).toBe '[Content_Types].xml' expect(zipPaths[0].isDirectory()).toBe false expect(zipPaths[0].isFile()).toBe true From 0aca2b848a9829a717d6f8f1bbeae68b617f6844 Mon Sep 17 00:00:00 2001 From: John Gleason Date: Sun, 6 Sep 2015 11:53:54 -0500 Subject: [PATCH 3/6] instance configurable custom extension mappings --- .idea/.name | 1 + .idea/jsLibraryMappings.xml | 6 + .../node_ls_archive_node_modules.xml | 14 + .idea/misc.xml | 14 + .idea/modules.xml | 8 + .idea/node-ls-archive.iml | 9 + .idea/vcs.xml | 6 + .idea/watcherTasks.xml | 4 + .idea/workspace.xml | 306 ++++++++++++++++++ spec/fixtures/one-file.customZip | Bin 0 -> 172 bytes spec/zip-spec.coffee | 36 ++- src/ls-archive.coffee | 39 ++- 12 files changed, 417 insertions(+), 26 deletions(-) create mode 100644 .idea/.name create mode 100644 .idea/jsLibraryMappings.xml create mode 100644 .idea/libraries/node_ls_archive_node_modules.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/node-ls-archive.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/watcherTasks.xml create mode 100644 .idea/workspace.xml create mode 100644 spec/fixtures/one-file.customZip diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..0029bc9 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +node-ls-archive \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..85a9932 --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/libraries/node_ls_archive_node_modules.xml b/.idea/libraries/node_ls_archive_node_modules.xml new file mode 100644 index 0000000..f9044f6 --- /dev/null +++ b/.idea/libraries/node_ls_archive_node_modules.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..19f74da --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c18251e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/node-ls-archive.iml b/.idea/node-ls-archive.iml new file mode 100644 index 0000000..d23c7bc --- /dev/null +++ b/.idea/node-ls-archive.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/watcherTasks.xml b/.idea/watcherTasks.xml new file mode 100644 index 0000000..4c417c4 --- /dev/null +++ b/.idea/watcherTasks.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..a175196 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,306 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1441552913255 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spec/fixtures/one-file.customZip b/spec/fixtures/one-file.customZip new file mode 100644 index 0000000000000000000000000000000000000000..c59cd1dae6537a6494cd52d92df37ace024f6d36 GIT binary patch literal 172 zcmWIWW@h1H0D)V5y-o@SR%UEKHVAVt$S|a3=A`PCRFs5 waitsFor -> pathError? runs -> expect(pathError.message.length).toBeGreaterThan 0 + describe "listing when custom extensions are added", -> + it "lists files and folders in the docx archive", -> + zipPaths = null + callback = (error, paths) -> zipPaths = paths + archive.configureExtensions(zip: ['.docx']) + archive.list(path.join(fixturesRoot, 'word.docx'), forceZip: true, callback) + waitsFor -> zipPaths? + runs -> + expect(zipPaths.length).toBe 13 + expect(zipPaths[0].path).toBe '[Content_Types].xml' + expect(zipPaths[0].isDirectory()).toBe false + expect(zipPaths[0].isFile()).toBe true + expect(zipPaths[0].isSymbolicLink()).toBe false + describe ".readFile()", -> describe "when the path exists in the archive", -> it "calls back with the contents of the given path", -> @@ -117,15 +131,13 @@ describe "zip files", -> waitsFor -> pathError? runs -> expect(pathError.message.length).toBeGreaterThan 0 - describe "when the forceZip option is enabled", -> - it "returns files and folders in the docx archive", -> - zipPaths = null - callback = (error, paths) -> zipPaths = paths - archive.list(path.join(fixturesRoot, 'word.docx'), forceZip: true, callback) - waitsFor -> zipPaths? - runs -> - expect(zipPaths.length).toBe 13 - expect(zipPaths[0].path).toBe '[Content_Types].xml' - expect(zipPaths[0].isDirectory()).toBe false - expect(zipPaths[0].isFile()).toBe true - expect(zipPaths[0].isSymbolicLink()).toBe false + describe "reading when custom extensions are added", -> + it "calls back with the contents of the given path", -> + archivePath = path.join(fixturesRoot, 'one-file.customZip') + pathContents = null + callback = (error, contents) -> pathContents = contents + archive.configureExtensions(zip: ['.customZip']) + archive.readFile(archivePath, 'file.txt', callback) + waitsFor -> pathContents? + runs -> expect(pathContents.toString()).toBe 'hello\n' + diff --git a/src/ls-archive.coffee b/src/ls-archive.coffee index c3f380b..72af407 100644 --- a/src/ls-archive.coffee +++ b/src/ls-archive.coffee @@ -172,43 +172,54 @@ readEntry = (entry, callback) -> entry.on 'data', (data) -> contents.push(data) entry.on 'end', -> callback(null, Buffer.concat(contents)) -isTarPath = (archivePath) -> - path.extname(archivePath) is '.tar' +isTarPath = (archivePath, extensions) -> + path.extname(archivePath) in extensions -isZipPath = (archivePath) -> +isZipPath = (archivePath, extensions) -> extension = path.extname(archivePath) - extension in ['.epub', '.jar', '.love', '.war', '.zip', '.egg', '.whl', '.xpi'] + extension in extensions -isGzipPath = (archivePath) -> - path.extname(archivePath) is '.tgz' or - path.extname(path.basename(archivePath, '.gz')) is '.tar' +isGzipPath = (archivePath, extensions) -> + path.extname(archivePath) in extensions.gzip or + path.extname(path.basename(archivePath, '.gz')) in extensions.tar module.exports = + + extensions: + zip: ['.epub', '.jar', '.love', '.war', '.zip', '.egg', '.whl', '.xpi'] + tar: ['.tar'] + gzip: ['.tgz'] + + configureExtensions: (addlExtensions) -> + @extensions.zip.push(addlExtensions.zip...) + @extensions.tar.push(addlExtensions.tar...) + @extensions.gzip.push(addlExtensions.gzip...) + isPathSupported: (archivePath) -> return false unless archivePath - isTarPath(archivePath) or isZipPath(archivePath) or isGzipPath(archivePath) + isTarPath(archivePath, @extensions.tar) or isZipPath(archivePath, @extensions.zip) or isGzipPath(archivePath, @extensions) list: (archivePath, options={}, callback) -> if typeof options is 'function' callback = options options = {} - if isTarPath(archivePath) + if isTarPath(archivePath, @extensions.tar) listTar(archivePath, options, wrapCallback(callback)) - else if isGzipPath(archivePath) + else if isGzipPath(archivePath, @extensions) listGzip(archivePath, options, wrapCallback(callback)) - else if isZipPath(archivePath) or options.forceZip + else if isZipPath(archivePath, @extensions.zip) listZip(archivePath, options, wrapCallback(callback)) else callback(new Error("'#{path.extname(archivePath)}' files are not supported")) undefined readFile: (archivePath, filePath, callback) -> - if isTarPath(archivePath) + if isTarPath(archivePath, @extensions.tar) readFileFromTar(archivePath, filePath, wrapCallback(callback)) - else if isGzipPath(archivePath) + else if isGzipPath(archivePath, @extensions) readFileFromGzip(archivePath, filePath, wrapCallback(callback)) - else if isZipPath(archivePath) + else if isZipPath(archivePath, @extensions.zip) readFileFromZip(archivePath, filePath, wrapCallback(callback)) else callback(new Error("'#{path.extname(archivePath)}' files are not supported")) From fec708ccbb0314d0600682d3503c61008f941eec Mon Sep 17 00:00:00 2001 From: John Gleason Date: Sun, 6 Sep 2015 11:55:37 -0500 Subject: [PATCH 4/6] removing .idea files' --- .gitignore | 1 + .idea/.name | 1 - .idea/jsLibraryMappings.xml | 6 - .../node_ls_archive_node_modules.xml | 14 - .idea/misc.xml | 14 - .idea/modules.xml | 8 - .idea/node-ls-archive.iml | 9 - .idea/vcs.xml | 6 - .idea/watcherTasks.xml | 4 - .idea/workspace.xml | 306 ------------------ 10 files changed, 1 insertion(+), 368 deletions(-) delete mode 100644 .idea/.name delete mode 100644 .idea/jsLibraryMappings.xml delete mode 100644 .idea/libraries/node_ls_archive_node_modules.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/node-ls-archive.iml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/watcherTasks.xml delete mode 100644 .idea/workspace.xml diff --git a/.gitignore b/.gitignore index 23b40b5..ecf23aa 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ lib/ npm-debug.log .node-version .DS_Store +.idea \ No newline at end of file diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 0029bc9..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -node-ls-archive \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml deleted file mode 100644 index 85a9932..0000000 --- a/.idea/jsLibraryMappings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/libraries/node_ls_archive_node_modules.xml b/.idea/libraries/node_ls_archive_node_modules.xml deleted file mode 100644 index f9044f6..0000000 --- a/.idea/libraries/node_ls_archive_node_modules.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 19f74da..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index c18251e..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/node-ls-archive.iml b/.idea/node-ls-archive.iml deleted file mode 100644 index d23c7bc..0000000 --- a/.idea/node-ls-archive.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/watcherTasks.xml b/.idea/watcherTasks.xml deleted file mode 100644 index 4c417c4..0000000 --- a/.idea/watcherTasks.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index a175196..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,306 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1441552913255 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From df3d8680477bf5ecb032d8f1a75b9a3122f4a195 Mon Sep 17 00:00:00 2001 From: John Gleason Date: Sun, 6 Sep 2015 12:18:01 -0500 Subject: [PATCH 5/6] Merging extension configurability with upstream changes. --- src/ls-archive.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ls-archive.coffee b/src/ls-archive.coffee index 72af407..0d34795 100644 --- a/src/ls-archive.coffee +++ b/src/ls-archive.coffee @@ -186,7 +186,7 @@ isGzipPath = (archivePath, extensions) -> module.exports = extensions: - zip: ['.epub', '.jar', '.love', '.war', '.zip', '.egg', '.whl', '.xpi'] + zip: ['.epub', '.jar', '.love', '.war', '.zip', '.egg', '.whl', '.xpi', '.nupkg'] tar: ['.tar'] gzip: ['.tgz'] From c627e59897ac929de20879388e92fc288ba08ed5 Mon Sep 17 00:00:00 2001 From: John Gleason Date: Sun, 6 Sep 2015 12:22:30 -0500 Subject: [PATCH 6/6] Documentation for extension configuration --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index a5671f4..621a31c 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,14 @@ Buffer contents of the uncompressed paths. The `callback` gets two arguments `callback` - The function to call after reading completes with an error or the Buffer contents. +### archive.configureExtensions(additionalExtensions) + +Adds custom file extensions to zip, tar, and/or gzip handling to support archives with atypical extensions. + +`additionalExtensions` - Object literal with string arrays for zip, tar, and gzip + +Example: `archive.configureExtensions(zip: ['.docx'])` + ### ArchiveEntry Class representing a path entry inside an archive file.