|
@@ -4,7 +4,11 @@ import { unzip } from 'react-native-zip-archive';
|
|
export const downloadToFile = async (
|
|
export const downloadToFile = async (
|
|
fileUrl: string,
|
|
fileUrl: string,
|
|
fileName: string,
|
|
fileName: string,
|
|
- listener?: (bytesWritten: number, contentLength: number) => void,
|
|
|
|
|
|
+ listener?: (
|
|
|
|
+ bytesWritten: number,
|
|
|
|
+ contentLength: number,
|
|
|
|
+ progress: string,
|
|
|
|
+ ) => void,
|
|
) => {
|
|
) => {
|
|
// /storage/emulated/0/Android/data/com.trust.ywx/files/bundles/android/common.android.bundle
|
|
// /storage/emulated/0/Android/data/com.trust.ywx/files/bundles/android/common.android.bundle
|
|
const downloadDest = `${RNFS.ExternalDirectoryPath}/bundles/${fileName}`;
|
|
const downloadDest = `${RNFS.ExternalDirectoryPath}/bundles/${fileName}`;
|
|
@@ -18,7 +22,12 @@ export const downloadToFile = async (
|
|
fromUrl: fileUrl,
|
|
fromUrl: fileUrl,
|
|
toFile: downloadDest,
|
|
toFile: downloadDest,
|
|
progress: (res: any) => {
|
|
progress: (res: any) => {
|
|
- listener && listener(res.bytesWritten, res.contentLength);
|
|
|
|
|
|
+ listener &&
|
|
|
|
+ listener(
|
|
|
|
+ res.bytesWritten,
|
|
|
|
+ res.contentLength,
|
|
|
|
+ `进度: ${((res.bytesWritten / res.contentLength) * 100).toFixed(2)}%`,
|
|
|
|
+ );
|
|
console.log(
|
|
console.log(
|
|
`进度: ${((res.bytesWritten / res.contentLength) * 100).toFixed(2)}%`,
|
|
`进度: ${((res.bytesWritten / res.contentLength) * 100).toFixed(2)}%`,
|
|
);
|
|
);
|