esbuild-gas-plugin
Version:
esbuild plugin for Google Apps Script.
33 lines (32 loc) • 863 B
JavaScript
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
export class LimitedReader {
constructor(reader, limit) {
Object.defineProperty(this, "reader", {
enumerable: true,
configurable: true,
writable: true,
value: reader
});
Object.defineProperty(this, "limit", {
enumerable: true,
configurable: true,
writable: true,
value: 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;
}
}