Skip to content

fileInterface

File interface with utility methods.

WARNING

The FileInterface object does not guarantee that the file actually exists. It is only a helper to represent a resource and make operations easier.

Example

ts
import { 
SF
} from "@duplojs/server-utils";
import {
E
,
unwrap
} from "@duplojs/utils";
const
file
=
SF
.
createFileInterface
("/tmp/example.json");
const
parentPath
=
file
.
getParentPath
();
// parentPath: string const
stat
= await
file
.
stat
();
// stat: E.Success<SF.StatInfo> | SF.FileSystemLeft if (
E
.
isRight
(
stat
)) {
const
info
=
unwrap
(
stat
);
// info.isFile: boolean } if (
SF
.
isFileInterface
(
file
)) {
// file: SF.FileInterface
file
.
getParentPath
();
}

Syntax

typescript
function createFileInterface(
  path: string | URL
): FileInterface
typescript
function isFileInterface(
  input: unknown
): input is FileInterface

Interface FileInterface

typescript
interface FileInterface {
  name: string;
  path: string;
  mimeType: SupportedMimeType | null;
  extension: SupportedExtensionFile | null;
  getParentPath(): string;
  rename(newName: string): Promise<FileSystemLeft | E.Success<FileInterface>>;
  exist(): Promise<FileSystemLeft | E.Ok>;
  relocate(parentPath: string | URL): Promise<FileSystemLeft | E.Success<FileInterface>>;
  remove(): Promise<FileSystemLeft | E.Ok>;
  stat(): Promise<FileSystemLeft | E.Success<StatInfo>>;
}

Parameters

  • path : path of the file.

Return value

  • FileInterface : interface with name, extension, mimeType, path, and methods like rename(newName), exist(), relocate(parentPath), remove(), stat(), and getParentPath().

See also

  • stat - Retrieves information about a path.

Released under the MIT license.