@umituz/react-native-filesystem 1.2.0 → 1.2.3

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.0",
3
+ "version": "1.2.3",
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
- switch (type) {
38
- case "documentDirectory":
39
- return FileSystem.documentDirectory || "";
40
- case "cacheDirectory":
41
- return FileSystem.cacheDirectory || "";
42
- default:
43
- return "";
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,22 @@
1
+ /**
2
+ * Encoding Service
3
+ * Single Responsibility: Handle file encoding/decoding operations
4
+ */
5
+
6
+ import type { FileEncoding } from "../../domain/entities/File";
7
+
8
+ /**
9
+ * Convert FileEncoding to Expo FileSystem encoding type
10
+ * Expo v19+ uses string literals directly
11
+ */
12
+ export function getEncodingType(encoding: FileEncoding): "utf8" | "base64" {
13
+ return encoding;
14
+ }
15
+
16
+ /**
17
+ * Validate encoding type
18
+ */
19
+ export function isValidEncoding(encoding: string): encoding is FileEncoding {
20
+ return encoding === "utf8" || encoding === "base64";
21
+ }
22
+
@@ -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
- encoding === "base64"
20
- ? FileSystem.EncodingType.Base64
21
- : FileSystem.EncodingType.UTF8;
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 {