Zum Inhalt springen

Einstieg

Terminalfenster
bun add @capgo/capacitor-file
bunx cap sync
import { CapacitorFile } from '@capgo/capacitor-file';

Ein Dateisystem anfordern.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.requestFileSystem({} as RequestFileSystemOptions);

Ein Datei-URL in einen Eintrag auflösen.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.resolveLocalFileSystemURL({} as ResolveURLOptions);

Ein Datei-Eintrag erhalten.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getFile({} as GetFileOptions);

Ein Verzeichnis-Eintrag erhalten.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getDirectory({} as GetDirectoryOptions);

Ein Datei als Text oder Base64 lesen.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.readFile({} as ReadFileOptions);

Ein Datei als Daten-URL (Base64 mit MIME-Typ-Präfix) lesen.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.readAsDataURL({} as ReadFileOptions);

Daten in eine Datei schreiben.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.writeFile({} as WriteFileOptions);

Daten einer Datei anhängen.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.appendFile({} as WriteFileOptions);

Eine Datei löschen.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.deleteFile({} as DeleteFileOptions);

Ein Verzeichnis erstellen.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.mkdir({} as MkdirOptions);

Ein Verzeichnis löschen.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.rmdir({} as DeleteDirectoryOptions);

Inhalte eines Verzeichnisses lesen.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.readdir({} as ReaddirOptions);

Metadaten über ein Datei oder Verzeichnis abrufen.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.stat({} as StatOptions);

Ermitteln Sie Metadaten über ein Dateisystem oder einen Verzeichnis. Alias für stat().

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getMetadata({} as StatOptions);

Umbenennen oder ein Dateisystem oder ein Verzeichnis verschieben.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.rename({} as RenameOptions);

Ein Dateisystem oder ein Verzeichnis verschieben. Alias für rename().

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.move({} as RenameOptions);

Ein Dateisystem oder ein Verzeichnis kopieren.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.copy({} as CopyOptions);

Überprüfen Sie, ob ein Datei- oder Verzeichnis-System existiert.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.exists({} as ExistsOptions);

Ermitteln Sie die URI für eine Datei.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getUri({} as GetUriOptions);

Beschränken Sie eine Datei auf eine bestimmte Größe.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.truncate({} as TruncateOptions);

Ermitteln Sie alle bekannten Dateisystem-Verzeichnisse.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getDirectories();

Ermitteln Sie den freien Festplattenspeicher in Bytes.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getFreeDiskSpace();

Überprüfen Sie den aktuellen Berechtigungsstatus für Dateibearbeitungen. Bei Android-Systemen prüft dies die externen Speicherberechtigungen. Bei iOS- und Web-Systemen wird immer ‘erlaubt’ zurückgegeben, da keine besonderen Berechtigungen erforderlich sind.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.checkPermissions();

Berechtigungen für Dateibearbeitungen anfordern. Bei Android-Systemen werden die externen Speicherberechtigungen benötigt, um Daten außerhalb der Anwendungs-Private-Ordner zu zugreifen. Bei iOS- und Web-Systemen wird immer ‘erlaubt’ zurückgegeben, da keine besonderen Berechtigungen erforderlich sind.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.requestPermissions();

Optionen für die Anforderung eines Dateisystems.

export interface RequestFileSystemOptions {
/** The type of file system to request */
type: FileSystemType;
/** Requested size in bytes (may not be enforced on all platforms) */
size?: number;
}

Darstellt ein Dateisystem.

export interface FileSystem {
/** The name of the file system */
name: string;
/** The root directory of the file system */
root: DirectoryEntry;
}

Optionen zur Auflösung einer URL zu einem Eintrag.

export interface ResolveURLOptions {
/** The URL to resolve (file:// or cdvfile://) */
url: string;
}

Darstellt einen Datei- oder Verzeichniseintrag.

export interface Entry {
/** True if this is a file */
isFile: boolean;
/** True if this is a directory */
isDirectory: boolean;
/** The name of the file or directory */
name: string;
/** The full path relative to the filesystem root */
fullPath: string;
/** The native file:// URI */
nativeURL: string;
}

Optionen für das Abrufen eines Dateisystems.

export interface GetFileOptions {
/** Path to the file */
path: string;
/** Base directory */
directory?: Directory;
/** Options for creating the file */
options?: GetOptions;
}

Stellt einen Dateieintrag dar.

export interface FileEntry extends Entry {
isFile: true;
isDirectory: false;
}

Optionen für das Abrufen eines Verzeichnisses.

export interface GetDirectoryOptions {
/** Path to the directory */
path: string;
/** Base directory */
directory?: Directory;
/** Options for creating the directory */
options?: GetOptions;
}

Stellt einen Verzeichnis-Eintrag dar.

export interface DirectoryEntry extends Entry {
isFile: false;
isDirectory: true;
}

Optionen für das Lesen einer Datei.

export interface ReadFileOptions {
/** Path to the file */
path: string;
/** Base directory */
directory?: Directory;
/** Encoding for text files (omit for binary/base64) */
encoding?: Encoding;
/** Byte offset to start reading from (default: 0) */
offset?: number;
/** Number of bytes to read (default: read to end of file) */
length?: number;
}

Erfolg des Lesens einer Datei.

export interface ReadFileResult {
/** File contents as string (text) or base64 (binary) */
data: string;
}

Optionen für das Schreiben einer Datei.

export interface WriteFileOptions {
/** Path to the file */
path: string;
/** Base directory */
directory?: Directory;
/** Data to write (string for text, base64 for binary) */
data: string;
/** Encoding for text files */
encoding?: Encoding;
/** If true, append to existing file instead of overwriting */
append?: boolean;
/** Create intermediate directories if they don't exist */
recursive?: boolean;
/** Byte position to start writing at (for random access writes). If not specified, writes from beginning or appends based on 'append' flag */
position?: number;
}

Erfolg des Schreibens einer Datei.

export interface WriteFileResult {
/** The URI of the written file */
uri: string;
}

Quelle der Wahrheit

Quelle der Wahrheit

Diese Seite wurde aus dem Plugin generiert. src/definitions.tsRe-run die Synchronisation, wenn die öffentliche API upstream ändert.

Weiter von Getting Started

Weiter von Getting Started

Wenn Sie Getting Started um Speicherplatz und Dateihandling zu planen, verbinden Sie es mit Mit @capgo/capacitor-file für die native Fähigkeit in Mit @capgo/capacitor-file, für die Implementierungsdetails in @capgo/capacitor-data-storage-sqlite, für die Implementierungsdetails in @capgo/capacitor-data-storage-sqlite, Mit @capgo/capacitor-data-storage-sqlite für die native Fähigkeit in Mit @capgo/capacitor-data-storage-sqlite @capgo/capacitor-file für die Implementierungsdetails in @capgo/capacitor-file, und @capgo/capacitor-uploader für die Implementierungsdetails in @capgo/capacitor-uploader.