DefinitelyTyped/types/react-native-background-downloader/react-native-background-downloader-tests.tsx
Junseong Park b486ac5f27
added @types/react-native-background-downloader (#42052)
* added @types/react-native-background-downloader

* remove typescript version

* modified for lint
2020-02-05 15:18:08 -08:00

29 lines
724 B
TypeScript

import RNBackgroundDownloader from 'react-native-background-downloader';
const task = RNBackgroundDownloader.download({
id: 'file123',
url: 'https://link-to-very.large/file.zip',
destination: `${RNBackgroundDownloader.directories.documents}/file.zip`,
})
.begin(expectedBytes => {
console.log(`Going to download ${expectedBytes} bytes!`);
})
.progress(percent => {
console.log(`Downloaded: ${percent * 100}%`);
})
.done(() => {
console.log('Download is done!');
})
.error(error => {
console.log('Download canceled due to error: ', error);
});
// Pause the task
task.pause();
// Resume after pause
task.resume();
// Cancel the task
task.stop();