How to use the react-native-fs.writeFile function in react-native-fs

To help you get started, we’ve selected a few react-native-fs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github realm / realm-js / tests / react-test-app / index.ios.js View on Github external
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();
    }
github EdgeApp / edge-react-gui / src / components / scenes / RequestScene.js View on Github external
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)
  }
github microsoft / appcenter-sdk-react-native / TestApp / app / AttachmentsProvider.js View on Github external
async function saveFileInDocumentsFolder(data) {
  const path = `${RNFS.DocumentDirectoryPath}/${BINARY_ATTACHMENT_STORAGE_FILENAME}`;
  RNFS.writeFile(path, data, DEFAULT_ENCODING)
    .then(() => console.log('Binary attachment saved'))
    .catch(err => console.error(err.message));
}
github ptmt / using-async-storage-in-react-native / App.js View on Github external
const queries = [];
    for (const [index, amount] of amounts.entries()) {
      const result = await measureQueries(amount);
      queries.push(result);
      setState({
        progress: `queries: ${Math.round(index * 100 / amounts.length)}%`,
      });
    }

    const report = {
      writes,
      reads,
      queries,
    };

    await RNFS.writeFile(path, JSON.stringify(report), 'utf8');
    running = false;
    return path;
  } catch (e) {
    console.error(e);
    running = false;
    return 'Error';
  }
}
github iotaledger / trinity-wallet / src / mobile / containers / PaperWallet.js View on Github external
static callback(dataURL) {
        RNFS.writeFile(qrPath, dataURL, 'base64');
    }
github celo-org / celo-monorepo / packages / mobile / src / web3 / saga.ts View on Github external
async function savePrivateKeyToLocalDisk(
  account: string,
  privateKey: string,
  encryptionPassword: string
) {
  ensureAddressAndKeyMatch(account, privateKey)
  const filePath = getPrivateKeyFilePath(account)
  const plainTextData = privateKey
  const encryptedData: Buffer = getEncryptedData(plainTextData, encryptionPassword)
  Logger.debug('savePrivateKeyToLocalDisk', `Writing encrypted private key to ${filePath}`)
  await RNFS.writeFile(getPrivateKeyFilePath(account), encryptedData.toString('hex'))
}
github laurent22 / joplin / ReactNativeClient / lib / fs-driver-rn.js View on Github external
writeFile(path, string, encoding = 'base64') {
		return RNFS.writeFile(path, string, encoding);
	}
github celo-org / celo-monorepo / packages / mobile / src / qrcode / utils.ts View on Github external
svg.toDataURL(async (data: string) => {
    const path = RNFS.DocumentDirectoryPath + QRFileName
    try {
      await RNFS.writeFile(path, data, 'base64')
      Share.open({
        url: 'file://' + path,
        type: 'image/png',
      }).catch((err: Error) => {
        throw err
      })
    } catch (e) {
      Logger.warn(TAG, e)
    }
  })
}
github celo-org / celo-monorepo / packages / mobile / src / geth / geth.ts View on Github external
async function writeGenesisBlock(nodeDir: string, genesisBlock: string) {
  Logger.debug(`writeGenesisBlock genesis block is: "${genesisBlock}"`)
  const genesisBlockFile = getGenesisBlockFile(nodeDir)
  await RNFS.mkdir(getFolder(genesisBlockFile))
  await RNFS.writeFile(genesisBlockFile, genesisBlock, 'utf8')
}