ensureFile
Ensures a file exists.
Example
ts
import { SF } from "@duplojs/server-utils";
import { E } from "@duplojs/utils";
const result = await SF.ensureFile("/tmp/empty.txt");
// result: E.Ok | SF.FileSystemLeft
if (E.isRight(result)) {
// if the file already exists, nothing happens (create if not exist)
}Syntax
typescript
function ensureFile(
path: string | URL
): Promise<FileSystemLeft | E.Ok>Parameters
path: path of the file.
Return value
E.Ok: if the file exists or was created.FileSystemLeft: if the operation fails.
See also
ensureDirectory- Ensures a directory exists.
