multipart-write-stream

1.0.14 • Public • Published

multipart write stream

NPM version npm download David deps

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

Readme

Keywords

none

Package Sidebar

Install

npm i multipart-write-stream

Weekly Downloads

0

Version

1.0.14

License

MIT

Unpacked Size

10.5 kB

Total Files

4

Last publish

Collaborators

  • imcooder