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
): FileInterfacetypescript
function isFileInterface(
input: unknown
): input is FileInterfaceInterface 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 avecname,extension,mimeType,pathet des méthodes commerename(newName),exist(),relocate(parentPath),remove(),stat()etgetParentPath().
Voir aussi
stat- Récupère les informations d'un chemin.
