blob: 05efce152ec032224789a38af7883e1f35f569f0 [file] [log] [blame]
(function() {
var LineTransform, Stream,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Stream = require('stream');
LineTransform = (function(_super) {
__extends(LineTransform, _super);
function LineTransform(options) {
this.savedR = null;
LineTransform.__super__.constructor.call(this, options);
}
LineTransform.prototype._transform = function(chunk, encoding, done) {
var hi, last, lo;
lo = 0;
hi = 0;
if (this.savedR) {
if (chunk[0] !== 0x0a) {
this.push(this.savedR);
}
this.savedR = null;
}
last = chunk.length - 1;
while (hi <= last) {
if (chunk[hi] === 0x0d) {
if (hi === last) {
this.savedR = chunk.slice(last);
break;
} else if (chunk[hi + 1] === 0x0a) {
this.push(chunk.slice(lo, hi));
lo = hi + 1;
}
}
hi += 1;
}
if (hi !== lo) {
this.push(chunk.slice(lo, hi));
}
done();
};
LineTransform.prototype._flush = function(done) {
if (this.savedR) {
this.push(this.savedR);
}
return done();
};
return LineTransform;
})(Stream.Transform);
module.exports = LineTransform;
}).call(this);