JSPM

@capacitor/filesystem

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 218078
  • Score
    100M100P100Q165019F
  • License MIT

The Filesystem API provides a NodeJS-like API for working with files on the device.

Package Exports

  • @capacitor/filesystem

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@capacitor/filesystem) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@capacitor/filesystem

The Filesystem API provides a NodeJS-like API for working with files on the device.

Install

npm install @capacitor/filesystem
npx cap sync

API

readFile(...)

readFile(options: FileReadOptions) => Promise<FileReadResult>

Read a file from disk

Param Type
options FileReadOptions

Returns: Promise<FileReadResult>

Since: 1.0.0


writeFile(...)

writeFile(options: FileWriteOptions) => Promise<FileWriteResult>

Write a file to disk in the specified location on device

Param Type
options FileWriteOptions

Returns: Promise<FileWriteResult>

Since: 1.0.0


appendFile(...)

appendFile(options: FileAppendOptions) => Promise<void>

Append to a file on disk in the specified location on device

Param Type
options FileAppendOptions

Since: 1.0.0


deleteFile(...)

deleteFile(options: FileDeleteOptions) => Promise<void>

Delete a file from disk

Param Type
options FileDeleteOptions

Since: 1.0.0


mkdir(...)

mkdir(options: MkdirOptions) => Promise<void>

Create a directory.

Param Type
options MkdirOptions

Since: 1.0.0


rmdir(...)

rmdir(options: RmdirOptions) => Promise<void>

Remove a directory

Param Type
options RmdirOptions

Since: 1.0.0


readdir(...)

readdir(options: ReaddirOptions) => Promise<ReaddirResult>

Return a list of files from the directory (not recursive)

Param Type
options ReaddirOptions

Returns: Promise<ReaddirResult>

Since: 1.0.0


getUri(...)

getUri(options: GetUriOptions) => Promise<GetUriResult>

Return full File URI for a path and directory

Param Type
options GetUriOptions

Returns: Promise<GetUriResult>

Since: 1.0.0


stat(...)

stat(options: StatOptions) => Promise<StatResult>

Return data about a file

Param Type
options StatOptions

Returns: Promise<StatResult>

Since: 1.0.0


rename(...)

rename(options: RenameOptions) => Promise<void>

Rename a file or directory

Param Type
options CopyOptions

Since: 1.0.0


copy(...)

copy(options: CopyOptions) => Promise<void>

Copy a file or directory

Param Type
options CopyOptions

Since: 1.0.0


checkPermissions()

checkPermissions() => Promise<FilesystemPermissionStatus>

Check read/write permissions. Required on Android, only when using FilesystemDirectory.Documents or FilesystemDirectory.ExternalStorage.

Returns: Promise<FilesystemPermissionStatus>

Since: 1.0.0


requestPermissions()

requestPermissions() => Promise<FilesystemPermissionStatus>

Request read/write permissions. Required on Android, only when using FilesystemDirectory.Documents or FilesystemDirectory.ExternalStorage.

Returns: Promise<FilesystemPermissionStatus>

Since: 1.0.0


Interfaces

FileReadResult

Prop Type Description Since
data string The string representation of the data contained in the file 1.0.0

FileReadOptions

Prop Type Description Since
path string The path of the file to read 1.0.0
directory FilesystemDirectory The FilesystemDirectory to read the file from 1.0.0
encoding FilesystemEncoding The encoding to read the file in, if not provided, data is read as binary and returned as base64 encoded. Pass FilesystemEncoding.UTF8 to read data as string 1.0.0

FileWriteResult

Prop Type Description Since
uri string The uri where the file was written into 1.0.0

FileWriteOptions

Prop Type Description Default Since
path string The path of the file to write 1.0.0
data string The data to write 1.0.0
directory FilesystemDirectory The FilesystemDirectory to store the file in 1.0.0
encoding FilesystemEncoding The encoding to write the file in. If not provided, data is written as base64 encoded. Pass FilesystemEncoding.UTF8 to write data as string 1.0.0
recursive boolean Whether to create any missing parent directories. false 1.0.0

FileAppendOptions

Prop Type Description Since
path string The path of the file to append 1.0.0
data string The data to write 1.0.0
directory FilesystemDirectory The FilesystemDirectory to store the file in 1.0.0
encoding FilesystemEncoding The encoding to write the file in. If not provided, data is written as base64 encoded. Pass FilesystemEncoding.UTF8 to write data as string 1.0.0

FileDeleteOptions

Prop Type Description Since
path string The path of the file to delete 1.0.0
directory FilesystemDirectory The FilesystemDirectory to delete the file from 1.0.0

MkdirOptions

Prop Type Description Default Since
path string The path of the new directory 1.0.0
directory FilesystemDirectory The FilesystemDirectory to make the new directory in 1.0.0
recursive boolean Whether to create any missing parent directories as well. false 1.0.0

RmdirOptions

Prop Type Description Default Since
path string The path of the directory to remove 1.0.0
directory FilesystemDirectory The FilesystemDirectory to remove the directory from 1.0.0
recursive boolean Whether to recursively remove the contents of the directory false 1.0.0

ReaddirResult

Prop Type Description Since
files string[] List of files and directories inside the directory 1.0.0

ReaddirOptions

Prop Type Description Since
path string The path of the directory to read 1.0.0
directory FilesystemDirectory The FilesystemDirectory to list files from 1.0.0

GetUriResult

Prop Type Description Since
uri string The uri of the file 1.0.0

GetUriOptions

Prop Type Description Since
path string The path of the file to get the URI for 1.0.0
directory FilesystemDirectory The FilesystemDirectory to get the file under 1.0.0

StatResult

Prop Type Description Since
type string Type of the file 1.0.0
size number Size of the file 1.0.0
ctime number Time of creation 1.0.0
mtime number Time of last modification 1.0.0
uri string The uri of the file 1.0.0

StatOptions

Prop Type Description Since
path string The path of the file to get data about 1.0.0
directory FilesystemDirectory The FilesystemDirectory to get the file under 1.0.0

CopyOptions

Prop Type Description Since
from string The existing file or directory 1.0.0
to string The destination file or directory 1.0.0
directory FilesystemDirectory The FilesystemDirectory containing the existing file or directory 1.0.0
toDirectory FilesystemDirectory The FilesystemDirectory containing the destination file or directory. If not supplied will use the 'directory' parameter as the destination 1.0.0

FilesystemPermissionStatus

Prop Type
publicStorage any

Enums

FilesystemDirectory

Members Value Description Since
Documents 'DOCUMENTS' The Documents directory On iOS it's the app's documents directory. Use this directory to store user-generated content. On Android it's the Public Documents folder, so it's accessible from other apps. It's not accesible on Android 10 unless the app enables legacy External Storage by adding android:requestLegacyExternalStorage="true" in the application tag in the AndroidManifest.xml 1.0.0
Data 'DATA' The Data directory On iOS it will use the Documents directory On Android it's the directory holding application files. Files will be deleted when the application is uninstalled. 1.0.0
Cache 'CACHE' The Cache directory Can be deleted in cases of low memory, so use this directory to write app-specific files that your app can re-create easily. 1.0.0
External 'EXTERNAL' The external directory On iOS it will use the Documents directory On Android it's the directory on the primary shared/external storage device where the application can place persistent files it owns. These files are internal to the applications, and not typically visible to the user as media. Files will be deleted when the application is uninstalled. 1.0.0
ExternalStorage 'EXTERNAL_STORAGE' The external storage directory On iOS it will use the Documents directory On Android it's the primary shared/external storage directory. It's not accesible on Android 10 unless the app enables legacy External Storage by adding android:requestLegacyExternalStorage="true" in the application tag in the AndroidManifest.xml 1.0.0

FilesystemEncoding

Members Value Description Since
UTF8 'utf8' Eight-bit UCS Transformation Format 1.0.0
ASCII 'ascii' Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set This encoding is only supported on Android. 1.0.0
UTF16 'utf16' Sixteen-bit UCS Transformation Format, byte order identified by an optional byte-order mark This encoding is only supported on Android. 1.0.0