@wrote/read
Version:
Read the contents of file from the filesystem.
24 lines (22 loc) • 559 B
JavaScript
import { createReadStream } from 'fs'
import { collect } from 'catchment'
/**
* Read a file.
* @param {string} path The path to the file to read.
*/
export default async function read(path) {
const rs = createReadStream(path)
/** @type {string} */
const res = await collect(rs)
return res
}
/**
* Read a file as a buffer.
* @param {string} path The path to the file to read.
*/
export async function readBuffer(path) {
const rs = createReadStream(path)
/** @type {Buffer} */
const res = await collect(rs, { binary: true })
return res
}