async-multipart-iterator
Iterate the parts of an RFC 1528 multipart (multipart/mixed, multipart/alternative, multipart/digest, multipart/parallel) document, sequentially producing a header and a body iterator for each part.
Quick example
'use strict'
const someInputFile = 'something';
const someOutputDir = '/tmp/something';
const boundary = 'cd67d1a112145bdcfdce0c5839b36b53';
const fs = require('fs');
const {multipartIterator} = require('async-multipart-iterator');
async function main() {
const input = fs.createReadStream(someInputFile);
let count = 0;
for await (let [header, bodyIterator] of multipartIterator(boundary, input)) {
console.log(header)
const stream = fs.createWriteStream(`{someOutputFile}/${count++}`);
for await (let chunk of bodyIterator) {
await new Promise( (res,rej) => stream.write(chunk, res));
}
await new Promise( (res,rej) => stream.end(res));
}
}
main().catch(console.error)