Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'react-native-fs' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
itemTestsuite.att('name', suiteName);
itemTestsuite.att('tests', nbrTests);
itemTestsuite.att('failures', nbrFailures);
itemTestsuite.att('timestamp', "2016-01-22T14:40:44.874443-05:00");//TODO use real timestamp
}
// export unit tests results
let xmlString = rootXml.end({
pretty: true,
indent: ' ',
newline: '\n',
});
// write the unit tests reports
const path = RNFS.MainBundlePath + "/tests.xml";
await RNFS.writeFile(path, xmlString, 'utf8');
//using console.log output is not shown in Release builds. using console.warn
console.warn(xmlString);
console.warn('__REALM_JS_TESTS_COMPLETED__');
if (failingTests.length !== 0) {
console.error('\n\nREALM_FAILING_TESTS\n');
console.error(failingTests);
}
}
catch (e) {
console.error(e);
}
finally {
console.warn("Realm Tests App finished. Exiting. Disable this to debug the app locally");
RNExitApp.exitApp();
}
import * as RNFS from 'react-native-fs';
// get a list of files and directories in the main bundle
RNFS.readDir(RNFS.MainBundlePath) // On Android, use "RNFS.DocumentDirectoryPath" (MainBundlePath is not defined)
.then((result) => {
console.log('GOT RESULT', result);
// stat the first file
return Promise.all([RNFS.stat(result[0].path), result[0].path]);
})
.then((statResult) => {
if (statResult[0].isFile()) {
// if we have a file, read it
return RNFS.readFile(statResult[1], 'utf8');
}
return 'no file';
})
.then((contents) => {
// log the file contents
import React from 'react'
import fs from 'react-native-fs'
import ImageViewer from 'react-native-image-zoom-viewer'
import {
Animated,
Easing,
CameraRoll
} from 'react-native'
declare var global
const psnineFolder = fs.DocumentDirectoryPath + '/psnine'
fs.stat(psnineFolder).then(data => {
const isDirectory = data.isDirectory()
if (!isDirectory) {
fs.unlink(psnineFolder).catch(() => {}).then(() => fs.mkdir(psnineFolder))
}
}).catch(() => {
fs.mkdir(psnineFolder).catch(err => console.log(err, 'ImageViewer:line#27'))
})
const onSave = (image) => {
// console.log(image, psnineFolder + '/' + image.split('/').pop())
const result = CameraRoll.saveToCameraRoll(image)
return result.then((url) => {
global.toast('保存成功')
return url
import React from 'react'
import fs from 'react-native-fs'
import ImageViewer from 'react-native-image-zoom-viewer'
import {
Animated,
Easing,
CameraRoll
} from 'react-native'
declare var global
const psnineFolder = fs.DocumentDirectoryPath + '/psnine'
fs.stat(psnineFolder).then(data => {
const isDirectory = data.isDirectory()
if (!isDirectory) {
fs.unlink(psnineFolder).catch(() => {}).then(() => fs.mkdir(psnineFolder))
}
}).catch(() => {
fs.mkdir(psnineFolder).catch(err => console.log(err, 'ImageViewer:line#27'))
})
const onSave = (image) => {
// console.log(image, psnineFolder + '/' + image.split('/').pop())
const result = CameraRoll.saveToCameraRoll(image)
return result.then((url) => {
global.toast('保存成功')
return url
}).catch(err => global.toast('保存失败: ' + err.toString()))
}
import {
ToastAndroid,
View,
Animated,
Easing,
StatusBar,
Text
} from 'react-native'
import fs from 'react-native-fs'
import { ViewPagerZoom } from 'react-native-image-zoom'
import PhotoView from 'react-native-photo-view'
declare var global
const psnineFolder = fs.ExternalStorageDirectoryPath + '/psnine'
console.log('==========================>')
fs.stat(psnineFolder).then(data => {
const isDirectory = data.isDirectory()
if (!isDirectory) {
fs.unlink(psnineFolder).catch(() => { }).then(() => fs.mkdir(psnineFolder))
}
}).catch(() => {
fs.mkdir(psnineFolder).catch(err => console.log(err, 'ImageViewer:line#27'))
})
const onSave = (image) => {
// console.log(image, psnineFolder + '/' + image.split('/').pop())
const result = fs.downloadFile({
fromUrl: image,
toFile: psnineFolder + '/' + image.split('/').pop()
})
export default async function photosTask (dispatch, failedImages) {
// console.log('FAILED IMAGES:', failedImages)
console.log('running photos task')
BackgroundTimer.start() // This requests some background time from the OS
// Start IPFS
const path = RNFS.DocumentDirectoryPath
await IPFS.createNodeWithDataDir(path)
await IPFS.startNode()
// Get a list of the jobs already in the queue
// const existingJobs = await queue.getJobs(true)
// Query for any new photos, add jobs to queue
const photos = await queryPhotos()
// PushNotificationIOS.presentLocalNotification({
// alertBody: 'fetch of ' + photos.length + ' photos',
// userInfo: {}
// })
for (const photo of photos) {
const multipartData = await IPFS.addImageAtPath(photo.node.image.path, photo.node.image.thumbPath)
await RNFS.unlink(photo.node.image.path)
await RNFS.unlink(photo.node.image.thumbPath)
async function _deleteConfiguration(): Promise < void > {
try {
const configVersions : Array < Object > = await Database.getConfigVersions();
const clearVersions: Array < Object > = [];
if (configVersions == null) {
return;
}
for (let i = 0; i < configVersions.length; i++) {
try {
const dir = CONFIG_SUBDIRECTORIES[configVersions[i].type];
await RNFS.unlink(CONFIG_DIRECTORY + dir + configVersions[i].name);
} catch (e) {
// do nothing - file doesn't exist
}
clearVersions.push({
name: configVersions[i].name,
type: configVersions[i].type,
version: 0,
});
}
await Database.updateConfigVersions(clearVersions);
await RNFS.unlink(CONFIG_DIRECTORY);
} catch (err) {
console.log('Error accessing database while clearing versions.', err);
}
}
await RNFS.moveFile(
TEMP_CONFIG_DIRECTORY + configurationUpdates[i].name,
CONFIG_DIRECTORY + CONFIG_SUBDIRECTORIES[configurationUpdates[i].type] + configurationUpdates[i].name
);
configRowUpdates.push({
name: configurationUpdates[i].name,
type: configurationUpdates[i].type,
version: configurationUpdates[i].newVersion,
});
}
// Delete temporary downloads
await RNFS.unlink(TEMP_CONFIG_DIRECTORY);
// Update config versions in database
await Database.updateConfigVersions(configRowUpdates);
university = null;
await module.exports.init();
} catch (e) {
throw e;
}
}
async getItem(key) {
const filePath = this.psnineFolder + `/${en(key)}.json`
try {
const content = await fs.readFile(filePath, 'utf8')
// console.log(content)
return content
} catch (err) {
// console.log(err)
return null
}
}
shareMessage = () => {
const { currencyCode, publicAddress } = this.props
let sharedAddress = this.state.encodedURI
// if encoded (like XTZ), only share the public address
if (currencyCode && Constants.getSpecialCurrencyInfo(currencyCode).isUriEncodedStructure) {
sharedAddress = publicAddress
}
const title = sprintf(s.strings.request_qr_email_title, s.strings.app_name, currencyCode)
const message = sprintf(s.strings.request_qr_email_title, s.strings.app_name, currencyCode) + ': ' + sharedAddress
const path = Platform.OS === Constants.IOS ? RNFS.DocumentDirectoryPath + '/' + title + '.txt' : RNFS.ExternalDirectoryPath + '/' + title + '.txt'
RNFS.writeFile(path, message, 'utf8')
.then(success => {
const url = Platform.OS === Constants.IOS ? 'file://' + path : ''
const shareOptions = {
url,
title,
message: sharedAddress
}
Share.open(shareOptions).catch(e => console.log(e))
})
.catch(showError)
}