UNPKG

837 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.ReadFromBuffers = void 0;
4const stream_1 = require("stream");
5class ReadFromBuffers extends stream_1.Readable {
6 constructor(options) {
7 super(options);
8 this.numBuffersRead = 0;
9 this.buffersToRead = options.buffers;
10 this.errorAfter = typeof options.errorAfter === "number" ? options.errorAfter : -1;
11 }
12 _read() {
13 if (this.errorAfter !== -1 && this.errorAfter === this.numBuffersRead) {
14 this.emit("error", new Error("Mock Error"));
15 return;
16 }
17 if (this.numBuffersRead >= this.buffersToRead.length) {
18 return this.push(null);
19 }
20 return this.push(this.buffersToRead[this.numBuffersRead++]);
21 }
22}
23exports.ReadFromBuffers = ReadFromBuffers;