How to use the expo-file-system.copyAsync 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', () => {
    copyAsync({ from: '', to: '' }).then(fileInfo => {
      (fileInfo: void);

      // $ExpectError: check any
      (fileInfo: number);
    });
  });
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 raises an error when pass invalid arguments', () => {
    // $ExpectError: first argument is required
    copyAsync();
    // $ExpectError: first argument must be an object
    copyAsync(69);
    // $ExpectError: need 'to' prop
    copyAsync({ from: '' });
    // $ExpectError: need 'from' prop
    copyAsync({ to: '' });
    copyAsync({
      // $ExpectError: need string
      from: 69,
      // $ExpectError: need string
      to: 69,
    });
  });
});
github expo / expo-asset-utils / src / fileInfoAsync.js View on Github external
async function fileInfoAsync(url: ?string, name: string): Promise {
  if (!url) {
    throw new Error('expo-asset-utils: fileInfoAsync(): cannot load from empty url!');
    return null;
  }
  name = name || filenameFromUri(url);

  if (Platform.OS === 'web') {
    return { uri: url, name, hash: null };
  }

  const localUri = FileSystem.cacheDirectory + name;

  if (isAssetLibraryUri(url)) {
    /// ios asset: we need to copy this over and then get the hash
    await 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) {
        throw new Error(
          `expo-asset-utils: fileInfoAsync(): couldn't resolve md5 hash for local uri: ${url} or alternate: ${localUri}`
        );
        return null;
      }
github expo / expo / packages / expo / build / DataMigrationHelper.js View on Github external
async function treeSearch(relativePath, legacyPath, newPath, resolveConflict) {
    const currentNewPath = `${newPath}${relativePath}`;
    const currentLegacyPath = `${legacyPath}${relativePath}`;
    const legacyPathInfo = await FileSystem.getInfoAsync(currentLegacyPath);
    const newPathInfo = await FileSystem.getInfoAsync(currentNewPath);
    if (legacyPathInfo.exists && !newPathInfo.exists) {
        await FileSystem.copyAsync({
            from: currentLegacyPath,
            to: currentNewPath,
        });
        await FileSystem.deleteAsync(currentLegacyPath);
        return;
    }
    if (legacyPathInfo.isDirectory) {
        const children = await FileSystem.readDirectoryAsync(currentLegacyPath);
        for (let child of children) {
            await treeSearch(relativePath + `${child}/`, legacyPath, newPath, resolveConflict);
        }
    }
    else {
        await resolveConflict(currentLegacyPath, currentNewPath);
    }
}
github expo / expo / home / utils / ImageSelectionUtils.ts View on Github external
async function moveToPhotoCacheAsync(uri: string): Promise {
  await ensureDirectory(directory);
  const extension = getExtension(uri);
  const cachedFileName = `${Date.now()}.${extension}`;
  const cachedFileLocation = `${directory}/${cachedFileName}`;
  await FileSystem.copyAsync({
    from: uri,
    to: cachedFileLocation,
  });
  return cachedFileLocation;
}
github expo / expo-asset-utils / src / copyAssetToSameDirectoryWithNewNameAsync.js View on Github external
async function copyAssetToSameDirectoryWithNewNameAsync(
  fileReference,
  name: string
): Promise {
  const url = await uriAsync(fileReference);
  const nextUrl = replaceNameInUri(url, name);
  await copyAsync({ from: url, to: nextUrl });
  return nextUrl;
}