UNPKG

typesxml

Version:

Open source XML library written in TypeScript

48 lines 1.36 kB
/******************************************************************************* * Copyright (c) 2023-2026 Maxprograms. * * This program and the accompanying materials * are made available under the terms of the Eclipse License 1.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/org/documents/epl-v10.html * * Contributors: * Maxprograms - initial API and implementation *******************************************************************************/ import { NeedMoreDataError } from "./NeedMoreDataError.js"; export class StreamReader { encoding; chunks; finished; constructor(encoding) { this.encoding = encoding; this.chunks = []; this.finished = false; } enqueue(chunk) { this.chunks.push(chunk); } markFinished() { this.finished = true; } read() { if (this.chunks.length > 0) { return this.chunks.shift(); } if (this.finished) { return ''; } throw new NeedMoreDataError(); } dataAvailable() { return this.chunks.length > 0; } isFinished() { return this.finished && this.chunks.length === 0; } closeFile() { this.chunks.length = 0; this.finished = true; } } //# sourceMappingURL=StreamReader.js.map