mirror of
https://github.com/nodemailer/wildduck.git
synced 2024-12-26 09:50:47 +08:00
26 lines
581 B
JavaScript
26 lines
581 B
JavaScript
'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();
|
|
}
|
|
this.options.ttlcounter(this.options.key, this.bytes, this.options.maxBytes, false, () => done());
|
|
}
|
|
}
|
|
|
|
module.exports = LimitedFetch;
|