mirror of
https://github.com/HeyPuter/puter.git
synced 2026-02-05 21:38:41 -06:00
dev: add utility to measure bytes in a stream
This commit is contained in:
@@ -341,6 +341,27 @@ const size_limit_stream = (source, { limit }) => {
|
||||
return stream;
|
||||
}
|
||||
|
||||
class SizeMeasuringStream extends Transform {
|
||||
constructor(options, probe) {
|
||||
super(options);
|
||||
this.probe = probe;
|
||||
this.loaded = 0;
|
||||
}
|
||||
|
||||
_transform(chunk, encoding, callback) {
|
||||
this.loaded += chunk.length;
|
||||
probe.amount = this.loaded;
|
||||
this.push(chunk);
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
const size_measure_stream = (source, probe = {}) => {
|
||||
const stream = new SizeMeasuringStream({}, probe);
|
||||
source.pipe(stream);
|
||||
return stream;
|
||||
}
|
||||
|
||||
class StuckDetectorStream extends Transform {
|
||||
constructor(options, {
|
||||
timeout,
|
||||
|
||||
Reference in New Issue
Block a user