File System

file.mjs

@mr_ozio/scraper-utils · v2.5.0 · Generated April 21, 2026

Target Style

Target Style

11 exports

const

ensureDirectory

Target Style
export const ensureDirectory = async ({ at }) => {

Ensures that a directory exists.

Target style API. Preferred for new code.

Parameters

  • options{ at: string }

Returns

Promise<void>

const

ensureParentDirectory

Target Style
export const ensureParentDirectory = async ({ for: filePath }) => {

Ensures that the parent directory for a file path exists.

Target style API. Preferred for new code.

Parameters

  • options{ for: string }

Returns

Promise<void>

const

listFiles

Target Style
export const listFiles = async ({ in: dirPath }) => {

Lists absolute file paths inside a directory.

Target style API. Preferred for new code.

Parameters

  • options{ in: string }

Returns

Promise<string[]>

Example

const files = await listFiles({
  in: '/tmp/screenshots',
})

const

fileExistsAt

Target Style
export const fileExistsAt = async (filePath) => {

Checks whether a file exists at a path.

Target style API. Preferred for new code.

Parameters

  • filePathstring

Returns

Promise<boolean>

Example

const exists = await fileExistsAt('/tmp/greeting.txt')

const

writeFile

Target Style
export const writeFile = async (contents, { to, encoding = 'utf-8', createDirectories = false } = {}) => {

Writes file contents to a path.

Target style API. Preferred for new code.

Parameters

  • contentsstring | NodeJS.ArrayBufferView
  • options{ to: string, encoding?: BufferEncoding, createDirectories?: boolean }

Returns

Promise<void>

Example

await writeFile('hello', {
  to: '/tmp/greeting.txt',
  createDirectories: true,
})

const

readFile

Target Style
export const readFile = async ({ from, encoding = 'utf-8' } = {}) => {

Reads text contents from a file.

Target style API. Preferred for new code.

Parameters

  • options{ from: string, encoding?: BufferEncoding }

Returns

Promise<string>

Example

const contents = await readFile({
  from: '/tmp/greeting.txt',
})

const

copyFile

Target Style
export const copyFile = async ({ from, to, onProgress, createDirectories = false } = {}) => {

Copies a file between paths.

Target style API. Preferred for new code.

Parameters

  • options{ from: string, to: string, onProgress?: Function, createDirectories?: boolean }

Returns

Promise<void>

Example

await copyFile({
  from: '/tmp/source.txt',
  to: '/tmp/copy.txt',
  createDirectories: true,
})

const

moveFile

Target Style
export const moveFile = async ({ from, to, onProgress, createDirectories = false } = {}) => {

Moves a file into a destination path.

Target style API. Preferred for new code.

Parameters

  • options{ from: string, to: string, onProgress?: Function, createDirectories?: boolean }

Returns

Promise<void>

const

removeFile

Target Style
export const removeFile = async ({ at, throwIfNotExist = false } = {}) => {

Removes a file by path.

Target style API. Preferred for new code.

Parameters

  • options{ at: string, throwIfNotExist?: boolean }

Returns

Promise<void>

const

removeDirectory

Target Style
export const removeDirectory = async ({ at }) => {

Removes a directory recursively.

Target style API. Preferred for new code.

Parameters

  • options{ at: string }

Returns

Promise<void>

const

fileSize

Target Style
export const fileSize = async ({ at }) => {

Reads the size of a file in bytes.

Target style API. Preferred for new code.

Parameters

  • options{ at: string }

Returns

Promise<number>

Legacy Style

Legacy Style

3 exports

const

makeDirectory

Legacy Style
export const makeDirectory = async (fullPath) => {

No description provided.

Legacy API. Kept for older code and not the preferred choice for new code.

const

readDirectory

Legacy Style
export const readDirectory = async (dirPath) => {

No description provided.

Legacy API. Kept for older code and not the preferred choice for new code.

const

fileExists

Legacy Style
export const fileExists = async ({ at }) => fileExistsAt(at)

Checks whether a file exists.

Legacy API. Kept for older code and not the preferred choice for new code.

Parameters

  • options{ at: string }

Returns

Promise<boolean>