UNPKG

generic-filehandle2

Version:

uniform interface for accessing binary data from local files, remote HTTP resources, and browser Blob data

24 lines 757 B
import { open, readFile, stat } from 'fs/promises'; export default class LocalFile { constructor(source, _opts = {}) { this.filename = source; } async read(length, position = 0) { const arr = new Uint8Array(length); const fd = await open(this.filename, 'r'); const res = await fd.read(arr, 0, length, position); await fd.close(); return res.buffer.subarray(0, res.bytesRead); } async readFile(options) { const res = await readFile(this.filename, options); return typeof res === 'string' ? res : new Uint8Array(res); } async stat() { return stat(this.filename); } async close() { /* do nothing */ } } //# sourceMappingURL=localFile.js.map