multipart-write-stream
v1.0.14
Published
multipart write stream
Downloads
4
Readme
multipart write stream
Install
npm i multipart-write-stream -S
Usage
addPart
return Promse
let stream = new multipartStream({
boundary: "cooder"
});
stream.pipe(process.stdout, {
end: false
});
stream.on('finish', () => {
console.log('all finish');
});
let data = [{
key: "test",
},
{
key: "test test"
},
{
key: "test test test"
}
];
for (let i = 0; i < data.length - 1; i++) {
stream.addPart({
headers: {
'Content-Disposition': 'form-data; name=metadata',
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify(data[i]),
}).then(function() {
console.log('success');
}).catch(function(error) {
console.error('response failed:%s', error.stack);
});
}
let delayStream = new PassThrough();
setTimeout(() => {
delayStream.end('delay stream test');
}, 5000);
stream.addPart({
headers: {
'Content-Disposition': 'form-data; name=metadata',
'Content-Type': 'application/json; charset=utf-8',
},
body: delayStream,
}).then(() => {
// console.log('stream write finish');
});
stream.addPart({
headers: {
'Content-Disposition': 'form-data; name=metadata',
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify(data[data.length - 1]),
}).then(function() {
console.debug('success');
}, true).catch(function(error) {
logger.error('failed:%s', error.stack);
});
body: string array or stream
License
The MIT License