Provides comprehensive access to the local file system on mobile devices through Expo's module system.
npx @tessl/cli install tessl/npm-expo-file-system@19.0.0Expo File System provides comprehensive access to the local file system on mobile devices through Expo's module system. It offers a modern, object-oriented API for file and directory operations including reading, writing, copying, moving, and deleting files and directories with cross-platform support for iOS and Android.
npx expo install expo-file-systemimport { File, Directory, Paths } from "expo-file-system";For legacy compatibility:
import * as FileSystem from "expo-file-system/legacy";Type imports:
import type { FileInfo, DirectoryInfo, FileCreateOptions } from "expo-file-system";import { File, Directory, Paths } from "expo-file-system";
// Create file and directory instances
const file = new File(Paths.document, "myfile.txt");
const directory = new Directory(Paths.cache, "temp");
// Basic file operations
file.write("Hello, World!");
const content = await file.text();
console.log(content); // "Hello, World!"
// Directory operations
directory.create();
const files = directory.list();
// Check disk space
console.log(`Available space: ${Paths.availableDiskSpace} bytes`);Expo File System is built around several key components:
File and Directory classes with fluent interfacesPaths class providing access to cache, document, and bundle directoriesComplete file management including creation, reading, writing, copying, moving, and deletion. Supports both synchronous and asynchronous operations with streaming for large files.
class File implements Blob {
constructor(...uris: (string | File | Directory)[]);
readonly uri: string;
readonly name: string;
readonly extension: string;
readonly parentDirectory: Directory;
exists: boolean;
size: number;
}Directory management including creation, listing contents, copying, moving, and deletion. Provides recursive operations and metadata access.
class Directory {
constructor(...uris: (string | File | Directory)[]);
readonly uri: string;
readonly name: string;
readonly parentDirectory: Directory;
exists: boolean;
size: number | null;
}Access to system directories (cache, document, bundle) and comprehensive path manipulation utilities with cross-platform compatibility.
class Paths extends PathUtilities {
static get cache(): Directory;
static get document(): Directory;
static get bundle(): Directory;
static get appleSharedContainers(): Record<string, Directory>;
static get totalDiskSpace(): number;
static get availableDiskSpace(): number;
static info(...uris: string[]): PathInfo;
}Readable and writable streams for efficient handling of large files with backpressure control and memory-efficient processing.
interface FileHandle {
offset: number | null;
size: number | null;
close(): void;
readBytes(length: number): Uint8Array<ArrayBuffer>;
writeBytes(bytes: Uint8Array): void;
}Download files from URLs with progress tracking and resume capabilities. Supports custom headers and destination control.
class File {
static downloadFileAsync(
url: string,
destination: Directory | File,
options?: DownloadOptions
): Promise<File>;
}Native file and directory pickers for user-initiated file selection with platform-specific behaviors and MIME type filtering.
class File {
static pickFileAsync(initialUri?: string, mimeType?: string): Promise<File | File[]>;
}
class Directory {
static pickDirectoryAsync(initialUri?: string): Promise<Directory>;
}interface FileInfo {
exists: boolean;
uri?: string;
size?: number;
modificationTime?: number;
creationTime?: number;
md5?: string;
}
interface DirectoryInfo {
exists: boolean;
uri?: string;
size?: number;
modificationTime?: number;
creationTime?: number;
files?: string[];
}
interface PathInfo {
exists: boolean;
isDirectory: boolean | null;
}
interface FileCreateOptions {
intermediates?: boolean;
overwrite?: boolean;
}
interface DirectoryCreateOptions {
intermediates?: boolean;
overwrite?: boolean;
idempotent?: boolean;
}
interface InfoOptions {
md5?: boolean;
}
interface DownloadOptions {
headers?: { [key: string]: string };
}