是什么 ? | : | a small node module that pipes streams together and destroys all of them if one of them closes. |
开发语言 | : | Node.js |
源码仓库 | : | https://github.com/mafintosh/pump |
包管理器 | 安装命令 |
---|---|
npm | npm install pump --save |
yarn | yarn add pump |
Stream stream = pump(streams: Array, callback?: function(error));
Stream stream = pump(...streams: Array, callback?: function(error));
使用示例:
const pump = require('pump');
const fs = require('fs');
const zlib = require('zlib');
pump(
fs.createReadStream('archive.tar'),
zlib.createGzip(),
fs.createWriteStream('archive.tar.gz'),
(err) => {
if (err) {
console.error('Pipeline failed.', err);
} else {
console.log('Pipeline succeeded.');
}
}
);
注意:Node.js Runtime 10增加了stream.pipeline方法,用来代替该模块。
const { pipeline } = require('stream');
const fs = require('fs');
const zlib = require('zlib');
pipeline(
fs.createReadStream('archive.tar'),
zlib.createGzip(),
fs.createWriteStream('archive.tar.gz'),
(err) => {
if (err) {
console.error('Pipeline failed.', err);
} else {
console.log('Pipeline succeeded.');
}
}
);