@thi.ng/file-io
Version:
Assorted file I/O utils (w/ logging support) for NodeJS/Bun
18 lines (17 loc) • 576 B
JavaScript
import { readFileSync } from "node:fs";
import { readFile } from "node:fs/promises";
import { maskedPath } from "./mask.js";
const readBinary = (path, logger) => {
logger?.debug("reading file:", maskedPath(path));
const buf = readFileSync(path);
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
};
const readBinaryAsync = async (path, logger) => {
logger?.debug("reading file:", maskedPath(path));
const buf = await readFile(path);
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
};
export {
readBinary,
readBinaryAsync
};