Zum Inhalt springen

Getting Started

GitHub

Sie können unsere AI-gestützte Einrichtung verwenden, um das Plugin zu installieren. Fügen Sie die Capgo Fähigkeiten Ihrem AI-Tool mit der folgenden Befehl hinzu:

Terminal-Fenster
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Verwenden Sie dann die folgende Anfrage:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-file` plugin in my project.

Wenn Sie die manuelle Einrichtung bevorzugen, installieren Sie das Plugin, indem Sie die folgenden Befehle ausführen und die unten aufgeführten plattformspezifischen Anweisungen befolgen:

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

Einen Dateisystemanforderung stellen.

import { CapacitorFile, FileSystemType } from '@capgo/capacitor-file';
const result = await CapacitorFile.requestFileSystem({ type: FileSystemType.TEMPORARY });
console.log(result);

Ein lokales Dateisystem-URL auflösen.

import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.resolveLocalFileSystemURL({ url: 'https://example.com' });
console.log(result);

Ein Dateiantrag erhalten.

import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getFile({ path: 'path/to/file' });
console.log(result);

Einen Verzeichniseintrag erhalten.

import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getDirectory({ path: 'path/to/file' });
console.log(result);

Ein Datei als Text oder Base64 lesen.

import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.readFile({ path: 'path/to/file' });
console.log(result);

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

import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.readAsDataURL({ path: 'path/to/file' });
console.log(result);

Daten in eine Datei schreiben.

import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.writeFile({
path: 'path/to/file',
data: 'data',
});
console.log(result);

Daten an einen Datei anhängen.

import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.appendFile({
path: 'path/to/file',
data: 'data',
});
console.log(result);

Eine Datei löschen.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.deleteFile({ path: 'path/to/file' });

Ein Verzeichnis erstellen.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.mkdir({ path: 'path/to/file' });

Ein Verzeichnis löschen.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.rmdir({ path: 'path/to/file' });

Lese den Inhalt eines Verzeichnisses.

import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.readdir({ path: 'path/to/file' });
console.log(result);

Ermittle Metadaten über ein Datei oder ein Verzeichnis.

import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.stat({ path: 'path/to/file' });
console.log(result);

Ermittle Metadaten über eine Datei oder ein Verzeichnis. Alias für stat().

import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getMetadata({ path: 'path/to/file' });
console.log(result);

Umbenennen oder einen Ordner verschieben.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.rename({
from: 'from',
to: 'to',
});

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

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.move({
from: 'from',
to: 'to',
});

Eine Datei oder ein Verzeichnis kopieren.

import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.copy({
from: 'from',
to: 'to',
});
console.log(result);

Check if a file or directory exists.

import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.exists({ path: 'path/to/file' });
console.log(result);

Ermitteln Sie die URI einer Datei.

import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getUri({ path: 'path/to/file' });
console.log(result);

Ein Datei auf eine bestimmte Größe trancieren.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.truncate({ path: 'path/to/file' });

Alle bekannten Dateisystem-Ordner abrufen.

import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getDirectories();
console.log(result);

Die verfügbare Festplattenplatz in Bytes abrufen.

import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getFreeDiskSpace();
console.log(result);

Die aktuelle Berechtigung für Dateibearbeitungen überprüfen. Bei Android wird die Außenplatzberechtigung überprüft. Bei iOS und Web wird immer ‘erlaubt’ zurückgegeben, da keine besonderen Berechtigungen erforderlich sind.

import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.checkPermissions();
console.log(result);

Erlaubnisse für Dateibearbeitungen anfordern. Bei Android-Anwendungen wird die Auflistung der externen Speichererlaubnisse angefordert, die zum Zugriff auf Dateien außerhalb der privaten Verzeichnisse der App erforderlich sind. Bei iOS- und Web-Anwendungen wird immer ‘erteilt’ zurückgegeben, da keine besonderen Erlaubnisse erforderlich sind.

import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.requestPermissions();
console.log(result);

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

Einstellungen zur Auflösung einer URL zu einem Eintrag.

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

Stellt einen Datei- oder Verzeichnis-Eintrag dar.

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

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

Ergebnis der Dateiläsung.

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 wurde aus dem Plugin generiert. src/definitions.tsRe-run die Synchronisierung, wenn die öffentliche API upstream geändert wird.

Wenn Sie das Plugin verwenden Getting Started um den Speicher und die Dateihandling zu planen, verbinden Sie es mit Mit @capgo/capacitor-Datei zur nativen Fähigkeit in Mit @capgo/capacitor-Datei, @capgo/capacitor-Daten-Speicher-SQLite zur Implementierungsdetail in @capgo/capacitor-Daten-Speicher-SQLite, Mit @capgo/capacitor-Daten-Speicher-SQLite zur nativen Fähigkeit in Mit @capgo/capacitor-Daten-Speicher-SQLite, @capgo/capacitor-Datei zur Implementierungsdetail in @capgo/capacitor-Datei und @capgo/capacitor-Uploader zur Implementierungsdetail in @capgo/capacitor-Uploader.