X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=node_modules%2Flinerstream%2Findex.js;fp=node_modules%2Flinerstream%2Findex.js;h=407be32a758b521d5afe98367082867e489839f2;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/node_modules/linerstream/index.js b/node_modules/linerstream/index.js new file mode 100644 index 000000000..407be32a7 --- /dev/null +++ b/node_modules/linerstream/index.js @@ -0,0 +1,32 @@ +var Transform = require('stream').Transform +var util = require('util') +var os = require('os') + +function Liner(opts) { + opts = opts || {} + opts.objectMode = true + Transform.call(this, opts) +} + +util.inherits(Liner, Transform) +Liner.prototype._transform = function transform(chunk, encoding, done) { + var data = chunk.toString() + if (this._lastLineData) { + data = this._lastLineData + data + } + var lines = data.split(os.EOL) + this._lastLineData = lines.splice(lines.length - 1, 1)[0] + + lines.forEach(this.push.bind(this)) + done() +} + +Liner.prototype._flush = function flush(done) { + if (this._lastLineData) { + this.push(this._lastLineData) + } + this._lastLineData = null + done() +} + +module.exports = Liner