Skip to content

filesystemUtils

github-actions edited this page Jun 2, 2026 · 24 revisions

filesystemUtils

Interfaces

TemporaryFileOptions

Defined in: src/filesystemUtils.mts:10

Properties

Property Type Description Defined in
path? string Path where the temporary file should be created. src/filesystemUtils.mts:14
writerOptions? object Options object defined by the first parameter accepted by BunFile.writer(). src/filesystemUtils.mts:18
writerOptions.highWaterMark? number - node_modules/bun-types/bun.d.ts:2159

Functions

findMissingPaths()

findMissingPaths(paths): Promise<string[]>

Defined in: src/filesystemUtils.mts:30

Compile a list of all inaccessible file paths, then return it. If all paths are valid, the list will be empty.

Parameters

Parameter Type Description
paths string[] List of file and/or directory paths.

Returns

Promise<string[]>

The list of inaccessible paths, if any.


getHumanReadableFilesize()

getHumanReadableFilesize(filesize, localeOverride?): string

Defined in: src/filesystemUtils.mts:72

Get a human readable filesize given its numeric value and an optional locale.

Parameters

Parameter Type Description
filesize number A file's size represented as a number.
localeOverride? string An optional locale value to override the default set by the operating system.

Returns

string

A localized string representing a file size.


getPathsRecursive()

getPathsRecursive(rootDirectory, ignore): Promise<string[]>

Defined in: src/filesystemUtils.mts:48

Recursively build a list of paths starting at a target directory. Ignore any paths that match values in the included ignore list.

Parameters

Parameter Type Description
rootDirectory string The root directory of the search.
ignore string[] The list of path segment names to match and ignore.

Returns

Promise<string[]>

A list of paths.


isDirectoryAccessible()

isDirectoryAccessible(path): Promise<boolean>

Defined in: src/filesystemUtils.mts:93

Determine if the provided path can be successfully accessed.

Parameters

Parameter Type Description
path string Path whose permissions to check.

Returns

Promise<boolean>

Boolean indicating whether or not the path is accessible.


usingNewTemporaryFile()

usingNewTemporaryFile(options?): object

Defined in: src/filesystemUtils.mts:132

Create a new temporary file with an await using variable declaration then append to it with a FileSink instance. Automatically delete the file when its variable falls out of scope. Customize file behavior with an optional options object as follows:

{
  path?: string;                                    // Target path to use for temporary file creation.
  writerOptions?: Parameters<BunFile['writer']>[0]; // Options object to customize `Bun.file().writer()` behavior
}

.

Parameters

Parameter Type Description
options? TemporaryFileOptions Options object to customize temporary file behavior.

Returns

Temporary file instance object.

Name Type Description Defined in
[asyncDispose]() () => Promise<void> Asynchronous automatic disposal function. src/filesystemUtils.mts:152
append() (appendContents, shouldForceFlush) => Promise<void> Append string contents to the target temporary file. src/filesystemUtils.mts:142

See

https://github.com/tc39/proposal-explicit-resource-management to explain the origin and use of the using keyword

Example

import { usingNewTemporaryFile } from '@mangs/bun-utils/filesystem';

await using file = usingNewTemporaryFile();
await file.append('test data 42\n');
// sometime later...
await file.append('holy data, batman\n');

// file auto-deletes at the end of its execution scope

Clone this wiki locally