UNPKG

@boringnode/transmit

Version:

A framework agnostic Server-Sent-Event library

27 lines (26 loc) 605 B
/* * @boringnode/transmit * * @license MIT * @copyright BoringNode */ import { Writable } from 'node:stream'; export class Sink extends Writable { #chunks = []; constructor() { super({ objectMode: true }); } assertWriteHead(assertion) { // @ts-expect-error - Mocking the writeHead method this.writeHead = (statusCode, headers) => { assertion(statusCode, headers); }; } get content() { return this.#chunks.join(''); } _write(chunk, _encoding, callback) { this.#chunks.push(chunk); callback(); } }