1

我用代码在nodejs中压缩了一个文件夹:

fstream = require('fstream'),
tar = require('tar'),
zlib = require('zlib');
fstream.Reader(toZipDetails) /* Read the source directory */
         .pipe(tar.Pack()) /* Convert the directory to a .tar file */
         .pipe(zlib.Gzip()) /* Compress the .tar file */
         .pipe(fstream.Writer(zipOutDetails)); /* Give the output file name */

然后我解压缩它:

fs.createReadStream(inFileName)
                .pipe(zlib.Gunzip())
                .pipe(tar.Extract({ path: "C:\\temp\\extract" }))
                .on("end", function () {
                    alert("done");
                });

文件夹名称toZip与 file a.txt

我想要一个文件夹中带有 a.txt 的 toZipextract文件夹,但是

我有一个a.txt file in extract folder

我怎样才能得到toZip文件夹?

4

1 回答 1

0

你可以试试 :

var unzip = require('unzip')
var fs = require('fs');

fs.createReadStream('<<.zip folder path>>').pipe(unzip.Extract({ path: <<save unzipped data path>> }));
于 2018-11-13T06:31:46.560 回答