function streamToBuffer(stream) { return new Promise((resolve, reject) => { let buffers = []; stream.on('error', reject); stream.on('data', (data) => buffers.push(data)) stream.on('end', () => resolve(Buffer.concat(buffers)) }); }
let Duplex = require('stream').Duplex; function bufferToStream(buffer) { let stream = new Duplex(); stream.push(buffer); stream.push(null); return stream; }