This is a creation in Article, where the information may have evolved or changed.
The node version of the recent project has been upgraded to 8.x, resulting in the process of packaging a folder failed, before using the Archiver library, in the node6.x version of the problem, but in the node8.x version of the following exception:
Typeerror:cannot Read property ' Pipescount ' of undefined at Module.exports.Readable.pipe (_stream_readable.js:545:16) At Module.exports.ziparchiveoutputstream._smartstream (C:\Workbench\flood\node_modules\compress-commons\lib\ archivers\zip\zip-archive-output-stream.js:184:11) at Module.exports.ziparchiveoutputstream._appendstream (c \ WORKBENCH\FLOOD\NODE_MODULES\COMPRESS-COMMONS\LIB\ARCHIVERS\ZIP\ZIP-ARCHIVE-OUTPUT-STREAM.JS:96:20) at Module.exports.ArchiveOutputStream.entry (C:\Workbench\flood\node_modules\compress-commons\lib\archivers\ ARCHIVE-OUTPUT-STREAM.JS:88:10) at Module.exports.ZipStream.entry (C:\Workbench\flood\node_modules\zip-stream\ index.js:138:49) at Zip.append (c:\workbench\flood\node_modules\archiver\lib\plugins\zip.js:53:15) at Archiver._mod Uleappend (c:\workbench\flood\node_modules\archiver\lib\core.js:172:16) at Archiver._onqueuetask (C:\Workbench\ Flood\node_modules\archiver\lib\core.js:370:8) at C:\Workbench\flood\node_modules\async\dist\async.js:4069:9 at Process (c:\workbench\flood\node_modules\async\dist\async.js:2317:17)
Also try to zip-archiver and other similar library found also the same results, as if the bottom is also based on archiver to do, but only change the idea: the use of Golang to write their own, and then call node execfile to execute.
Of course, using Golang to implement ZIP compression code or more, so in order to save time, from GitHub to find a packaged library Https://github.com/mholt/archiver, The code is still very simple to implement:
package mainimport ( "flag" "fmt" "github.com/mholt/archiver")func main() { srcDir := flag.String("in", "", "target file/dir") outDir := flag.String("out", "", "dest dir") flag.Parse() // fmt.Println("srcDir", *srcDir) // fmt.Println("outDir", *outDir) err := archiver.Zip.Make(*outDir, []string{*srcDir}) if err != nil { panic(err) }}
Save the code as ZIP.GO, then compile the go build zip.go
zip.exe file and make the call in node:
// 调用 zip.exeexecFile('./build/tools/zip.exe', ['-in', './dists/target/', '-out', './dists/dest.zip'], (error, stdout, stderr) => { if (error) throw error; console.log('archive file/dir success');});
It is important to note that the format of the arguments passed in by execfile is executed before I write the
['-in ./dists/target/', '-out ./dists/dest.zip']
Always error, thought is the problem of the code, and later to see the document only know that the parameters of the format of the problem, should be like the following to pass in before you can:
['-key1', 'value1', '-key2', 'value2',...]
After the change, running on the Windows platform is no problem, the file can be compressed properly.