Skip to content

File

File system utilities to read, write, and inspect resources.

How to import?

The library exposes the DServerFile and SF namespaces from the main entry or via direct import (tree-shaking friendly), which lets you load only what you need.

typescript
import { DServerFile, SF } from "@duplojs/server-utils";
import * as DServerFile from "@duplojs/server-utils/file";
import * as SF from "@duplojs/server-utils/file";

Read

readFile

reads a file and returns its binary content.

readTextFile

reads a text file and returns its content.

Write

writeFile

writes binary content to a file.

writeTextFile

writes text content to a file.

Append

appendFile

appends binary content to the end of a file.

appendTextFile

appends text content to the end of a file.

JSON

readJsonFile

reads and parses a JSON file.

writeJsonFile

serializes and writes a JSON file.

Directories

readDirectory

lists the entries in a directory.

makeDirectory

creates a directory.

ensureDirectory

ensures a directory exists.

walkDirectory

walks a directory recursively.

creates a symbolic link.

reads the target of a symbolic link.

creates a hard link.

linkStat

retrieves information about a symbolic link.

Checks and metadata

exists

checks that a resource exists.

stat

retrieves information about a resource.

realPath

resolves a resource to its canonical form.

Move and copy

remove

removes a file or directory.

copy

copies a file or directory.

move

moves a file or directory.

relocate

relocates a resource into a new parent directory.

rename

renames a file or directory within its parent directory.

truncate

truncates a file to a given size.

Permissions and timestamps

setMode

sets permissions for a file or directory.

setOwner

sets the owner of a file or directory.

setTime

updates access and modification timestamps.

Temporary files and helpers

makeTemporaryDirectory

creates a temporary directory.

makeTemporaryFile

creates a temporary file.

ensureFile

ensures a file exists.

Interfaces

fileInterface

creates a file interface with utility methods.

folderInterface

creates a directory interface with utility methods.

unknownInterface

creates an interface for a resource of unknown type.

Released under the MIT license.