mirror of
https://gitlab.com/timvisee/send.git
synced 2024-11-10 21:22:35 +01:00
22 lines
448 B
JavaScript
22 lines
448 B
JavaScript
const { Transform } = require('stream');
|
|
|
|
class Limiter extends Transform {
|
|
constructor(limit) {
|
|
super();
|
|
this.limit = limit;
|
|
this.length = 0;
|
|
}
|
|
|
|
_transform(chunk, encoding, callback) {
|
|
this.length += chunk.length;
|
|
this.push(chunk);
|
|
if (this.length > this.limit) {
|
|
console.error('LIMIT', this.length, this.limit);
|
|
return callback(new Error('limit'));
|
|
}
|
|
callback();
|
|
}
|
|
}
|
|
|
|
module.exports = Limiter;
|