Skip to content

File

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

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.

Paths and metadata

exists

checks that a path exists.

stat

retrieves information about a path.

realPath

resolves a path 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.

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.

MIME types

mimeType

list of supported MIME types and extensions.

Interfaces

fileInterface

creates a file interface with utility methods.

folderInterface

creates a directory interface with utility methods.

unknownInterface

creates an interface for a path of unknown type.

Released under the MIT license.