Skip to content

fileInterface

Interface fichier avec des méthodes utilitaires.

WARNING

L'objet FileInterface ne garantit pas l'existence réelle du fichier. C'est uniquement un helper pour representer une ressource et faciliter les opérations.

Exemple

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
();
}

Syntaxe

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>>;
}

Paramètres

  • path : chemin du fichier.

Valeur de retour

  • FileInterface : interface avec name, extension, mimeType, path et des méthodes comme rename(newName), exist(), relocate(parentPath), remove(), stat() et getParentPath().

Voir aussi

  • stat - Récupère les informations d'un chemin.

Diffusé sous licence MIT.