|
@@ -310,6 +310,33 @@ const progress_stream = (source, { total, progress_callback }) => {
|
|
|
return stream;
|
|
|
}
|
|
|
|
|
|
+class SizeLimitingStream extends Transform {
|
|
|
+ constructor(options, { limit }) {
|
|
|
+ super(options);
|
|
|
+ this.limit = limit;
|
|
|
+ this.loaded = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ _transform(chunk, encoding, callback) {
|
|
|
+ this.loaded += chunk.length;
|
|
|
+ if ( this.loaded > this.limit ) {
|
|
|
+ const excess = this.loaded - this.limit;
|
|
|
+ chunk = chunk.slice(0, chunk.length - excess);
|
|
|
+ }
|
|
|
+ this.push(chunk);
|
|
|
+ if ( this.loaded >= this.limit ) {
|
|
|
+ this.end();
|
|
|
+ }
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const size_limit_stream = (source, { limit }) => {
|
|
|
+ const stream = new SizeLimitingStream({}, { limit });
|
|
|
+ source.pipe(stream);
|
|
|
+ return stream;
|
|
|
+}
|
|
|
+
|
|
|
class StuckDetectorStream extends Transform {
|
|
|
constructor(options, {
|
|
|
timeout,
|
|
@@ -459,6 +486,7 @@ module.exports = {
|
|
|
logging_stream,
|
|
|
offset_write_stream,
|
|
|
progress_stream,
|
|
|
+ size_limit_stream,
|
|
|
stuck_detector_stream,
|
|
|
string_to_stream,
|
|
|
chunk_stream,
|