@oazmi/build-tools
Version:
general deno build tool scripts which I practically use in all of my typescript repos
28 lines (27 loc) • 752 B
JavaScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
/**
* @deprecated (will be removed after 1.0.0) Use the {@link https://developer.mozilla.org/en-US/docs/Web/API/Streams_API | Web Streams API} instead.
*/
export class LimitedReader {
reader;
limit;
constructor(reader, limit) {
this.reader = reader;
this.limit = limit;
}
async read(p) {
if (this.limit <= 0) {
return null;
}
if (p.length > this.limit) {
p = p.subarray(0, this.limit);
}
const n = await this.reader.read(p);
if (n === null) {
return null;
}
this.limit -= n;
return n;
}
}