How to use the react-native-fs.readFile 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 smallpath / psnine / psnine / component / DiskStorage / index.ts View on Github external
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
    }
  }
github rakannimer / react-orchestra / native / src / MusicManager.js View on Github external
const loadMidi = async (midiURL) => {
  const midiKey = generateMidiKey(midiURL);
  const isInDB = await Store.exists('Midi', midiKey);
  let midiPath;
  // if (!isInDB) {
  //   alert('IS IN DB');
  //   midiPath = midiKeyToLocalPath(midiURL);
  // } else {
  const { localPath } = await getMidiFromRemote(midiURL);
  await Store.set('Midi', midiKey, { localPath, remotePath: midiURL });
  midiPath = localPath;
  // }
  let midifile;
  try {
    midifile = await RNFS.readFile(midiPath, 'base64');
  } catch (err) {
    alert(`ERROR Reading Midi from filesystem ${err.message}`);
  }
  let bytes;
  try {
    bytes = base64.decode(midifile);
  } catch (err) {
    alert(`ERROR decodign Midi from filesystem ${err.message}`);
  }

  let jsonMidi;
  let metaAndTracks;
  try {
    jsonMidi = midiFileParser(bytes);
    metaAndTracks = MidiIO.getAllTracks(jsonMidi);
  } catch (err) {
github le0zh / gitbook-reader-rn / src / screens / Reader / index.js View on Github external
_loadContent = src => {
    // 修改页面样式
    // todo: 修改字体大小,默认为 font-size: 1.125em;
    const fixedStyle = ' style="padding: 0 10px; font-size: 1em" ';
    const fixedMeta = '';

    RNFS.readFile(`${this.bookDir}/content/${src}`).then(content => {
      this.setState({
        content: content
          // .replace('', fixedMeta)
          .replace('
github tensorflow / tfjs / tfjs-react-native / src / bundle_resource_io.ts View on Github external
let base64Weights: string;
    if (Platform.OS === 'android') {
      // On android we get a resource id instead of a regular path. We need
      // to load the weights from the res/raw folder using this id.
      try {
        const fileName = `${weightsAsset.uri}.${weightsAsset.type}`;
        base64Weights = await RNFS.readFileRes(fileName, 'base64');
      } catch (e) {
        throw new Error(
            `Error reading resource ${weightsAsset.uri}. Make sure the file is
            in located in the res/raw folder of the bundle`,
        );
      }
    } else {
      try {
        base64Weights = await RNFS.readFile(weightsAsset.uri, 'base64');
      } catch (e) {
        throw new Error(
            `Error reading resource ${weightsAsset.uri}. Make sure the file is
            in located in the res/raw folder of the bundle`,
        );
      }
    }

    const weightData = util.encodeString(base64Weights, 'base64').buffer;
    const modelArtifacts: io.ModelArtifacts = Object.assign({}, modelJson);
    modelArtifacts.weightSpecs = modelJson.weightsManifest[0].weights;
    //@ts-ignore
    delete modelArtifacts.weightManifest;
    modelArtifacts.weightData = weightData;
    return modelArtifacts;
  }
github celo-org / celo-monorepo / packages / mobile / src / utils / Logger.ts View on Github external
getLogs = async (): Promise => {
    // TODO(Rossy) Does this technique of passing logs back as a string
    // fail when the logs get o big?
    try {
      const rnLogsSrc = this.getReactNativeLogsFilePath()
      const gethLogsSrc = this.getGethLogFilePath()
      let reactNativeLogs = null
      let gethLogs = null
      if (await RNFS.exists(rnLogsSrc)) {
        reactNativeLogs = await RNFS.readFile(rnLogsSrc)
      }
      if (await RNFS.exists(gethLogsSrc)) {
        gethLogs = await RNFS.readFile(gethLogsSrc)
      }

      return { reactNativeLogs, gethLogs }
    } catch (e) {
      this.showError('Failed to read logs: ' + e)
      return null
    }
  }
github anchetaWern / RNChatkitDemo / src / screens / Chat.js View on Github external
}, async (err, file) => {
      if (!err) {

        try {
          const file_type = mime.contentType(file.fileName);
          const base64 = await RNFS.readFile(file.uri, "base64");

          const file_blob = await Blob.build(base64, { type: `${file_type};BASE64` });

          this.attachment = {
            file_blob: file_blob,
            file_name: file.fileName,
            file_type: file_type
          };

          Alert.alert("Success", "File attached!");

        } catch (attach_err) {
          console.log("error attaching file: ", attach_err);
        }
      }
github goldennetwork / golden-wallet-react-native / app / modules / DAppBrowser / DAppBrowserScreen.js View on Github external
componentWillMount() {
    if (jsContent === '') {
      if (Platform.OS === 'ios') {
        RNFS.readFile(`${RNFS.MainBundlePath}/GoldenProvider.js`, 'utf8')
          .then((content) => {
            jsContent = content
            this.setState({})
          })
      } else {
        RNFS.readFileAssets(`GoldenProvider.js`, 'utf8')
          .then((content) => {
            jsContent = content
            this.setState({})
          })
      }
    }
  }
github strivert / react-native-real-property-reports / src / components / Molecule / CameraPic.js View on Github external
.then((data) => {

        RNFS.readFile(data.path.substring(7), "base64").then(res => {
          this.setState({
            isAfterTake: true,
            tempImage: res,
            isCamera: false
          })
          /*
          this.setState(
            update(this.state, {
              images: { 
                $push: [{
                  'backImage': res,
                  'drawImage': ''
                }]
              },
              isCamera: {$set: false},
              selectedIndex: {$set: 0},
github goldennetwork / golden-wallet-react-native / app / modules / WalletList / screen / HomeScreen.js View on Github external
openShare = (filePath) => {
    MainStore.appState.mixpanleHandler.track(MixpanelHandler.eventName.ACTION_SHARE)
    NavStore.preventOpenUnlockScreen = true
    RNFS.readFile(filePath, 'base64').then((file) => {
      const shareOptions = {
        title: 'Golden',
        message: `My address: ${MainStore.appState.selectedWallet.address}`,
        url: `data:image/png;base64,${file}`
      }
      Share.open(shareOptions).catch(() => { })
    })
  }