@umituz/react-native-filesystem 1.2.0 → 1.2.2
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.2",
|
|
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",
|
|
@@ -34,13 +34,27 @@ export async function listDirectory(uri: string): Promise<string[]> {
|
|
|
34
34
|
* Get directory path by type
|
|
35
35
|
*/
|
|
36
36
|
export function getDirectoryPath(type: DirectoryType): string {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
try {
|
|
38
|
+
switch (type) {
|
|
39
|
+
case "documentDirectory":
|
|
40
|
+
// Try Expo v19+ API first
|
|
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 || "";
|
|
46
|
+
case "cacheDirectory":
|
|
47
|
+
// Try Expo v19+ API first
|
|
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 || "";
|
|
53
|
+
default:
|
|
54
|
+
return "";
|
|
55
|
+
}
|
|
56
|
+
} catch (error) {
|
|
57
|
+
return "";
|
|
44
58
|
}
|
|
45
59
|
}
|
|
46
60
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encoding Service
|
|
3
|
+
* Single Responsibility: Handle file encoding/decoding operations
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as FileSystem from "expo-file-system";
|
|
7
|
+
import type { FileEncoding } from "../../domain/entities/File";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Convert FileEncoding to Expo FileSystem encoding type
|
|
11
|
+
*/
|
|
12
|
+
export function getEncodingType(encoding: FileEncoding): any {
|
|
13
|
+
// Expo v19+ uses different encoding format
|
|
14
|
+
if (encoding === "base64") {
|
|
15
|
+
return FileSystem.EncodingType?.Base64 ?? "base64";
|
|
16
|
+
}
|
|
17
|
+
return FileSystem.EncodingType?.UTF8 ?? "utf8";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Validate encoding type
|
|
22
|
+
*/
|
|
23
|
+
export function isValidEncoding(encoding: string): encoding is FileEncoding {
|
|
24
|
+
return encoding === "utf8" || encoding === "base64";
|
|
25
|
+
}
|
|
26
|
+
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import * as FileSystem from "expo-file-system";
|
|
7
7
|
import type { FileEncoding } from "../../domain/entities/File";
|
|
8
|
+
import { getEncodingType } from "./encoding.service";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Read file as string with encoding
|
|
@@ -14,11 +15,7 @@ export async function readFile(
|
|
|
14
15
|
encoding: FileEncoding = "utf8",
|
|
15
16
|
): Promise<string | null> {
|
|
16
17
|
try {
|
|
17
|
-
const encodingType =
|
|
18
|
-
encoding === "base64"
|
|
19
|
-
? FileSystem.EncodingType.Base64
|
|
20
|
-
: FileSystem.EncodingType.UTF8;
|
|
21
|
-
|
|
18
|
+
const encodingType = getEncodingType(encoding);
|
|
22
19
|
const content = await FileSystem.readAsStringAsync(uri, {
|
|
23
20
|
encoding: encodingType,
|
|
24
21
|
});
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import * as FileSystem from "expo-file-system";
|
|
7
7
|
import type { FileEncoding, FileOperationResult } from "../../domain/entities/File";
|
|
8
|
+
import { getEncodingType } from "./encoding.service";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Write string to file
|
|
@@ -15,12 +16,10 @@ export async function writeFile(
|
|
|
15
16
|
encoding: FileEncoding = "utf8",
|
|
16
17
|
): Promise<FileOperationResult> {
|
|
17
18
|
try {
|
|
18
|
-
const encodingType =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
await FileSystem.writeAsStringAsync(uri, content, { encoding: encodingType });
|
|
19
|
+
const encodingType = getEncodingType(encoding);
|
|
20
|
+
await FileSystem.writeAsStringAsync(uri, content, {
|
|
21
|
+
encoding: encodingType,
|
|
22
|
+
});
|
|
24
23
|
return { success: true, uri };
|
|
25
24
|
} catch (error) {
|
|
26
25
|
return {
|