You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
906 B
37 lines
906 B
// encode-stream.js |
|
|
|
exports.createEncodeStream = EncodeStream; |
|
|
|
var util = require("util"); |
|
var Transform = require("stream").Transform; |
|
var EncodeBuffer = require("./encode-buffer").EncodeBuffer; |
|
|
|
util.inherits(EncodeStream, Transform); |
|
|
|
var DEFAULT_OPTIONS = {objectMode: true}; |
|
|
|
function EncodeStream(options) { |
|
if (!(this instanceof EncodeStream)) return new EncodeStream(options); |
|
if (options) { |
|
options.objectMode = true; |
|
} else { |
|
options = DEFAULT_OPTIONS; |
|
} |
|
Transform.call(this, options); |
|
|
|
var stream = this; |
|
var encoder = this.encoder = new EncodeBuffer(options); |
|
encoder.push = function(chunk) { |
|
stream.push(chunk); |
|
}; |
|
} |
|
|
|
EncodeStream.prototype._transform = function(chunk, encoding, callback) { |
|
this.encoder.write(chunk); |
|
if (callback) callback(); |
|
}; |
|
|
|
EncodeStream.prototype._flush = function(callback) { |
|
this.encoder.flush(); |
|
if (callback) callback(); |
|
};
|
|
|