Zum Inhalt springen

Getting Started

GitHub
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);

Eine Datei-URL auf einen Eintrag auflösen.

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

Ein Dateiantrag erhalten.

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

Ein Verzeichnisantrag erhalten.

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

Zur Zwischenablage kopieren

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

Abschnitt mit dem Titel “readFile”

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 in eine 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);

Zur Zwischenablage kopieren

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

Zur Zwischenablage kopieren

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

Ein Datei oder Verzeichnis umbenennen oder verschieben.

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

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

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

Ein Datei oder Verzeichnis kopieren.

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

Überprüfen, ob eine Datei oder ein Verzeichnis existiert.

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

Ermitteln Sie die URI für ein Datei.

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

Kürzen Sie eine Datei auf eine bestimmte Größe.

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

Ermitteln Sie alle bekannten Dateisystem-Ordner.

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

Ermitteln Sie die verfügbare Festplattenplatz in Bytes.

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

Überprüfen Sie den aktuellen Zustand der Berechtigungen für Dateibearbeitungen. Bei Android-Systemen prüft dies die Berechtigungen für externe Speicher. 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 erforderlichen Berechtigungen für den Zugriff auf Dateien außerhalb der privaten Verzeichnisse des Apps angefordert. 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 Verzeichnis-Eintrag.

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 zur Abrufung einer Datei.

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

Ergebnis der Dateilese.

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

Optionen für die Dateischreibung.

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

Ergebnis der Dateischreibung.

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

Diese Seite wird aus der Plugin-Datei generiert. src/definitions.ts. Wiederholen Sie die Synchronisierung, wenn die öffentliche API upstream geändert wird.

Wenn Sie " Getting Started zur Planung von Speicher und Dateimanagement verwenden, verbinden Sie es mit Mit @capgo/capacitor-datei für die native Fähigkeit in Mit @capgo/capacitor-datei, Mit @capgo/capacitor-datenspeicher-sqlite für die Implementierungsdetail in Mit @capgo/capacitor-datenspeicher-sqlite, Mit @capgo/capacitor-datenspeicher-sqlite für die native Fähigkeit in Mit @capgo/capacitor-datenspeicher-sqlite @capgo/capacitor-Datei für die Implementierungsdetails in @capgo/capacitor-Datei, und @capgo/capacitor-Uploader für die Implementierungsdetails in @capgo/capacitor-Uploader.