
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@rn-common/file
Advanced tools
This module provides a set of utility functions for working with the file system in React Native, using Expo's `FileSystem` API. It includes functions for creating directories, reading and writing files, deleting files and folders, and managing downloads.
@rn-common/file
This module provides a set of utility functions for working with the file system in React Native, using Expo's FileSystem
API. It includes functions for creating directories, reading and writing files, deleting files and folders, and managing downloads.
Install using:
npx expo install @rn-common/file expo-file-system
DocumentDirectory
: The document directory path.CacheDirectory
: The cache directory path.mkdir(dir: string)
Creates a new directory at the specified path, including any necessary intermediate directories.
Parameters:
dir
(string): The path of the directory to create.Returns:
Promise<void>
: Resolves when the directory is created.Example:
await mkdir('/path/to/new/directory')
readFile(filePath: string, options?: FileSystem.ReadingOptions)
Reads the contents of a file as a string.
Parameters:
filePath
(string): The path of the file to read.options
(FileSystem.ReadingOptions): Optional settings for reading the file.Returns:
Promise<string>
: The contents of the file.Example:
const contents = await readFile('/path/to/file.txt')
writeFile(filePath: string, contents: string, options?: FileSystem.WritingOptions)
Writes content to a file.
Parameters:
filePath
(string): The path of the file to write to.contents
(string): The content to write.options
(FileSystem.WritingOptions): Optional settings for writing the file.Returns:
Promise<void>
: Resolves when the file is written.Example:
await writeFile('/path/to/file.txt', 'Hello, World!')
removeFile(filePath: string)
Deletes a file at the specified path.
Parameters:
filePath
(string): The path of the file to delete.Returns:
Promise<void>
: Resolves when the file is deleted.Example:
await removeFile('/path/to/file.txt')
removeFolder(folderPath: string)
Deletes a folder and all its contents.
Parameters:
folderPath
(string): The path of the folder to delete.Returns:
Promise<void>
: Resolves when the folder and its contents are deleted.Example:
await removeFolder('/path/to/folder')
extractFilename(filePath: string, withExtension = true)
Extracts the filename from a given file path.
Parameters:
filePath
(string): The file path.withExtension
(boolean, default: true
): Whether to include the file extension.Returns:
string
: The extracted filename.Example:
const filename = extractFilename('/path/to/file.txt') // 'file.txt'
const nameWithoutExtension = extractFilename('/path/to/file.txt', false) // 'file'
extractExtension(filePath: string)
Extracts the file extension from a given file path.
Parameters:
filePath
(string): The file path.Returns:
string
: The file extension.Example:
const extension = extractExtension('/path/to/file.txt') // 'txt'
joinPath(...paths: string[])
Joins multiple path segments into a single path.
Parameters:
...paths
(string[]): Path segments.Returns:
string
: The combined path.Example:
const fullPath = joinPath('/path', 'to', 'file.txt') // '/path/to/file.txt'
createDownloadFile({ uri, filePath, options, onProgress })
Initiates a file download from a specified URI.
Parameters:
uri
(string): The URI of the file to download.filePath
(string): The local path to save the downloaded file.options
(FileSystem.DownloadOptions): Optional download settings.onProgress
(function): Callback for download progress.Returns:
Object
: Methods to control the download (download
, pause
, resume
, cancel
) and the uri
of the downloaded file.Example:
const { download, pause, resume, cancel, uri } = createDownloadFile({
uri: 'https://example.com/file.zip',
filePath: '/path/to/file.zip',
onProgress: (progress) => console.log(`Download progress: ${progress}%`),
})
await download()
FAQs
This module provides a set of utility functions for working with the file system in React Native, using Expo's `FileSystem` API. It includes functions for creating directories, reading and writing files, deleting files and folders, and managing downloads.
The npm package @rn-common/file receives a total of 0 weekly downloads. As such, @rn-common/file popularity was classified as not popular.
We found that @rn-common/file demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.