@umituz/react-native-filesystem 1.2.4 → 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.4",
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",
@@ -3,7 +3,7 @@
3
3
  * Single Responsibility: Manage directory operations
4
4
  */
5
5
 
6
- import * as FileSystem from "expo-file-system/legacy";
6
+ import * as FileSystem from "expo-file-system";
7
7
  import type { DirectoryType } from "../../domain/entities/File";
8
8
 
9
9
  /**
@@ -3,7 +3,7 @@
3
3
  * Single Responsibility: Download files from URLs
4
4
  */
5
5
 
6
- import * as FileSystem from "expo-file-system/legacy";
6
+ import * as FileSystem from "expo-file-system";
7
7
  import type { FileOperationResult } from "../../domain/entities/File";
8
8
  import { getDirectoryPath } from "./directory.service";
9
9
  import { FileUtils } from "../../domain/entities/File";
@@ -3,7 +3,7 @@
3
3
  * Single Responsibility: Get file information and metadata
4
4
  */
5
5
 
6
- import * as FileSystem from "expo-file-system/legacy";
6
+ import * as FileSystem from "expo-file-system";
7
7
  import type { FileInfo } from "../../domain/entities/File";
8
8
 
9
9
  /**
@@ -3,7 +3,7 @@
3
3
  * Single Responsibility: Manage file operations (delete, copy, move)
4
4
  */
5
5
 
6
- import * as FileSystem from "expo-file-system/legacy";
6
+ import * as FileSystem from "expo-file-system";
7
7
  import type { FileOperationResult } from "../../domain/entities/File";
8
8
 
9
9
  /**
@@ -3,7 +3,7 @@
3
3
  * Single Responsibility: Read files from device storage
4
4
  */
5
5
 
6
- import * as FileSystem from "expo-file-system/legacy";
6
+ import * as FileSystem from "expo-file-system";
7
7
  import type { FileEncoding } from "../../domain/entities/File";
8
8
  import { getEncodingType } from "./encoding.service";
9
9
 
@@ -15,6 +15,23 @@ 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
37
  encoding: encodingType as FileSystem.EncodingType,
@@ -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
  */
@@ -3,7 +3,7 @@
3
3
  * Single Responsibility: Write files to device storage
4
4
  */
5
5
 
6
- import * as FileSystem from "expo-file-system/legacy";
6
+ import * as FileSystem from "expo-file-system";
7
7
  import type { FileEncoding, FileOperationResult } from "../../domain/entities/File";
8
8
  import { getEncodingType } from "./encoding.service";
9
9