Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should raises an error when pass invalid arguments', () => {
// $ExpectError: first argument is required
downloadAsync();
// $ExpectError: first argument must be a string
downloadAsync(69);
// $ExpectError: second argument must be a string
downloadAsync('', 69);
// $ExpectError: third argument must be an object
downloadAsync('', '', 69);
// $ExpectError: 'abc' is missing in options
downloadAsync('', '', { abc: 'test' });
downloadAsync('', '', {
// $ExpectError: invalid value
md5: 'need boolean',
});
});
});
it('should passes when used properly', () => {
downloadAsync('url', 'fileUri').then(result => {
(result.uri: string);
(result.status: number);
(result.headers: { [string]: string });
(result.md5: ?string);
// $ExpectError: check any
(result.uri: number);
});
downloadAsync('url', 'fileUri', { md5: false });
downloadAsync('url', 'fileUri', { cache: false });
downloadAsync('url', 'fileUri', { headers: { 'header-name': 'abc' } });
downloadAsync('url', 'fileUri', {
md5: false,
cache: false,
headers: { 'X-Auth': 'abc' },
});
});
it('should raises an error when pass invalid arguments', () => {
// $ExpectError: first argument is required
downloadAsync();
// $ExpectError: first argument must be a string
downloadAsync(69);
// $ExpectError: second argument must be a string
downloadAsync('', 69);
// $ExpectError: third argument must be an object
downloadAsync('', '', 69);
// $ExpectError: 'abc' is missing in options
downloadAsync('', '', { abc: 'test' });
downloadAsync('', '', {
// $ExpectError: invalid value
md5: 'need boolean',
});
});
});
it('should passes when used properly', () => {
downloadAsync('url', 'fileUri').then(result => {
(result.uri: string);
(result.status: number);
(result.headers: { [string]: string });
(result.md5: ?string);
// $ExpectError: check any
(result.uri: number);
});
downloadAsync('url', 'fileUri', { md5: false });
downloadAsync('url', 'fileUri', { cache: false });
downloadAsync('url', 'fileUri', { headers: { 'header-name': 'abc' } });
downloadAsync('url', 'fileUri', {
md5: false,
cache: false,
headers: { 'X-Auth': 'abc' },
it('should raises an error when pass invalid arguments', () => {
// $ExpectError: first argument is required
downloadAsync();
// $ExpectError: first argument must be a string
downloadAsync(69);
// $ExpectError: second argument must be a string
downloadAsync('', 69);
// $ExpectError: third argument must be an object
downloadAsync('', '', 69);
// $ExpectError: 'abc' is missing in options
downloadAsync('', '', { abc: 'test' });
downloadAsync('', '', {
// $ExpectError: invalid value
md5: 'need boolean',
});
});
});
async _downloadAsyncUnmanagedEnv(): Promise {
// Bail out if it's already at a file URL because it's already available locally
if (this.uri.startsWith('file://')) {
this.localUri = this.uri;
return;
}
const localUri = `${FileSystem.cacheDirectory}ExponentAsset-${this.hash}.${this.type}`;
// We don't check the FileSystem for an existing version of the asset and we
// also don't perform an integrity check!
await FileSystem.downloadAsync(this.uri, localUri);
this.localUri = localUri;
}
} 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;
}
}
return file;
} else {
/// remote image: download first
const { uri, md5: hash } = await FileSystem.downloadAsync(url, localUri, {
md5: true,
});
return { uri, name, hash };
}
}
export default fileInfoAsync;
Image.getSize(uri, async (width2, height2) => {
let cropObj;
({ cropObj, imgWidth, imgHeight } = this.getCropBounds(imgWidth, width2, imgHeight, height2))
if (cropObj.height > 0 && cropObj.width > 0) {
let uriToCrop = uri
if (this.isRemote) {
const response = await FileSystem.downloadAsync(
uri,
FileSystem.documentDirectory + 'image',
)
uriToCrop = response.uri
}
const { uri: uriCroped, base64 } = await this.crop(cropObj, uriToCrop)
this.setState({
uri: uriCroped, base64, cropMode: false, processing: false,
})
}
})
}
async _downloadAsyncManagedEnv() {
const localUri = `${FileSystem.cacheDirectory}ExponentAsset-${this.hash}.${this.type}`;
let { exists, md5 } = await FileSystem.getInfoAsync(localUri, {
md5: true,
});
if (!exists || md5 !== this.hash) {
({ md5 } = await FileSystem.downloadAsync(this.uri, localUri, {
md5: true,
}));
if (md5 !== this.hash) {
throw new Error(`Downloaded file for asset '${this.name}.${this.type}' ` +
`Located at ${this.uri} ` +
`failed MD5 integrity check`);
}
}
this.localUri = localUri;
}
async _downloadAsyncUnmanagedEnv() {