Files
Foundry-VTT-Docker/resources/app/node_modules/@smithy/eventstream-serde-universal/dist-es/fixtures/MockEventMessageSource.fixture.js

31 lines
1013 B
JavaScript
Raw Normal View History

2025-01-04 00:34:03 +01:00
import { Readable } from "stream";
export class MockEventMessageSource extends Readable {
constructor(options) {
super(options);
this.readCount = 0;
this.data = Buffer.concat(options.messages);
this.emitSize = options.emitSize;
this.throwError = options.throwError;
}
_read() {
const self = this;
if (this.readCount === this.data.length) {
if (this.throwError) {
process.nextTick(function () {
self.emit("error", new Error("Throwing an error!"));
});
return;
}
else {
this.push(null);
return;
}
}
const bytesLeft = this.data.length - this.readCount;
const numBytesToSend = Math.min(bytesLeft, this.emitSize);
const chunk = this.data.slice(this.readCount, this.readCount + numBytesToSend);
this.readCount += numBytesToSend;
this.push(chunk);
}
}