source: trip-planner-front/node_modules/are-we-there-yet/tracker-stream.js@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 963 bytes
Line 
1'use strict'
2var util = require('util')
3var stream = require('readable-stream')
4var delegate = require('delegates')
5var Tracker = require('./tracker.js')
6
7var TrackerStream = module.exports = function (name, size, options) {
8 stream.Transform.call(this, options)
9 this.tracker = new Tracker(name, size)
10 this.name = name
11 this.id = this.tracker.id
12 this.tracker.on('change', delegateChange(this))
13}
14util.inherits(TrackerStream, stream.Transform)
15
16function delegateChange (trackerStream) {
17 return function (name, completion, tracker) {
18 trackerStream.emit('change', name, completion, trackerStream)
19 }
20}
21
22TrackerStream.prototype._transform = function (data, encoding, cb) {
23 this.tracker.completeWork(data.length ? data.length : 1)
24 this.push(data)
25 cb()
26}
27
28TrackerStream.prototype._flush = function (cb) {
29 this.tracker.finish()
30 cb()
31}
32
33delegate(TrackerStream.prototype, 'tracker')
34 .method('completed')
35 .method('addWork')
36 .method('finish')
Note: See TracBrowser for help on using the repository browser.