{"library":"react-native-fs","title":"React Native File System (react-native-fs)","description":"react-native-fs provides comprehensive native filesystem access for React Native applications across iOS, Android, and Windows platforms. It offers a robust API for common file operations such as reading, writing, and deleting files, managing directories, and facilitating advanced use cases like background file downloads and uploads with progress tracking. The library is actively maintained, with the current stable version being 2.20.0, and receives regular updates to address compatibility with new React Native versions and underlying OS changes, exemplified by recent fixes for iOS crashes and Android type corrections. A key differentiator is its direct native integration, enabling features like handling content URIs on Android and asset video URIs on iOS, which are crucial for complex media and document management within mobile applications. It carefully manages compatibility across various React Native versions, requiring specific `react-native-fs` versions depending on the host `react-native` and Gradle versions, highlighting its sensitivity to the broader ecosystem.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install react-native-fs"],"cli":null},"imports":["import RNFS from 'react-native-fs';","import RNFS from 'react-native-fs';\nconst path = RNFS.DocumentDirectoryPath;","const RNFS = require('react-native-fs');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import RNFS from 'react-native-fs';\n\nconst fileName = 'test.txt';\nconst content = 'Hello from react-native-fs!';\nconst filePath = `${RNFS.TemporaryDirectoryPath}/${fileName}`;\n\nasync function runFsExample() {\n  try {\n    // 1. Write a file\n    await RNFS.writeFile(filePath, content, 'utf8');\n    console.log(`File written to: ${filePath}`);\n\n    // 2. Read the file\n    const readContent = await RNFS.readFile(filePath, 'utf8');\n    console.log(`File content: ${readContent}`);\n\n    if (readContent !== content) {\n      throw new Error('Content mismatch!');\n    }\n\n    // 3. Check if file exists\n    const exists = await RNFS.exists(filePath);\n    console.log(`File exists: ${exists}`);\n\n    // 4. Get file stats\n    const statResult = await RNFS.stat(filePath);\n    console.log(`File size: ${statResult.size} bytes`);\n\n    // 5. Delete the file\n    await RNFS.unlink(filePath);\n    console.log(`File deleted: ${filePath}`);\n\n    const deletedExists = await RNFS.exists(filePath);\n    console.log(`File exists after deletion: ${deletedExists}`);\n\n  } catch (error) {\n    console.error('An error occurred during FS operations:', error);\n  }\n}\n\nrunFsExample();","lang":"typescript","description":"This example demonstrates basic file operations: writing a string to a temporary file, reading its content, checking its existence, retrieving its statistics, and finally deleting it. It uses `RNFS.TemporaryDirectoryPath` for cross-platform compatibility.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}