How to use the expo-file-system.FileSystem 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 expo / expo-asset-utils / dist / index.js View on Github external
async function fileInfoAsync(url, name) {
  if (!url) {
    console.error('fileInfoAsync: cannot load from empty url!');
    return null;
  }
  name = name || filenameFromUri(url);
  const localUri = expoFileSystem.FileSystem.cacheDirectory + name;

  if (isAssetLibraryUri(url)) {
    /// ios asset: we need to copy this over and then get the hash
    await expoFileSystem.FileSystem.copyAsync({
      from: url,
      to: localUri,
    });
    const hash = await getHashAsync(localUri);
    return { uri: localUri, name, hash };
  } else if (isLocalUri(url)) {
    /// local image: we just need the hash
    let file = await resolveLocalFileAsync({ uri: url, name });
    if (!file) {
      file = await resolveLocalFileAsync({ uri: localUri, name });
      if (!file) {
        console.error(
          "ExpoAssetUtils.fileInfoAsync: couldn't resolve md5 hash for local uri: " +
            url +
            ' or alternate: ' +
            localUri
github expo / expo / packages / expo-asset / src / Asset.js View on Github external
import { PixelRatio, Platform } from 'react-native';
import AssetRegistry from 'react-native/Libraries/Image/AssetRegistry';
import AssetSourceResolver from 'react-native/Libraries/Image/AssetSourceResolver';
import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';
import uriparser from 'uri-parser';
import urljoin from 'url-join';

let FS, Constants;

try {
  FS = require('expo-file-system').FileSystem;
} catch (error) {
  throw new Error('`expo-asset` requires `expo-file-system` package to be installed and linked.');
}

try {
  Constants = require('expo-constants').default;
} catch (error) {
  throw new Error('`expo-asset` requires `expo-constants` package to be installed and linked.');
}

const parser = new uriparser.Parser();

// Fast lookup check if assets are available in the local bundle.
const bundledAssets = new Set(FS.bundledAssets || []);

// Fast lookup check if asset map has any overrides in the manifest
github expo / expo / modules / expo-asset / src / Asset.js View on Github external
import uriparser from 'uri-parser';
import urljoin from 'url-join';
import { PixelRatio, Platform } from 'react-native';
import AssetRegistry from 'react-native/Libraries/Image/AssetRegistry';
import AssetSourceResolver from 'react-native/Libraries/Image/AssetSourceResolver';
import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';

let FS, Constants;

try {
  FS = require('expo-file-system').FileSystem;
} catch (error) {
  throw new Error('`expo-asset` requires `expo-file-system` package to be installed and linked.');
}

try {
  Constants = require('expo-constants').Constants;
} catch (error) {
  throw new Error('`expo-asset` requires `expo-constants` package to be installed and linked.');
}

const parser = new uriparser.Parser();

// Fast lookup check if assets are available in the local bundle.
const bundledAssets = new Set(FS.bundledAssets || []);

// Fast lookup check if asset map has any overrides in the manifest
github expo / expo-asset-utils / dist / index.js View on Github external
async function copyAssetToSameDirectoryWithNewNameAsync(
  fileReference,
  name
) {
  const url = await uriAsync(fileReference);
  const nextUrl = replaceNameInUri(url, name);
  await expoFileSystem.FileSystem.copyAsync({ from: url, to: nextUrl });
  return nextUrl;
}