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
getInfoAsync();
// $ExpectError: first argument must be a string
getInfoAsync(69);
// $ExpectError: second argument must be an object
getInfoAsync('', 69);
// $ExpectError: 'abc' is missing in options
getInfoAsync('', { abc: 'test' });
getInfoAsync('', {
// $ExpectError
md5: 'need number',
});
});
});
it('should raises an error when pass invalid arguments', () => {
// $ExpectError: first argument is required
getInfoAsync();
// $ExpectError: first argument must be a string
getInfoAsync(69);
// $ExpectError: second argument must be an object
getInfoAsync('', 69);
// $ExpectError: 'abc' is missing in options
getInfoAsync('', { abc: 'test' });
getInfoAsync('', {
// $ExpectError
md5: 'need number',
});
});
});
const getCacheEntry = async (uri: string): Promise<{ exists: boolean; path: string; tmpPath: string }> => {
const filename = uri.substring(uri.lastIndexOf("/"), uri.indexOf("?") === -1 ? uri.length : uri.indexOf("?"));
const ext = filename.indexOf(".") === -1 ? ".jpg" : filename.substring(filename.lastIndexOf("."));
const path = `${BASE_DIR}${SHA1(uri)}${ext}`;
const tmpPath = `${BASE_DIR}${SHA1(uri)}-${_.uniqueId()}${ext}`;
// TODO: maybe we don't have to do this every time
try {
await FileSystem.makeDirectoryAsync(BASE_DIR);
} catch (e) {
// do nothing
}
const info = await FileSystem.getInfoAsync(path);
const { exists } = info;
return { exists, path, tmpPath };
};
_getInfo = async () => {
if (!this.download) {
alert('Initiate a download first!');
return;
}
try {
const info = await FileSystem.getInfoAsync(this.download._fileUri);
Alert.alert('File Info:', JSON.stringify(info), [{ text: 'OK', onPress: () => {} }]);
} catch (e) {
console.log(e);
}
}
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 {
async function getHashAsync(uri: string): Promise {
const { md5 } = await FileSystem.getInfoAsync(uri, { md5: true });
return md5;
}
withCallback(callback, async () => {
const pathKey = pathForKey(key);
const { exists } = await FileSystem.getInfoAsync(pathKey);
if (exists) {
return await FileSystem.readAsStringAsync(pathKey);
}
});
withCallback(callback, async () => {
const { exists } = await FileSystem.getInfoAsync(baseFolder);
if (exists == false) {
await FileSystem.makeDirectoryAsync(baseFolder, {
intermediates: true,
});
}
await FileSystem.writeAsStringAsync(pathForKey(key), value);
});
static async getCacheSize(): Promise {
const { size } = await FileSystem.getInfoAsync(BASE_DIR, { size: true });
return size;
}
}