UNPKG

adbkit

Version:

A pure Node.js client for the Android Debug Bridge.

56 lines (47 loc) 1.44 kB
var LineTransform, Stream, extend = 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; }, hasProp = {}.hasOwnProperty; Stream = require('stream'); LineTransform = (function(superClass) { extend(LineTransform, superClass); 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;