Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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
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;
}