stream footer

This commit is contained in:
Emily Hou 2018-06-25 11:26:48 -07:00
parent a4cf46c0eb
commit 9d04514f8e
3 changed files with 36 additions and 8 deletions

23
server/streamparser.js Normal file
View file

@ -0,0 +1,23 @@
const { Transform } = require('stream');
class StreamParser extends Transform {
constructor() {
super();
let res;
this.promise = new Promise(resolve => {
res = resolve;
});
this.res = res;
}
_transform(chunk, encoding, callback) {
if (chunk.byteLength === 1 && chunk[0] === 0) {
this.res();
} else {
this.push(chunk);
}
callback();
}
}
module.exports = StreamParser;