@umituz/react-native-filesystem 1.2.3 → 1.2.5
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-filesystem",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "Domain-Driven Design filesystem utilities for React Native apps with build-time module loading and runtime file operations",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -37,19 +37,9 @@ export function getDirectoryPath(type: DirectoryType): string {
|
|
|
37
37
|
try {
|
|
38
38
|
switch (type) {
|
|
39
39
|
case "documentDirectory":
|
|
40
|
-
|
|
41
|
-
if ((FileSystem as any).Paths?.document?.uri) {
|
|
42
|
-
return (FileSystem as any).Paths.document.uri;
|
|
43
|
-
}
|
|
44
|
-
// Fallback for older versions
|
|
45
|
-
return (FileSystem as any).documentDirectory || "";
|
|
40
|
+
return FileSystem.documentDirectory || "";
|
|
46
41
|
case "cacheDirectory":
|
|
47
|
-
|
|
48
|
-
if ((FileSystem as any).Paths?.cache?.uri) {
|
|
49
|
-
return (FileSystem as any).Paths.cache.uri;
|
|
50
|
-
}
|
|
51
|
-
// Fallback for older versions
|
|
52
|
-
return (FileSystem as any).cacheDirectory || "";
|
|
42
|
+
return FileSystem.cacheDirectory || "";
|
|
53
43
|
default:
|
|
54
44
|
return "";
|
|
55
45
|
}
|
|
@@ -7,9 +7,11 @@ import type { FileEncoding } from "../../domain/entities/File";
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Convert FileEncoding to Expo FileSystem encoding type
|
|
10
|
-
*
|
|
10
|
+
* Legacy API uses EncodingType enum
|
|
11
11
|
*/
|
|
12
|
-
export function getEncodingType(encoding: FileEncoding):
|
|
12
|
+
export function getEncodingType(encoding: FileEncoding): any {
|
|
13
|
+
// Legacy API uses EncodingType enum
|
|
14
|
+
// Return as string for compatibility
|
|
13
15
|
return encoding;
|
|
14
16
|
}
|
|
15
17
|
|
|
@@ -15,9 +15,26 @@ export async function readFile(
|
|
|
15
15
|
encoding: FileEncoding = "utf8",
|
|
16
16
|
): Promise<string | null> {
|
|
17
17
|
try {
|
|
18
|
+
// For file:// URLs, try fetch first (works in React Native)
|
|
19
|
+
if (uri.startsWith("file://")) {
|
|
20
|
+
try {
|
|
21
|
+
const response = await fetch(uri);
|
|
22
|
+
if (response.ok) {
|
|
23
|
+
if (encoding === "base64") {
|
|
24
|
+
const blob = await response.blob();
|
|
25
|
+
return await blobToBase64(blob);
|
|
26
|
+
}
|
|
27
|
+
return await response.text();
|
|
28
|
+
}
|
|
29
|
+
} catch (fetchError) {
|
|
30
|
+
// Fall through to FileSystem API
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Use FileSystem API as fallback
|
|
18
35
|
const encodingType = getEncodingType(encoding);
|
|
19
36
|
const content = await FileSystem.readAsStringAsync(uri, {
|
|
20
|
-
encoding: encodingType,
|
|
37
|
+
encoding: encodingType as FileSystem.EncodingType,
|
|
21
38
|
});
|
|
22
39
|
return content;
|
|
23
40
|
} catch (error) {
|
|
@@ -25,6 +42,23 @@ export async function readFile(
|
|
|
25
42
|
}
|
|
26
43
|
}
|
|
27
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Convert blob to base64 string
|
|
47
|
+
*/
|
|
48
|
+
function blobToBase64(blob: Blob): Promise<string> {
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
const reader = new FileReader();
|
|
51
|
+
reader.onloadend = () => {
|
|
52
|
+
const result = reader.result as string;
|
|
53
|
+
// Remove data URL prefix if present
|
|
54
|
+
const base64 = result.includes(",") ? result.split(",")[1] : result;
|
|
55
|
+
resolve(base64);
|
|
56
|
+
};
|
|
57
|
+
reader.onerror = reject;
|
|
58
|
+
reader.readAsDataURL(blob);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
28
62
|
/**
|
|
29
63
|
* Read file as base64 string
|
|
30
64
|
*/
|
|
@@ -18,7 +18,7 @@ export async function writeFile(
|
|
|
18
18
|
try {
|
|
19
19
|
const encodingType = getEncodingType(encoding);
|
|
20
20
|
await FileSystem.writeAsStringAsync(uri, content, {
|
|
21
|
-
encoding: encodingType,
|
|
21
|
+
encoding: encodingType as FileSystem.EncodingType,
|
|
22
22
|
});
|
|
23
23
|
return { success: true, uri };
|
|
24
24
|
} catch (error) {
|