
Security News
Node.js Moves Toward Stable TypeScript Support with Amaro 1.0
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
expo-file-system
Advanced tools
The expo-file-system package provides access to the file system on the device, allowing for reading, writing, deleting, and managing files and directories. It is part of the Expo ecosystem and is designed to work seamlessly with other Expo modules.
Reading Files
This feature allows you to read the contents of a file from a given URI. The readAsStringAsync method reads the file and returns its content as a string.
import * as FileSystem from 'expo-file-system';
async function readFile(uri) {
try {
const content = await FileSystem.readAsStringAsync(uri);
console.log(content);
} catch (error) {
console.error('Error reading file:', error);
}
}
Writing Files
This feature allows you to write content to a file at a specified URI. The writeAsStringAsync method writes the provided content to the file.
import * as FileSystem from 'expo-file-system';
async function writeFile(uri, content) {
try {
await FileSystem.writeAsStringAsync(uri, content);
console.log('File written successfully');
} catch (error) {
console.error('Error writing file:', error);
}
}
Deleting Files
This feature allows you to delete a file at a specified URI. The deleteAsync method deletes the file.
import * as FileSystem from 'expo-file-system';
async function deleteFile(uri) {
try {
await FileSystem.deleteAsync(uri);
console.log('File deleted successfully');
} catch (error) {
console.error('Error deleting file:', error);
}
}
Creating Directories
This feature allows you to create a directory at a specified URI. The makeDirectoryAsync method creates the directory, and the intermediates option allows for creating intermediate directories if they do not exist.
import * as FileSystem from 'expo-file-system';
async function createDirectory(uri) {
try {
await FileSystem.makeDirectoryAsync(uri, { intermediates: true });
console.log('Directory created successfully');
} catch (error) {
console.error('Error creating directory:', error);
}
}
Downloading Files
This feature allows you to download a file from a remote URI to a local URI. The downloadAsync method handles the download process.
import * as FileSystem from 'expo-file-system';
async function downloadFile(uri, downloadUri) {
try {
const { uri: localUri } = await FileSystem.downloadAsync(downloadUri, uri);
console.log('File downloaded to:', localUri);
} catch (error) {
console.error('Error downloading file:', error);
}
}
react-native-fs is a file system library for React Native that provides similar functionalities to expo-file-system, such as reading, writing, and managing files and directories. It is more flexible in terms of platform support but requires linking and additional setup compared to the seamless integration of expo-file-system within the Expo ecosystem.
rn-fetch-blob is a library that provides file system access and network capabilities for React Native. It allows for file manipulation, downloading, and uploading, similar to expo-file-system. However, it also includes advanced features like handling large file uploads and downloads, making it a more comprehensive solution for network and file system operations.
Provides access to the local file system on the device.
For managed Expo projects, please follow the installation instructions in the API documentation for the latest stable release.
For bare React Native projects, you must ensure that you have installed and configured the expo
package before continuing.
This module requires permissions to interact with the filesystem and create resumable downloads. The READ_EXTERNAL_STORAGE
, WRITE_EXTERNAL_STORAGE
and INTERNET
permissions are automatically added.
<!-- Added permissions -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
No additional set up necessary.
Contributions are very welcome! Please refer to guidelines described in the contributing guide.
FAQs
Provides access to the local file system on the device.
The npm package expo-file-system receives a total of 1,118,512 weekly downloads. As such, expo-file-system popularity was classified as popular.
We found that expo-file-system demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 32 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.