UNPKG

512 BJavaScriptView Raw
1
2const Transform = require("stream").Transform;
3
4class UploadStream extends Transform {
5 constructor(options) {
6 super();
7 this.boundary = options.boundary;
8 }
9
10 _transform(data, encoding, next) {
11 let buffer = ((Buffer.isBuffer(data)) ? data : Buffer.from(data, encoding));
12 this.push(buffer);
13 next();
14 }
15
16 _flush(next) {
17 this.push(Buffer.from("\r\n", 'ascii'));
18 this.push(Buffer.from("--" + this.boundary + "--", 'ascii'));
19 return next();
20 }
21}
22
23module.exports = UploadStream;