UNPKG

generic-filehandle2

Version:

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

27 lines 887 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const promises_1 = require("fs/promises"); class LocalFile { constructor(source, _opts = {}) { this.filename = source; } async read(length, position = 0) { const arr = new Uint8Array(length); const fd = await (0, promises_1.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 (0, promises_1.readFile)(this.filename, options); return typeof res === 'string' ? res : new Uint8Array(res); } async stat() { return (0, promises_1.stat)(this.filename); } async close() { /* do nothing */ } } exports.default = LocalFile; //# sourceMappingURL=localFile.js.map