我发现zlib返回了一个可读流,该流随后可通过管道传递到多个其他流中。因此,我执行以下 *** 作来解决上述问题:
var sourceFileStream = fs.createReadStream(sourceFile);// Even though we could chain like// sourceFileStream.pipe(zlib.createGzip()).pipe(response);// we need a stream with a gzipped data to pipe to two// other streams.var gzip = sourceFileStream.pipe(zlib.createGzip());// This will pipe the gzipped data to response object// and automatically close the response object.gzip.pipe(response);// Then I can pipe the gzipped data to a file.gzip.pipe(fs.createWriteStream(targetFilePath));
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)