netcdf4-wasm
Version:
NetCDF4 library compiled to WebAssembly with TypeScript bindings
30 lines • 1.01 kB
JavaScript
;
// Lazy file reading - in-memory backend
//
// Backs a LazyReader with an existing Uint8Array. This does not save memory (the
// whole buffer is already resident) but provides a uniform reader for callers who
// already hold the bytes, and is the reference backend the tests exercise the
// cache against.
Object.defineProperty(exports, "__esModule", { value: true });
exports.MemoryReader = void 0;
class MemoryReader {
constructor(data) {
this.data = data;
}
get size() {
return this.data.length;
}
read(offset, length) {
const end = Math.min(offset + length, this.data.length);
if (offset < 0 || offset >= this.data.length || end <= offset) {
return new Uint8Array(0);
}
// A view is safe: the source bytes are treated as immutable.
return this.data.subarray(offset, end);
}
close() {
// Nothing to release.
}
}
exports.MemoryReader = MemoryReader;
//# sourceMappingURL=memory-reader.js.map