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
name
=
file
.
getName
();
// name: string | null const
parentPath
=
file
.
getParentPath
();
// parentPath: string | null const
stat
= await
file
.
stat
();
// stat: E.Success<SF.StatInfo> | SF.FileSystemLeft<"stat"> 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
): FileInterface
typescript
function isFileInterface(
  input: unknown
): input is FileInterface

Interface FileInterface

typescript
interface FileInterface {
  path: string;
  getName(): string | null;
  getMimeType(): string | null;
  getExtension(params?: { withDot?: boolean; }): string | null;
  getParentPath(): string | null;
  rename(newName: string): Promise<FileSystemLeft<"rename"> | E.Success<FileInterface>>;
  relocate(parentPath: string): Promise<FileSystemLeft<"relocate"> | E.Success<FileInterface>>;
  move(newPath: string): Promise<FileSystemLeft<"move"> | E.Success<FileInterface>>;
  exists(): Promise<FileSystemLeft<"exists"> | E.Ok>;
  remove(): Promise<FileSystemLeft<"remove"> | E.Ok>;
  stat(): Promise<FileSystemLeft<"stat"> | E.Success<StatInfo>>;
}

Paramètres

  • path : chemin du fichier.

Valeur de retour

  • FileInterface : interface avec path, des getters (getName, getExtension, getMimeType, getParentPath) et des méthodes utilitaires comme rename(newName), exists(), relocate(parentPath), move(newPath), remove() et stat().

Voir aussi

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

Diffusé sous licence MIT.