1 |
|
2 | const Transform = require("stream").Transform;
|
3 |
|
4 | class 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 : new Buffer(data, encoding));
|
12 | this.push(buffer);
|
13 | next();
|
14 | }
|
15 |
|
16 | _flush(next) {
|
17 | this.push(new Buffer("\r\n", 'ascii'));
|
18 | this.push(new Buffer("--" + this.boundary + "--", 'ascii'));
|
19 | return next();
|
20 | }
|
21 | }
|
22 |
|
23 | module.exports = UploadStream;
|