Path: blob/master/src/middlewares/utils/StreamWriter.js
115 views
const stream = require('stream');12module.exports = class StreamWriter extends stream.Writable {3constructor(...args) {4super(...args);5this.writable = true;6this.bytes = 0;7this.raw = [];8}910write(buf) {11if(buf instanceof Buffer) {12this.raw.push(buf);13this.bytes += buf.length;14} else {15const chunk = Buffer.from(buf);16this.write(chunk);17}18}1920end(buf) {21if (buf) this.write(buf);2223this.writable = false;24this.body = Buffer.concat(this.raw);25super.end(...arguments);26}27};282930