wildduck/lib/limited-fetch.js

27 lines
581 B
JavaScript
Raw Normal View History

2017-11-12 21:13:32 +08:00
'use strict';
const Transform = require('stream').Transform;
class LimitedFetch extends Transform {
constructor(options) {
super();
this.options = options || {};
this.bytes = 0;
}
_transform(chunk, encoding, done) {
this.bytes += chunk.length;
this.push(chunk);
done();
}
_flush(done) {
if (!this.options.maxBytes) {
return done();
}
2017-11-13 21:27:37 +08:00
this.options.ttlcounter(this.options.key, this.bytes, this.options.maxBytes, false, () => done());
2017-11-12 21:13:32 +08:00
}
}
module.exports = LimitedFetch;