
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
react-native-fs2
Advanced tools
A fork of react-native-fs with a smaller footprint and fixes due to the upstream library seemingly being abandoned.
This library intentional or not has become critical to the success of our mobile applications. We've noticed a few things that led to this fork:
We debated a few paths, but we felt it best to fork the project and make some major changes that will upset some.
We will continue to support this library for as long as we use it.
npm i --save react-native-fs2
react-native-fs2 | react-native |
---|---|
3.0.x | >=0.69 |
Changes can be found in CHANGELOG.md
import RNFS from 'react-native-fs2';
console.log(await RNFS.getFSInfo());
mkdir
// mkdir(filepath: string, options?: MkdirOptions): Promise<undefined>
await RNFS.mkdir(`FolderToCreate`);
filepath
location.MkdirOptions
with properties:
moveFile
// moveFile(filepath: string, destPath: string, options?: FileOptions): Promise<undefined>
await RNFS.moveFile('FileToMove', 'DestinationLocation')
filepath
to destPath
FileOptions
with properties:
copyFile
// copyFile(filepath: string, destPath: string, options?: FileOptions): Promise<undefined>
await RNFS.copyFile('FileToCopy', 'DestinationLocation')
filepath
to destPath
FileOptions
with properties:
getFSInfo
// getFSInfo(): Promise<FSInfoResult>
const fsInfo = await RNFS.getFSInfo()
FSInfoResult
object that contains information on the device storage spaceFSInfoResult
number
-> The total amount of storage space on the device (in bytes).number
-> The amount of available storage space on the device (in bytes)getAllExternalFilesDirs
(Android only)// getAllExternalFilesDirs(): Promise<string[]>
const externalFileDirs = await RNFS.getAllExternalFilesDirs()
array
with the absolute paths to application-specific directories on all shared/external storage devices where the application can place persistent files it owns.unlink
// unlink(filepath: string): Promise<void>
await RNFS.unlink('FileToUnlink')
filepath
. If the item does not exist, an error will be thrown.
Also recursively deletes directories (works like Linux rm -rf
).exists
// exists(filepath: string): Promise<boolean>
await RNFS.exists('File')
filepath
. If the item does not exist, return false.completeHandlerIOS
(iOS Only)// completeHandlerIOS(jobId: number): void
await RNFS.completeHandler('JobID')
readDir
// readDir(dirPath: string): Promise<ReadDirItem[]>
const dirItems = await RNFS.readDir('DirPath')
array
of ReadDirItem
which are items that are present in the directoryReadDirItem
Date | undefined
-> The creation date of the file (iOS only)Date | undefined
-> The last modified date of the filestring
-> The name of the itemstring
-> The absolute path to the itemnumber
-> Size in bytesboolean
-> Is the file just a file?boolean
-> Is the file a directory?readFile
// readFile(filepath: string, encodingOrOptions?: EncodingOrOptions): Promise<string>
const fileData = await RNFS.readFile('DirPath', 'utf8')
filepath
and return the file contents
EncodingOrOptions
with values:
'utf8'
(default) | 'base64'
(for binary files) | 'ascii'
| 'arraybuffer'
arraybuffer
requires react-native-blob-jsi-helper
npm i react-native-blob-jsi-helper
or yarn add react-native-blob-jsi-helper
read
/*
read(
filepath: string,
length: number = 0,
position: number = 0,
encodingOrOptions?: EncodingOrOptions
): Promise<string>
*/
const fileData = await RNFS.read('FileToRead', 0, 0, 'utf8')
filepath
and returns the file contents
.EncodingOrOptions
with values:
'utf8'
(default) | 'base64'
(for binary files) | 'ascii'
hash
// hash(filepath: string, algorithm: string): Promise<string>
const fileChecksum = await RNFS.hash('FileToHash', 'md5')
filepath
and returns its checksum as determined by algorithm, which can be one of the following md5
| sha1
| sha224
| sha256
| sha384
| sha512
.writeFile
// writeFile(filepath: string, contents: string, encodingOrOptions?: EncodingOrOptions): Promise<void>
await RNFS.write('FileToWrite', 'ContentsToWrite', 'utf8')
contents
to filepath
EncodingOrOptions
with values:
'utf8'
(default) | 'base64'
(for binary files) | 'ascii'
appendFile
// appendFile(filepath: string, contents: string, encodingOrOptions?: EncodingOrOptions): Promise<void>
await RNFS.appendFile('FileToWrite', 'ContentsToAppend', 'utf8')
contents
to filepath
EncodingOrOptions
with values:
'utf8'
(default) | 'base64'
(for binary files) | 'ascii'
write
// write(filepath: string, contents: string, position?: number, encodingOrOptions?: EncodingOrOptions): Promise<void>
await RNFS.write('FileToWrite', 'ContentsToWrite', -1, 'utf8')
contents
to filepath
at the given random access position. When position is undefined or -1 the contents is appended to the end of the fileEncodingOrOptions
with values:
'utf8'
(default) | 'base64'
(for binary files) | 'ascii'
stat
// stat(filepath: string): Promise<StatResult>
const fileStats = await RNFS.stat('FilePath')
array
of StatResult
which are statistics
of the file
StatResult
string
-> The same as filepath argumentdate
-> The creation date of the filedate
-> The last modified date of the filenumber
-> Size in bytesnumber
-> UNIX file modestring
-> Android: In case of content uri this is the pointed file path, otherwise is the same as pathboolean
-> Is the file just a file?boolean
-> Is the file a directory?downloadFile
// downloadFile(options: DownloadFileOptions): { jobId: number, promise: Promise<DownloadResult> }
const downloadResults = await RNFS.downloadFile('FilePath')
options.fromUrl
to options.toFile
. Will overwrite any previously existing file.
DownloadFileOptions
with properties
string
-> URL to download file fromstring
-> Local filesystem path to save the file toHeaders
-> An object of headers to be passed to the serverboolean
-> Continue the download in the background after the app terminates (iOS only)boolean
-> Allow the OS to control the timing and speed of the download to improve perceived performance (iOS only)boolean
number
number
(res: DownloadBeginCallbackResult) => void;
-> Note: it is required when progress prop provided(res: DownloadProgressCallbackResult) => void
;() => void
-> only supported on iOSnumber
-> only supported on Androidnumber
-> supported on Android and iOSnumber
-> Maximum time (in milliseconds) to download an entire resource (iOS only, useful for timing out background downloads)
DownloadResult
number
-> The download job ID, required if one wishes to cancel the download. See stopDownload
.number
-> The HTTP status codenumber
-> The number of bytes written to the filestopDownload
// stopDownload(jobId: number): void
await RNFS.stopDownload('JobID'): void
resumeDownload
(iOS Only)// resumeDownload(jobId: number): void
await RNFS.resumeDownload('JobID'): void
isResumable
(iOS Only)// isResumable(jobId: number): Promise<bool>
if (await RNFS.isResumable('JobID')) {
RNFS.resumeDownload('JobID')
}
touch
// touch(filepath: string, mtime?: Date, ctime?: Date): Promise<void>
await RNFS.touch('FilePath', Date, Date)
mtime
and creation timestamp ctime
of the file at filepath
. Setting ctime
is only supported on iOS, Android always sets both timestamps to mtime
.scanFile
(Android Only)// scanFile(path: string): Promise<string[]>
await RNFS.scanFile('FilePath', Date, Date)
RNFS2 can now interact with the MediaStore on Android. This allows you to add, delete, and update media files in the MediaStore.
<!-- Required only if your app needs to access images or photos that other apps created. -->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<!-- Required only if your app needs to access videos that other apps created. -->
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<!-- Required only if your app needs to access audio files that other apps created. -->
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29" />
createMediaFile
mimeType
. This will not create a file on the filesystem, but will create a reference in the MediaStore.// createMediaFile(fileDescriptor: FileDescriptor, mediatype: MediaCollections): Promise<string>
const fileDescriptor = { name: 'sample', parentFolder: 'MyAppFolder', mimeType: 'image/png' }
const contentURI = await RNFS.MediaStore.createMediaFile(fileDescriptor, RNFS.MediaStore.MEDIA_IMAGE)
updateMediaFile
// updateMediaFile(uri: string, fileDescriptor: FileDescriptor, mediatype: MediaCollections): Promise<string>
const contentURI = 'content://media/external/images/media/123'
const fileDescriptor = { name: 'sample-updated-filename', parentFolder: 'MyAppFolder', mimeType: 'image/png' }
const contentURI = await RNFS.MediaStore.updateMediaFile(contentURI, fileDescriptor, RNFS.MediaStore.MEDIA_IMAGE)
writeToMediaFile
mimeType
.// writeToMediaFile((uri: string, path: string): Promise<void>
await RNFS.MediaStore.writeToMediaFile('content://media/external/images/media/123', '/path/to/image/imageToWrite.png')
copyToMediaStore
filepath
to the MediaStore with the given mimeType
.// copyToMediaStore(fileDescriptor: filedescriptor, mediatype: MediaCollections, path: string): Promise<string>
const fileDescriptor = { name: 'sample', parentFolder: 'MyAppFolder', mimeType: 'image/png' }
const contentURI = await RNFS.MediaStore.copyToMediaStore(fileDescriptor, RNFS.MediaStore.MEDIA_IMAGE, '/path/to/image/imageToCopy.png')
queryMediaStore
searchOptions
.// queryMediaStore(searchOptions: MediaStoreSearchOptions): Promise<MediaStoreQueryResult>
await RNFS.MediaStore.queryMediaStore({
uri: 'content://media/external/images/media/123',
fileName: ''
relativePath: ''
mediaType: RNFS.MediaStore.MEDIA_IMAGE;
})
// or
await RNFS.MediaStore.queryMediaStore({
uri: '',
fileName: 'image.png'
relativePath: 'MyAppFolder'
mediaType: RNFS.MediaStore.MEDIA_IMAGE;
})
deleteFromMediaStore
uri
from the MediaStore.// deleteFromMediaStore(uri: string): Promise<boolean>
await RNFS.MediaStore.deleteFromMediaStore('content://media/external/images/media/123')
type FileDescriptor = {
name: string;
parentFolder: string;
mimeType: string
};
type MediaStoreSearchOptions = {
uri: string;
fileName: string;
relativePath: string;
mediaType: MediaCollections
};
type MediaStoreQueryResult = {
contentUri: string;
};
MediaStore.MEDIA_AUDIO
- Audio media collectionMediaStore.MEDIA_IMAGE
- Image media collectionMediaStore.MEDIA_VIDEO
- Video media collectionMediaStore.MEDIA_DOWNLOAD
- Download media collectionCachesDirectoryPath
- Absolute path to cache directory.DocumentDirectoryPath
- Absolute path to the document directory.TemporaryDirectoryPath
- Absolute path to temporary directory (cache on Android).ExternalCachesDirectoryPath
- Absolute path to the external cache directory.ExternalDirectoryPath
- Absolute path to external shared directory.ExternalStorageDirectoryPath
- Absolute path to the external shared storage directory.DownloadDirectoryPath
- Absolute path to the download directory.Please be sure to request needed permissions via PermissionsAndroid.
LibraryDirectoryPath
- Absolute path to NSLibraryDirectoryMainBundlePath
- Absolute path to main bundle directory.FAQs
Native filesystem access for react-native
The npm package react-native-fs2 receives a total of 104 weekly downloads. As such, react-native-fs2 popularity was classified as not popular.
We found that react-native-fs2 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.