How to use the expo-file-system.readAsStringAsync function in expo-file-system

To help you get started, we’ve selected a few expo-file-system 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 flow-typed / flow-typed / definitions / npm / expo-file-system_v4.x.x / flow_v0.69.0-v0.103.x / test_expo-file-system.js View on Github external
it('should passes when used properly', () => {
    readAsStringAsync('fileUri').then(fileInfo => {
      (fileInfo: string);

      // $ExpectError: check any
      (fileInfo: number);
    });

    readAsStringAsync('fileUri', { encoding: 'base64' });
    readAsStringAsync('fileUri', { position: 1 });
    readAsStringAsync('fileUri', { length: 1 });
    readAsStringAsync('fileUri', {
      encoding: 'utf8',
      position: 1,
      length: 1,
    });
  });
github expo / expo-three / src / loaders / readAsStringAsync.ts View on Github external
if (Platform.OS === 'web') {
    const loader = new THREE.FileLoader();
    return new Promise((resolve, reject) =>
      loader.load(
        localUri,
        async value => {
          // @ts-ignore
          resolve(await value);
        },
        () => {},
        reject,
      ),
    );
  }
  try {
    return await readAsStringAsync(localUri);
  } catch ({ message }) {
    throw new Error(
      `ExpoTHREE: FileSystem.readAsStringAsync(${localUri}) ${message}`,
    );
  } finally {
    if (global.__expo_three_log_loading) {
      console.timeEnd('loadAsset');
    }
  }
}
github bytefury / crater-mobile / src / components / FilePicker / index.js View on Github external
const { mediaType = 'Images' } = this.props

        let result = await ImagePicker.launchImageLibraryAsync({
            mediaTypes: ImagePicker.MediaTypeOptions[mediaType],
            // mediaTypes: ImagePicker.MediaTypeOptions.All,
            allowsEditing: mediaType === 'Images' ? true : false,
            base64: true,
            quality: 1,
        });

        if (!result.cancelled) {
            const { onChangeCallback, input: { onChange } } = this.props
            this.setState({ image: result.uri });

            FileSystem.readAsStringAsync(result.uri, {
                encoding: FileSystem.EncodingType.Base64
            }).then((base64) => {
                const res = { ...result, base64 }
                onChangeCallback(res)
                this.onToggleLoading()
            })
                .catch(error => {
                    console.error(error);
                });
        }
        else {
            this.onToggleLoading()
        }
    };
github bugsnag / bugsnag-js / packages / delivery-expo / queue.js View on Github external
async peek () {
    try {
      const payloads = await FileSystem.readDirectoryAsync(this._path)
      const payloadFileName = payloads.filter(f => filenameRe.test(f)).sort()[0]
      if (!payloadFileName) return null
      const id = `${this._path}/${payloadFileName}`

      try {
        const payloadJson = await FileSystem.readAsStringAsync(id)
        const payload = JSON.parse(payloadJson)
        return { id, payload }
      } catch (e) {
        // if we got here it's because
        // a) JSON.parse failed or
        // b) the file can no longer be read (maybe it was truncated?)
        // in both cases we want to speculatively remove it and try peeking again
        await this.remove(id)
        return this.peek()
      }
    } catch (e) {
      this._onerror(e)
      return null
    }
  }
github reggie3 / react-native-webview-quilljs / WebViewQuillJS / WebViewQuill.tsx View on Github external
private loadHTMLFile = async () => {
    try {
      let asset: Asset = await AssetUtils.resolveAsync(INDEX_FILE_PATH);
      let fileString: string = await FileSystem.readAsStringAsync(
        asset.localUri
      );

      this.setState({ webviewContent: fileString });
    } catch (error) {
      console.warn(error);
      console.warn("Unable to resolve index file");
    }
  };
github Nohac / redux-persist-expo-fs-storage / lib / index.js View on Github external
const getItem = (key, callback) => withCallback(callback, async () => {
    const pathKey = pathForKey(key);
    const { exists } = await FileSystem.getInfoAsync(pathKey);
    if (exists) {
      return await FileSystem.readAsStringAsync(pathKey);
    }
  });
github expo / expo-pixi / lib / spineAsync.js View on Github external
async function jsonFromResourceAsync(resource) {
  const jsonUrl = await uriAsync(resource);
  const jsonString = await readAsStringAsync(jsonUrl);
  return JSON.parse(jsonString);
}
github expo / expo / apps / native-component-list / src / screens / FileSystemScreen.tsx View on Github external
_copyAndReadAsset = async () => {
    const asset = Asset.fromModule(require('../../assets/index.html'));
    await asset.downloadAsync();
    const tmpFile = FileSystem.cacheDirectory + 'test.html';
    try {
      await FileSystem.copyAsync({ from: asset.localUri!, to: tmpFile });
      const result = await FileSystem.readAsStringAsync(tmpFile);
      Alert.alert('Result', result);
    } catch (e) {
      Alert.alert('Error', e.message);
    }
  }
github Nohac / redux-persist-expo-fs-storage / index.js View on Github external
withCallback(callback, async () => {
      const pathKey = pathForKey(key);
      const { exists } = await FileSystem.getInfoAsync(pathKey);
      if (exists) {
        return await FileSystem.readAsStringAsync(pathKey);
      }
    });