Last change
on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
963 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | 'use strict'
|
---|
| 2 | var util = require('util')
|
---|
| 3 | var stream = require('readable-stream')
|
---|
| 4 | var delegate = require('delegates')
|
---|
| 5 | var Tracker = require('./tracker.js')
|
---|
| 6 |
|
---|
| 7 | var 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 | }
|
---|
| 14 | util.inherits(TrackerStream, stream.Transform)
|
---|
| 15 |
|
---|
| 16 | function delegateChange (trackerStream) {
|
---|
| 17 | return function (name, completion, tracker) {
|
---|
| 18 | trackerStream.emit('change', name, completion, trackerStream)
|
---|
| 19 | }
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | TrackerStream.prototype._transform = function (data, encoding, cb) {
|
---|
| 23 | this.tracker.completeWork(data.length ? data.length : 1)
|
---|
| 24 | this.push(data)
|
---|
| 25 | cb()
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | TrackerStream.prototype._flush = function (cb) {
|
---|
| 29 | this.tracker.finish()
|
---|
| 30 | cb()
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | delegate(TrackerStream.prototype, 'tracker')
|
---|
| 34 | .method('completed')
|
---|
| 35 | .method('addWork')
|
---|
| 36 | .method('finish')
|
---|
Note:
See
TracBrowser
for help on using the repository browser.