react-native-compressor
Version:
Compress Image, Video, and Audio same like Whatsapp & Auto/Manual Compression | Background Upload | Download File | Create Video Thumbnail
31 lines • 931 B
JavaScript
import { NativeEventEmitter, Platform } from 'react-native';
import { Compressor } from '../Main';
const CompressEventEmitter = new NativeEventEmitter(Compressor);
import { uuidv4 } from './index';
export const download = async (fileUrl, downloadProgress, progressDivider) => {
let subscription;
try {
const uuid = uuidv4();
if (downloadProgress) {
subscription = CompressEventEmitter.addListener('downloadProgress', event => {
if (event.uuid === uuid) {
downloadProgress(event.data.progress);
}
});
}
if (Platform.OS === 'android' && fileUrl.includes('file://')) {
fileUrl = fileUrl.replace('file://', '');
}
const result = await Compressor.download(fileUrl, {
uuid,
progressDivider
});
return result;
} finally {
// @ts-ignore
if (subscription) {
subscription.remove();
}
}
};
//# sourceMappingURL=Downloader.js.map