Skip to content

Path.readBytes() method

pathlib-ts > Path > readBytes

Read the file as raw bytes and return a promise that resolves to the binary contents of the pointed-to file as a bytes object.

Signature:

readBytes(): Promise<Buffer>;

Returns:

Promise<Buffer>

Promise resolving to the binary contents.

Hashing a bundle asynchronously

import { createHash } from "node:crypto";
import { Path } from "pathlib-ts";
const bundle = new Path("./dist/app.js");
const hash = createHash("sha256")
.update(await bundle.readBytes())
.digest("hex");
console.log(hash);