forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode-stream.js
More file actions
32 lines (26 loc) · 820 Bytes
/
decode-stream.js
File metadata and controls
32 lines (26 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// decode-stream.js
exports.createDecodeStream = DecodeStream;
var util = require("util");
var Transform = require("stream").Transform;
var DecodeBuffer = require("./decode-buffer").DecodeBuffer;
util.inherits(DecodeStream, Transform);
var DEFAULT_OPTIONS = {objectMode: true};
function DecodeStream(options) {
if (!(this instanceof DecodeStream)) return new DecodeStream(options);
if (options) {
options.objectMode = true;
} else {
options = DEFAULT_OPTIONS;
}
Transform.call(this, options);
var stream = this;
var decoder = this.decoder = new DecodeBuffer(options);
decoder.push = function(chunk) {
stream.push(chunk);
};
}
DecodeStream.prototype._transform = function(chunk, encoding, callback) {
this.decoder.write(chunk);
this.decoder.flush();
if (callback) callback();
};