@umituz/react-native-filesystem 2.1.20 → 2.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@ import { downloadFile } from "./download.service";
|
|
|
11
11
|
import { clearCache, getDirectorySize } from "./cache.service";
|
|
12
12
|
import { generateFilePath } from "./file-path.service";
|
|
13
13
|
import { FileUtils } from "../../domain/entities/File";
|
|
14
|
-
import type {
|
|
14
|
+
import type { FileOperationResult } from "../../domain/entities/File";
|
|
15
15
|
|
|
16
16
|
export class FileSystemService {
|
|
17
17
|
static readFile = readFile;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { File, Paths, Directory } from "expo-file-system";
|
|
6
6
|
import type { FileOperationResult } from "../../domain/entities/File";
|
|
7
7
|
import { FileUtils } from "../../domain/entities/File";
|
|
8
|
+
import { SUPPORTED_DOWNLOAD_EXTENSIONS, DEFAULT_DOWNLOAD_EXTENSION } from "./download.constants";
|
|
8
9
|
import type { DownloadProgressCallback, DownloadWithProgressResult } from "./download.types";
|
|
9
10
|
|
|
10
11
|
const hashUrl = (url: string) => {
|
|
@@ -14,8 +15,9 @@ const hashUrl = (url: string) => {
|
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
const getExt = (url: string) => {
|
|
17
|
-
const
|
|
18
|
-
|
|
18
|
+
const parts = url.split("?")[0]?.split(".") || [];
|
|
19
|
+
const ext = parts.length > 1 ? parts.pop()?.toLowerCase() || DEFAULT_DOWNLOAD_EXTENSION : DEFAULT_DOWNLOAD_EXTENSION;
|
|
20
|
+
return (SUPPORTED_DOWNLOAD_EXTENSIONS as readonly string[]).includes(ext) ? ext : DEFAULT_DOWNLOAD_EXTENSION;
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
const getCacheUri = (url: string, dir: string) => FileUtils.joinPaths(dir, `cached_${hashUrl(url)}.${getExt(url)}`);
|
|
@@ -11,8 +11,7 @@ export function blobToBase64(blob: Blob): Promise<string> {
|
|
|
11
11
|
const reader = new FileReader();
|
|
12
12
|
reader.onloadend = () => {
|
|
13
13
|
const result = reader.result as string;
|
|
14
|
-
|
|
15
|
-
const base64 = result.includes(",") ? result.split(",")[1] : result;
|
|
14
|
+
const base64 = result.includes(",") ? result.split(",")[1] ?? result : result;
|
|
16
15
|
resolve(base64);
|
|
17
16
|
};
|
|
18
17
|
reader.onerror = reject;
|