我想知道流是否可以多次管道传输?根据文档,我看不到任何直接答案,这是我的代码示例。
var request = require('request');
var MemoryStream = require('memorystream');
var download = (options, stream) => {
return new Promise((resolve, reject) => {
request(options).pipe(stream).on('finish', () => {
resolve();
}).on('error', error => {
reject(error);
});
});
};
(async () => {
let stream = new MemoryStream(null, {
readable: true,
writable: true
});
let total = 8000, block = 3000;// will fetch by HEAD method
for (let i = 0; i < 3; i++) {
console.log(i);
let from = i * block;
let to = Math.min(total - 1, from + block - 1);
await download({
url: 'https://www.website.com/logo.png',
headers: {
'Range': 'bytes=' + from + '-' + to
}
}, stream);
console.log(i + ' done');
}
})();
输出就像“ 0 0 done 1”,那么什么也不会发生,没有错误,所以我想我使用的是错误的内存流?