UNPKG

@litert/televoke

Version:
100 lines 2.87 kB
"use strict"; /** * Copyright 2025 Angus.Fenying <fenying@litert.org> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.TvBinaryReadStream = void 0; const E = require("./Errors"); const node_stream_1 = require("node:stream"); class TvBinaryReadStream extends node_stream_1.Readable { constructor(id, _timeout = 0) { super(); this.id = id; this._timeout = _timeout; /** * The index of next chunk to read. */ this.nextIndex = 0; this._timer = null; if (_timeout > 0) { this._resetTimer(); } } setTimeout(timeout) { if (timeout === this._timeout) { return; } this._timeout = timeout; if (timeout > 0) { if (this._timer) { clearTimeout(this._timer); this._timer = null; } this._resetTimer(); } } _resetTimer() { if (this.readableEnded) { if (this._timer) { clearTimeout(this._timer); this._timer = null; } return; } if (this._timer) { this._timer.refresh(); return; } this._timer = setTimeout(() => { if (this.readableEnded) { return; } this._timer = null; this.destroy(new E.errors.timeout()); }, this._timeout); } append(chunkSegments) { if (this.readableEnded) { throw new E.errors.stream_closed(); } if (this._timeout > 0) { this._resetTimer(); } for (const s of chunkSegments) { super.push(s); } this.nextIndex++; } close() { if (this._timer) { clearTimeout(this._timer); this._timer = null; } this.push(null); } abort() { if (this._timer) { clearTimeout(this._timer); this._timer = null; } this.destroy(new E.errors.stream_aborted()); } // eslint-disable-next-line @typescript-eslint/naming-convention _read() { return; } } exports.TvBinaryReadStream = TvBinaryReadStream; //# sourceMappingURL=BinaryStream.js.map