aboutsummaryrefslogtreecommitdiff
path: root/node_modules/last-line-stream/index.js
blob: 2ecc37adfb127a388b3a1be9695efa7fc45cfedc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'use strict';
var through2 = require('through2');
var StringDecoder = require('string_decoder').StringDecoder;
var createTracker = require('./tracker');

module.exports = function (pipeDestination) {
	var decoder = new StringDecoder();
	var tracker = createTracker();

	var stream = through2(function (chunk, enc, cb) {
		tracker.update(decoder.write(chunk));
		cb(null, chunk);
	});

	Object.defineProperty(stream, 'lastLine', {
		get: tracker.lastLine
	});

	if (pipeDestination) {
		stream.pipe(pipeDestination);
	}

	return stream;
};