@umituz/react-native-filesystem 1.2.6 → 1.3.0
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 +3 -3
- package/src/infrastructure/services/cache.service.ts +1 -0
- package/src/infrastructure/services/directory.service.ts +8 -6
- package/src/infrastructure/services/download.service.ts +12 -9
- package/src/infrastructure/services/file-info.service.ts +12 -10
- package/src/infrastructure/services/file-manager.service.ts +30 -11
- package/src/infrastructure/services/file-reader.service.ts +7 -5
- package/src/infrastructure/services/file-writer.service.ts +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-filesystem",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"url": "git@github.com:umituz/react-native-filesystem.git"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"expo-file-system": "~
|
|
32
|
+
"expo-file-system": "~19.0.0",
|
|
33
33
|
"react": ">=18.2.0",
|
|
34
34
|
"react-native": ">=0.74.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/react": "^18.2.45",
|
|
38
38
|
"@types/react-native": "^0.73.0",
|
|
39
|
-
"expo-file-system": "~
|
|
39
|
+
"expo-file-system": "~19.0.18",
|
|
40
40
|
"react": "^18.2.0",
|
|
41
41
|
"react-native": "^0.74.0",
|
|
42
42
|
"typescript": "^5.3.3"
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Single Responsibility: Manage directory operations
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import { Directory, Paths } from "expo-file-system";
|
|
7
7
|
import type { DirectoryType } from "../../domain/entities/File";
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -11,7 +11,8 @@ import type { DirectoryType } from "../../domain/entities/File";
|
|
|
11
11
|
*/
|
|
12
12
|
export async function createDirectory(uri: string): Promise<boolean> {
|
|
13
13
|
try {
|
|
14
|
-
|
|
14
|
+
const dir = new Directory(uri);
|
|
15
|
+
dir.create({ intermediates: true, idempotent: true });
|
|
15
16
|
return true;
|
|
16
17
|
} catch (error) {
|
|
17
18
|
return false;
|
|
@@ -23,8 +24,9 @@ export async function createDirectory(uri: string): Promise<boolean> {
|
|
|
23
24
|
*/
|
|
24
25
|
export async function listDirectory(uri: string): Promise<string[]> {
|
|
25
26
|
try {
|
|
26
|
-
const
|
|
27
|
-
|
|
27
|
+
const dir = new Directory(uri);
|
|
28
|
+
const items = dir.list();
|
|
29
|
+
return items.map((item) => item.uri);
|
|
28
30
|
} catch (error) {
|
|
29
31
|
return [];
|
|
30
32
|
}
|
|
@@ -37,9 +39,9 @@ export function getDirectoryPath(type: DirectoryType): string {
|
|
|
37
39
|
try {
|
|
38
40
|
switch (type) {
|
|
39
41
|
case "documentDirectory":
|
|
40
|
-
return
|
|
42
|
+
return Paths.document.uri;
|
|
41
43
|
case "cacheDirectory":
|
|
42
|
-
return
|
|
44
|
+
return Paths.cache.uri;
|
|
43
45
|
default:
|
|
44
46
|
return "";
|
|
45
47
|
}
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* Single Responsibility: Download files from URLs
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import { File, Paths } from "expo-file-system";
|
|
7
7
|
import type { FileOperationResult } from "../../domain/entities/File";
|
|
8
|
-
import { getDirectoryPath } from "./directory.service";
|
|
9
8
|
import { FileUtils } from "../../domain/entities/File";
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -16,14 +15,18 @@ export async function downloadFile(
|
|
|
16
15
|
destinationUri?: string,
|
|
17
16
|
): Promise<FileOperationResult> {
|
|
18
17
|
try {
|
|
19
|
-
|
|
20
|
-
destinationUri ||
|
|
21
|
-
FileUtils.joinPaths(
|
|
22
|
-
getDirectoryPath("documentDirectory"),
|
|
23
|
-
FileUtils.generateUniqueFilename("download"),
|
|
24
|
-
);
|
|
18
|
+
let destination: File | typeof Paths.document;
|
|
25
19
|
|
|
26
|
-
|
|
20
|
+
if (destinationUri) {
|
|
21
|
+
destination = new File(destinationUri);
|
|
22
|
+
} else {
|
|
23
|
+
const filename = FileUtils.generateUniqueFilename("download");
|
|
24
|
+
destination = new File(Paths.document, filename);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const result = await File.downloadFileAsync(url, destination, {
|
|
28
|
+
idempotent: true,
|
|
29
|
+
});
|
|
27
30
|
return { success: true, uri: result.uri };
|
|
28
31
|
} catch (error) {
|
|
29
32
|
return {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Single Responsibility: Get file information and metadata
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import { File } from "expo-file-system";
|
|
7
7
|
import type { FileInfo } from "../../domain/entities/File";
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -11,19 +11,21 @@ import type { FileInfo } from "../../domain/entities/File";
|
|
|
11
11
|
*/
|
|
12
12
|
export async function getFileInfo(uri: string): Promise<FileInfo | null> {
|
|
13
13
|
try {
|
|
14
|
-
const
|
|
14
|
+
const file = new File(uri);
|
|
15
15
|
|
|
16
|
-
if (!
|
|
16
|
+
if (!file.exists) {
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
const info = file.info();
|
|
21
|
+
|
|
20
22
|
return {
|
|
21
23
|
uri,
|
|
22
|
-
name:
|
|
23
|
-
size:
|
|
24
|
-
exists:
|
|
25
|
-
isDirectory:
|
|
26
|
-
modificationTime:
|
|
24
|
+
name: file.name,
|
|
25
|
+
size: file.size || 0,
|
|
26
|
+
exists: file.exists,
|
|
27
|
+
isDirectory: false,
|
|
28
|
+
modificationTime: file.modificationTime || 0,
|
|
27
29
|
};
|
|
28
30
|
} catch (error) {
|
|
29
31
|
return null;
|
|
@@ -35,8 +37,8 @@ export async function getFileInfo(uri: string): Promise<FileInfo | null> {
|
|
|
35
37
|
*/
|
|
36
38
|
export async function fileExists(uri: string): Promise<boolean> {
|
|
37
39
|
try {
|
|
38
|
-
const
|
|
39
|
-
return
|
|
40
|
+
const file = new File(uri);
|
|
41
|
+
return file.exists;
|
|
40
42
|
} catch (error) {
|
|
41
43
|
return false;
|
|
42
44
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Single Responsibility: Manage file operations (delete, copy, move)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import { File, Directory } from "expo-file-system";
|
|
7
7
|
import type { FileOperationResult } from "../../domain/entities/File";
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -11,8 +11,29 @@ import type { FileOperationResult } from "../../domain/entities/File";
|
|
|
11
11
|
*/
|
|
12
12
|
export async function deleteFile(uri: string): Promise<boolean> {
|
|
13
13
|
try {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
// Try as file first
|
|
15
|
+
try {
|
|
16
|
+
const file = new File(uri);
|
|
17
|
+
if (file.exists) {
|
|
18
|
+
file.delete();
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
} catch {
|
|
22
|
+
// Not a file, try as directory
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Try as directory
|
|
26
|
+
try {
|
|
27
|
+
const dir = new Directory(uri);
|
|
28
|
+
if (dir.exists) {
|
|
29
|
+
dir.delete();
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
} catch {
|
|
33
|
+
// Not a directory either
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return false;
|
|
16
37
|
} catch (error) {
|
|
17
38
|
return false;
|
|
18
39
|
}
|
|
@@ -26,10 +47,9 @@ export async function copyFile(
|
|
|
26
47
|
destinationUri: string,
|
|
27
48
|
): Promise<FileOperationResult> {
|
|
28
49
|
try {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
50
|
+
const sourceFile = new File(sourceUri);
|
|
51
|
+
const destination = new File(destinationUri);
|
|
52
|
+
sourceFile.copy(destination);
|
|
33
53
|
return { success: true, uri: destinationUri };
|
|
34
54
|
} catch (error) {
|
|
35
55
|
return {
|
|
@@ -47,10 +67,9 @@ export async function moveFile(
|
|
|
47
67
|
destinationUri: string,
|
|
48
68
|
): Promise<FileOperationResult> {
|
|
49
69
|
try {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
70
|
+
const sourceFile = new File(sourceUri);
|
|
71
|
+
const destination = new File(destinationUri);
|
|
72
|
+
sourceFile.move(destination);
|
|
54
73
|
return { success: true, uri: destinationUri };
|
|
55
74
|
} catch (error) {
|
|
56
75
|
return {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Single Responsibility: Read files from device storage
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import { File } from "expo-file-system";
|
|
7
7
|
import type { FileEncoding } from "../../domain/entities/File";
|
|
8
8
|
import { getEncodingType } from "./encoding.service";
|
|
9
9
|
|
|
@@ -32,10 +32,12 @@ export async function readFile(
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// Use FileSystem API as fallback
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const file = new File(uri);
|
|
36
|
+
if (encoding === "base64") {
|
|
37
|
+
const content = await file.base64();
|
|
38
|
+
return content;
|
|
39
|
+
}
|
|
40
|
+
const content = await file.text();
|
|
39
41
|
return content;
|
|
40
42
|
} catch (error) {
|
|
41
43
|
return null;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Single Responsibility: Write files to device storage
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import { File } from "expo-file-system";
|
|
7
7
|
import type { FileEncoding, FileOperationResult } from "../../domain/entities/File";
|
|
8
8
|
import { getEncodingType } from "./encoding.service";
|
|
9
9
|
|
|
@@ -17,7 +17,8 @@ export async function writeFile(
|
|
|
17
17
|
): Promise<FileOperationResult> {
|
|
18
18
|
try {
|
|
19
19
|
const encodingType = getEncodingType(encoding);
|
|
20
|
-
|
|
20
|
+
const file = new File(uri);
|
|
21
|
+
file.write(content, {
|
|
21
22
|
encoding: encodingType as any,
|
|
22
23
|
});
|
|
23
24
|
return { success: true, uri };
|