Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_shareLocalImage = async () => {
const asset = Asset.fromModule(image);
await asset.downloadAsync();
const tmpFile = FileSystem.cacheDirectory + 'chapeau.png';
try {
// sharing only works with `file://` urls on Android so we need to copy it out of assets
await FileSystem.copyAsync({ from: asset.localUri!, to: tmpFile });
await Sharing.shareAsync(tmpFile, {
dialogTitle: 'Is it a snake or a hat?',
});
} catch (e) {
console.error(e);
}
}
/* @flow */
import * as FileSystem from 'expo-file-system';
export const DocumentDir = FileSystem.documentDirectory;
export const CacheDir = FileSystem.cacheDirectory;
const resolvePath = (...paths: Array) =>
paths
.join('/')
.split('/')
.filter(part => part && part !== '.')
.join('/');
// Wrap function to support both Promise and callback
async function withCallback(
callback?: ?(error: ?Error, result: R | void) => void,
func: () => Promise,
): Promise {
try {
const result = await func();
if (callback) {
import * as FileSystem from 'expo-file-system';
export const DocumentDir = FileSystem.documentDirectory;
export const CacheDir = FileSystem.cacheDirectory;
const resolvePath = (...paths) => paths.join('/').split('/').filter(part => part && part !== '.').join('/');
// Wrap function to support both Promise and callback
async function withCallback(callback, func) {
try {
const result = await func();
if (callback) {
callback(null, result);
}
return result;
} catch (err) {
if (callback) {
callback(err);
} else {
throw err;
// @flow
import * as _ from "lodash";
import * as FileSystem from "expo-file-system";
import SHA1 from "crypto-js/sha1";
export interface DownloadOptions {
md5?: boolean;
headers?: { [name: string]: string };
}
const BASE_DIR = `${FileSystem.cacheDirectory}expo-image-cache/`;
export class CacheEntry {
uri: string;
options: DownloadOptions;
path: string;
constructor(uri: string, options: DownloadOptions) {
this.uri = uri;
this.options = options;
}
async getPath(): Promise {
const { uri, options } = this;
const { path, exists, tmpPath } = await getCacheEntry(uri);
async _downloadAsyncUnmanagedEnv() {
// Bail out if it was bundled with the app
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;
}
async downloadAsync() {
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(
const FileSystem = require('expo-file-system')
const MAX_ITEMS = 64
const PAYLOAD_PATH = `${FileSystem.cacheDirectory}bugsnag`
const filenameRe = /^bugsnag-.*\.json$/
/*
* This class resembles FIFO queue in which to store undelivered payloads.
*/
module.exports = class UndeliveredPayloadQueue {
constructor (resource, onerror = () => {}) {
this._resource = resource
this._path = `${PAYLOAD_PATH}/${this._resource}`
this._onerror = onerror
this._truncating = false
this._initCall = null
}
/*
* Calls _init(), ensuring it only does that task once returning
async _downloadAsyncManagedEnv(): Promise {
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`
);
}
}
import { ReactNativeFile } from 'apollo-upload-client';
import * as mime from 'react-native-mime-types';
import url from 'url';
import PropTypes from 'prop-types';
import { View, Platform } from 'react-native';
import settings from '@gqlapp/config';
import ModalNotify from '../components/ModalNotify';
const { protocol, port, hostname } = url.parse(__API_URL__);
const serverUrl = `${protocol}//${
hostname === 'localhost' ? url.parse(Constants.manifest.bundleUrl).hostname : hostname
}${port ? ':' + port : ''}`;
const imageDir = FileSystem.cacheDirectory + 'ImagePicker/';
export default Component => {
return class MessageImage extends React.Component {
static propTypes = {
messages: PropTypes.object,
t: PropTypes.func
};
state = {
edges: [],
endCursor: 0,
allowImages: settings.chat.allowImages,
notify: null
};
static getDerivedStateFromProps({ messages }, { allowImages, edges: stateEdges, endCursor }) {
_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);
}
}