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 passes when used properly', () => {
readAsStringAsync('fileUri').then(fileInfo => {
(fileInfo: string);
// $ExpectError: check any
(fileInfo: number);
});
readAsStringAsync('fileUri', { encoding: 'base64' });
readAsStringAsync('fileUri', { position: 1 });
readAsStringAsync('fileUri', { length: 1 });
readAsStringAsync('fileUri', {
encoding: 'utf8',
position: 1,
length: 1,
});
});
if (Platform.OS === 'web') {
const loader = new THREE.FileLoader();
return new Promise((resolve, reject) =>
loader.load(
localUri,
async value => {
// @ts-ignore
resolve(await value);
},
() => {},
reject,
),
);
}
try {
return await readAsStringAsync(localUri);
} catch ({ message }) {
throw new Error(
`ExpoTHREE: FileSystem.readAsStringAsync(${localUri}) ${message}`,
);
} finally {
if (global.__expo_three_log_loading) {
console.timeEnd('loadAsset');
}
}
}
const { mediaType = 'Images' } = this.props
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions[mediaType],
// mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: mediaType === 'Images' ? true : false,
base64: true,
quality: 1,
});
if (!result.cancelled) {
const { onChangeCallback, input: { onChange } } = this.props
this.setState({ image: result.uri });
FileSystem.readAsStringAsync(result.uri, {
encoding: FileSystem.EncodingType.Base64
}).then((base64) => {
const res = { ...result, base64 }
onChangeCallback(res)
this.onToggleLoading()
})
.catch(error => {
console.error(error);
});
}
else {
this.onToggleLoading()
}
};
async peek () {
try {
const payloads = await FileSystem.readDirectoryAsync(this._path)
const payloadFileName = payloads.filter(f => filenameRe.test(f)).sort()[0]
if (!payloadFileName) return null
const id = `${this._path}/${payloadFileName}`
try {
const payloadJson = await FileSystem.readAsStringAsync(id)
const payload = JSON.parse(payloadJson)
return { id, payload }
} catch (e) {
// if we got here it's because
// a) JSON.parse failed or
// b) the file can no longer be read (maybe it was truncated?)
// in both cases we want to speculatively remove it and try peeking again
await this.remove(id)
return this.peek()
}
} catch (e) {
this._onerror(e)
return null
}
}
private loadHTMLFile = async () => {
try {
let asset: Asset = await AssetUtils.resolveAsync(INDEX_FILE_PATH);
let fileString: string = await FileSystem.readAsStringAsync(
asset.localUri
);
this.setState({ webviewContent: fileString });
} catch (error) {
console.warn(error);
console.warn("Unable to resolve index file");
}
};
const getItem = (key, callback) => withCallback(callback, async () => {
const pathKey = pathForKey(key);
const { exists } = await FileSystem.getInfoAsync(pathKey);
if (exists) {
return await FileSystem.readAsStringAsync(pathKey);
}
});
async function jsonFromResourceAsync(resource) {
const jsonUrl = await uriAsync(resource);
const jsonString = await readAsStringAsync(jsonUrl);
return JSON.parse(jsonString);
}
_copyAndReadAsset = async () => {
const asset = Asset.fromModule(require('../../assets/index.html'));
await asset.downloadAsync();
const tmpFile = FileSystem.cacheDirectory + 'test.html';
try {
await FileSystem.copyAsync({ from: asset.localUri!, to: tmpFile });
const result = await FileSystem.readAsStringAsync(tmpFile);
Alert.alert('Result', result);
} catch (e) {
Alert.alert('Error', e.message);
}
}
withCallback(callback, async () => {
const pathKey = pathForKey(key);
const { exists } = await FileSystem.getInfoAsync(pathKey);
if (exists) {
return await FileSystem.readAsStringAsync(pathKey);
}
});