@symbiote-native/file-system 0.1.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/LICENSE +21 -0
- package/README.md +262 -0
- package/build/angular/index.d.ts +1 -0
- package/build/angular/index.js +1 -0
- package/build/core/file-system.d.ts +169 -0
- package/build/core/file-system.js +404 -0
- package/build/core/index.d.ts +2 -0
- package/build/core/index.js +2 -0
- package/build/core/native-module.d.ts +32 -0
- package/build/core/native-module.js +2 -0
- package/build/core/types.d.ts +104 -0
- package/build/core/types.js +15 -0
- package/build/next/directory.d.ts +36 -0
- package/build/next/directory.js +59 -0
- package/build/next/file.d.ts +71 -0
- package/build/next/file.js +207 -0
- package/build/next/index.d.ts +5 -0
- package/build/next/index.js +5 -0
- package/build/next/native-module.d.ts +109 -0
- package/build/next/native-module.js +2 -0
- package/build/next/network-tasks.d.ts +118 -0
- package/build/next/network-tasks.js +333 -0
- package/build/next/node-path.d.ts +16 -0
- package/build/next/node-path.js +353 -0
- package/build/next/path-utilities.d.ts +42 -0
- package/build/next/path-utilities.js +110 -0
- package/build/next/paths.d.ts +22 -0
- package/build/next/paths.js +43 -0
- package/build/next/streams.d.ts +25 -0
- package/build/next/streams.js +55 -0
- package/build/next/types.d.ts +152 -0
- package/build/next/types.js +19 -0
- package/build/next/url-utilities.d.ts +3 -0
- package/build/next/url-utilities.js +62 -0
- package/build/next/watcher.d.ts +19 -0
- package/build/next/watcher.js +64 -0
- package/build-ngc/angular/index.d.ts +1 -0
- package/build-ngc/angular/index.js +2 -0
- package/build-ngc/angular/index.js.map +1 -0
- package/build-ngc/next/directory.d.ts +36 -0
- package/build-ngc/next/directory.js +60 -0
- package/build-ngc/next/directory.js.map +1 -0
- package/build-ngc/next/file.d.ts +71 -0
- package/build-ngc/next/file.js +208 -0
- package/build-ngc/next/file.js.map +1 -0
- package/build-ngc/next/index.d.ts +5 -0
- package/build-ngc/next/index.js +6 -0
- package/build-ngc/next/index.js.map +1 -0
- package/build-ngc/next/native-module.d.ts +109 -0
- package/build-ngc/next/native-module.js +3 -0
- package/build-ngc/next/native-module.js.map +1 -0
- package/build-ngc/next/network-tasks.d.ts +118 -0
- package/build-ngc/next/network-tasks.js +334 -0
- package/build-ngc/next/network-tasks.js.map +1 -0
- package/build-ngc/next/node-path.d.ts +16 -0
- package/build-ngc/next/node-path.js +354 -0
- package/build-ngc/next/node-path.js.map +1 -0
- package/build-ngc/next/path-utilities.d.ts +42 -0
- package/build-ngc/next/path-utilities.js +111 -0
- package/build-ngc/next/path-utilities.js.map +1 -0
- package/build-ngc/next/paths.d.ts +22 -0
- package/build-ngc/next/paths.js +44 -0
- package/build-ngc/next/paths.js.map +1 -0
- package/build-ngc/next/streams.d.ts +25 -0
- package/build-ngc/next/streams.js +56 -0
- package/build-ngc/next/streams.js.map +1 -0
- package/build-ngc/next/types.d.ts +152 -0
- package/build-ngc/next/types.js +20 -0
- package/build-ngc/next/types.js.map +1 -0
- package/build-ngc/next/url-utilities.d.ts +3 -0
- package/build-ngc/next/url-utilities.js +63 -0
- package/build-ngc/next/url-utilities.js.map +1 -0
- package/build-ngc/next/watcher.d.ts +19 -0
- package/build-ngc/next/watcher.js +65 -0
- package/build-ngc/next/watcher.js.map +1 -0
- package/native-link.json +17 -0
- package/package.json +154 -0
- package/src/angular/index.ts +1 -0
- package/src/core/file-system.ts +634 -0
- package/src/core/index.ts +2 -0
- package/src/core/native-module.ts +99 -0
- package/src/core/types.ts +135 -0
- package/src/next/directory.ts +83 -0
- package/src/next/file.ts +318 -0
- package/src/next/index.ts +5 -0
- package/src/next/native-module.ts +188 -0
- package/src/next/network-tasks.ts +456 -0
- package/src/next/node-path.ts +362 -0
- package/src/next/path-utilities.ts +144 -0
- package/src/next/paths.ts +52 -0
- package/src/next/streams-ambient.d.ts +34 -0
- package/src/next/streams.ts +81 -0
- package/src/next/types.ts +194 -0
- package/src/next/url-utilities.ts +70 -0
- package/src/next/watcher.ts +106 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { File } from './file';
|
|
2
|
+
import { expoFileSystemNext } from './native-module';
|
|
3
|
+
import { Paths } from './paths';
|
|
4
|
+
import { FileSystemWatcher } from './watcher';
|
|
5
|
+
/**
|
|
6
|
+
* Represents a directory on the filesystem.
|
|
7
|
+
*
|
|
8
|
+
* A `Directory` instance can be created for any path, and does not need to exist on the
|
|
9
|
+
* filesystem during creation.
|
|
10
|
+
*/
|
|
11
|
+
export class Directory extends expoFileSystemNext.FileSystemDirectory {
|
|
12
|
+
static pickDirectoryAsync;
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of a directory. It can be created for any path, and does not need to
|
|
15
|
+
* exist on the filesystem during creation.
|
|
16
|
+
*/
|
|
17
|
+
constructor(...uris) {
|
|
18
|
+
super(Paths.join(...uris));
|
|
19
|
+
this.validatePath();
|
|
20
|
+
}
|
|
21
|
+
/** Directory containing this directory. */
|
|
22
|
+
get parentDirectory() {
|
|
23
|
+
return new Directory(Paths.join(this.uri, '..'));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Lists the contents of a directory. Calling this method if the parent directory does not
|
|
27
|
+
* exist will throw an error.
|
|
28
|
+
*/
|
|
29
|
+
list() {
|
|
30
|
+
return super
|
|
31
|
+
.listAsRecords()
|
|
32
|
+
.map(({ isDirectory, uri }) => isDirectory ? new Directory(uri) : new File(uri));
|
|
33
|
+
}
|
|
34
|
+
/** Directory name. */
|
|
35
|
+
get name() {
|
|
36
|
+
return Paths.basename(this.uri);
|
|
37
|
+
}
|
|
38
|
+
createFile(name, mimeType) {
|
|
39
|
+
return new File(super.createFile(name, mimeType).uri);
|
|
40
|
+
}
|
|
41
|
+
createDirectory(name) {
|
|
42
|
+
return new Directory(super.createDirectory(name).uri);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Watches this directory for changes to its contents or the directory itself. On iOS,
|
|
46
|
+
* child changes are surfaced as a coarse-grained `modified` event on the directory itself, so
|
|
47
|
+
* filtering for child-level `created`, `deleted`, or `renamed` events is not reliable. The
|
|
48
|
+
* watcher automatically stops when the directory is deleted or renamed. To stop watching
|
|
49
|
+
* manually, call `remove()` on the returned subscription.
|
|
50
|
+
*/
|
|
51
|
+
watch(callback, options) {
|
|
52
|
+
return new FileSystemWatcher(this.uri, callback, options, (uri, isDirectory) => (isDirectory ? new Directory(uri) : new File(uri)));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
Directory.pickDirectoryAsync = async function (initialUri) {
|
|
56
|
+
const directory = (await expoFileSystemNext.pickDirectoryAsync(initialUri))
|
|
57
|
+
.uri;
|
|
58
|
+
return new Directory(directory);
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=directory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory.js","sourceRoot":"","sources":["../../src/next/directory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAO9C;;;;;GAKG;AACH,MAAM,OAAO,SAAU,SAAQ,kBAAkB,CAAC,mBAAmB;IACnE,MAAM,CAAC,kBAAkB,CAA8C;IAEvE;;;OAGG;IACH,YAAY,GAAG,IAAmC;QAChD,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QAC3B,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAED,2CAA2C;IAC3C,IAAI,eAAe;QACjB,OAAO,IAAI,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;IACnD,CAAC;IAED;;;OAGG;IACM,IAAI;QACX,OAAO,KAAK;aACT,aAAa,EAAE;aACf,GAAG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ask } from './network-tasks';
|
|
4
|
+
import { type IFileSystemDownloadOptions, type IFileSystemDownloadTaskOptions, type IFileSystemUploadOptions, type IFileSystemUploadResult, type IFileSystemWatchEvent, type IFileSystemWatchOptions, type IFileSystemWatchSubscription, type IPickMultipleFilesOptions, type IPickMultipleFilesResult, type IPickSingleFileOptions, type IPickSingleFileResult } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Represents a file on the filesystem.
|
|
7
|
+
*
|
|
8
|
+
* A `File` instance can be created for any path, and does not need to exist on the filesystem
|
|
9
|
+
* during creation. The constructor accepts an array of strings that are joined to create the
|
|
10
|
+
* file URI. The first argument can also be a `Directory` instance (like `Paths.cache`) or a
|
|
11
|
+
* `File` instance (which creates a new reference to the same file).
|
|
12
|
+
*/
|
|
13
|
+
export declare class File extends expoFileSystemNext.FileSystemFile {
|
|
14
|
+
/**
|
|
15
|
+
* Downloads a file from the network.
|
|
16
|
+
*
|
|
17
|
+
* On Android, the response body streams directly into the target file. If the download fails
|
|
18
|
+
* after it starts, a partially written file may remain at the destination. On iOS, the
|
|
19
|
+
* download first completes in a temporary location and the file is moved into place only
|
|
20
|
+
* after success, so no file is left behind when the request fails.
|
|
21
|
+
*/
|
|
22
|
+
static downloadFileAsync: (url: string, destination: Directory | File, options?: IFileSystemDownloadOptions) => Promise<File>;
|
|
23
|
+
/**
|
|
24
|
+
* Opens the system file picker for selecting a single file.
|
|
25
|
+
*/
|
|
26
|
+
static pickFileAsync(options?: IPickSingleFileOptions): Promise<IPickSingleFileResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Opens the system file picker for selecting multiple files.
|
|
29
|
+
*/
|
|
30
|
+
static pickFileAsync(options?: IPickMultipleFilesOptions): Promise<IPickMultipleFilesResult>;
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Use `pickFileAsync({initialUri, mimeTypes: mimeType})` instead.
|
|
33
|
+
*/
|
|
34
|
+
static pickFileAsync(initialUri?: string, mimeType?: string): Promise<File | File[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Creates an instance of a file. It can be created for any path, and does not need to exist on
|
|
37
|
+
* the filesystem during creation.
|
|
38
|
+
*/
|
|
39
|
+
constructor(...uris: (string | File | Directory)[]);
|
|
40
|
+
/** Directory containing the file. */
|
|
41
|
+
get parentDirectory(): Directory;
|
|
42
|
+
/** File extension, e.g. `.png`. */
|
|
43
|
+
get extension(): string;
|
|
44
|
+
/** File name. Includes the extension. */
|
|
45
|
+
get name(): string;
|
|
46
|
+
readableStream(): ReadableStream<unknown>;
|
|
47
|
+
writableStream(): WritableStream<Uint8Array<ArrayBufferLike>>;
|
|
48
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
49
|
+
json(): Promise<unknown>;
|
|
50
|
+
formData(): ReturnType<Response['formData']>;
|
|
51
|
+
stream(): ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
52
|
+
slice(start?: number, end?: number, contentType?: string): Blob;
|
|
53
|
+
/**
|
|
54
|
+
* Uploads this file to a server and starts the request immediately.
|
|
55
|
+
*/
|
|
56
|
+
upload(url: string, options?: IFileSystemUploadOptions): Promise<IFileSystemUploadResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Creates an upload task for this file without starting it.
|
|
59
|
+
*/
|
|
60
|
+
createUploadTask(url: string, options?: IFileSystemUploadOptions): UploadTask;
|
|
61
|
+
/**
|
|
62
|
+
* Creates a download task without starting it.
|
|
63
|
+
*/
|
|
64
|
+
static createDownloadTask(url: string, destination: File | Directory, options?: IFileSystemDownloadTaskOptions): DownloadTask;
|
|
65
|
+
/**
|
|
66
|
+
* Watches this file for changes on the filesystem. The watcher automatically stops when the
|
|
67
|
+
* file is deleted or renamed. To stop watching manually, call `remove()` on the returned
|
|
68
|
+
* subscription.
|
|
69
|
+
*/
|
|
70
|
+
watch(callback: (event: IFileSystemWatchEvent<File>) => void, options?: IFileSystemWatchOptions): IFileSystemWatchSubscription;
|
|
71
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { uuid } from 'expo-modules-core';
|
|
2
|
+
import { Directory } from './directory';
|
|
3
|
+
import { expoFileSystemNext } from './native-module';
|
|
4
|
+
import { DownloadTask, UploadTask } from './network-tasks';
|
|
5
|
+
import { Paths } from './paths';
|
|
6
|
+
import { FileSystemReadableStreamSource, FileSystemWritableSink, } from './streams';
|
|
7
|
+
import { FileSystemWatcher } from './watcher';
|
|
8
|
+
import { FileMode, } from './types';
|
|
9
|
+
function createAbortError(reason) {
|
|
10
|
+
const message = typeof reason === 'string' ? reason : 'The operation was aborted.';
|
|
11
|
+
const error = new Error(message);
|
|
12
|
+
error.name = 'AbortError';
|
|
13
|
+
return error;
|
|
14
|
+
}
|
|
15
|
+
function parsePickFileOptions(initialUriOrOptions, mimeType) {
|
|
16
|
+
if (typeof initialUriOrOptions === 'object') {
|
|
17
|
+
return { options: initialUriOrOptions, usingOldAPI: false };
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
options: {
|
|
21
|
+
initialUri: initialUriOrOptions,
|
|
22
|
+
mimeTypes: mimeType,
|
|
23
|
+
multipleFiles: false,
|
|
24
|
+
},
|
|
25
|
+
usingOldAPI: mimeType !== undefined || typeof initialUriOrOptions === 'string',
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Represents a file on the filesystem.
|
|
30
|
+
*
|
|
31
|
+
* A `File` instance can be created for any path, and does not need to exist on the filesystem
|
|
32
|
+
* during creation. The constructor accepts an array of strings that are joined to create the
|
|
33
|
+
* file URI. The first argument can also be a `Directory` instance (like `Paths.cache`) or a
|
|
34
|
+
* `File` instance (which creates a new reference to the same file).
|
|
35
|
+
*/
|
|
36
|
+
export class File extends expoFileSystemNext.FileSystemFile {
|
|
37
|
+
/**
|
|
38
|
+
* Downloads a file from the network.
|
|
39
|
+
*
|
|
40
|
+
* On Android, the response body streams directly into the target file. If the download fails
|
|
41
|
+
* after it starts, a partially written file may remain at the destination. On iOS, the
|
|
42
|
+
* download first completes in a temporary location and the file is moved into place only
|
|
43
|
+
* after success, so no file is left behind when the request fails.
|
|
44
|
+
*/
|
|
45
|
+
static downloadFileAsync;
|
|
46
|
+
static async pickFileAsync(initialUriOrOptions, mimeType) {
|
|
47
|
+
const { options, usingOldAPI } = parsePickFileOptions(initialUriOrOptions, mimeType);
|
|
48
|
+
try {
|
|
49
|
+
if (options.multipleFiles) {
|
|
50
|
+
const files = await expoFileSystemNext.pickFileAsync(options);
|
|
51
|
+
return {
|
|
52
|
+
result: files.map(file => new File(file.uri)),
|
|
53
|
+
canceled: false,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const file = await expoFileSystemNext.pickFileAsync(options);
|
|
57
|
+
if (usingOldAPI) {
|
|
58
|
+
return new File(file.uri);
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
result: new File(file.uri),
|
|
62
|
+
canceled: false,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (usingOldAPI) {
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
result: null,
|
|
71
|
+
canceled: true,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Creates an instance of a file. It can be created for any path, and does not need to exist on
|
|
77
|
+
* the filesystem during creation.
|
|
78
|
+
*/
|
|
79
|
+
constructor(...uris) {
|
|
80
|
+
super(Paths.join(...uris));
|
|
81
|
+
this.validatePath();
|
|
82
|
+
}
|
|
83
|
+
/** Directory containing the file. */
|
|
84
|
+
get parentDirectory() {
|
|
85
|
+
return new Directory(Paths.dirname(this.uri));
|
|
86
|
+
}
|
|
87
|
+
/** File extension, e.g. `.png`. */
|
|
88
|
+
get extension() {
|
|
89
|
+
return Paths.extname(this.uri);
|
|
90
|
+
}
|
|
91
|
+
/** File name. Includes the extension. */
|
|
92
|
+
get name() {
|
|
93
|
+
return Paths.basename(this.uri);
|
|
94
|
+
}
|
|
95
|
+
readableStream() {
|
|
96
|
+
return new ReadableStream(new FileSystemReadableStreamSource(super.open(FileMode.ReadOnly)));
|
|
97
|
+
}
|
|
98
|
+
writableStream() {
|
|
99
|
+
return new WritableStream(new FileSystemWritableSink(super.open(FileMode.WriteOnly)));
|
|
100
|
+
}
|
|
101
|
+
async arrayBuffer() {
|
|
102
|
+
const bytes = await this.bytes();
|
|
103
|
+
return bytes.buffer;
|
|
104
|
+
}
|
|
105
|
+
async json() {
|
|
106
|
+
return JSON.parse(await this.text());
|
|
107
|
+
}
|
|
108
|
+
async formData() {
|
|
109
|
+
return new Response(await this.arrayBuffer(), {
|
|
110
|
+
headers: this.type ? { 'Content-Type': this.type } : undefined,
|
|
111
|
+
}).formData();
|
|
112
|
+
}
|
|
113
|
+
stream() {
|
|
114
|
+
return this.readableStream();
|
|
115
|
+
}
|
|
116
|
+
slice(start, end, contentType) {
|
|
117
|
+
// React Native's own ambient `Blob` declaration (react-native/src/types/globals.d.ts) is
|
|
118
|
+
// narrower than its runtime: `blobParts` is typed as `(Blob | string)[]` only (the real
|
|
119
|
+
// native implementation accepts raw bytes), and `BlobOptions` requires both `type` and
|
|
120
|
+
// `lastModified` even though `lastModified` is a `File`-only concept the Web `Blob` spec
|
|
121
|
+
// doesn't have at all. Cast at this one call — RN's declared contract, not our logic, is
|
|
122
|
+
// what's incomplete; `lastModified` is supplied only to satisfy the type and is not read by
|
|
123
|
+
// any real `Blob` implementation.
|
|
124
|
+
const bytes = this.bytesSync().slice(start, end);
|
|
125
|
+
return new Blob([bytes], {
|
|
126
|
+
type: contentType ?? '',
|
|
127
|
+
lastModified: Date.now(),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Uploads this file to a server and starts the request immediately.
|
|
132
|
+
*/
|
|
133
|
+
upload(url, options) {
|
|
134
|
+
return new UploadTask(this, url, options).uploadAsync();
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Creates an upload task for this file without starting it.
|
|
138
|
+
*/
|
|
139
|
+
createUploadTask(url, options) {
|
|
140
|
+
return new UploadTask(this, url, options);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Creates a download task without starting it.
|
|
144
|
+
*/
|
|
145
|
+
static createDownloadTask(url, destination, options) {
|
|
146
|
+
return new DownloadTask(url, destination, options);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Watches this file for changes on the filesystem. The watcher automatically stops when the
|
|
150
|
+
* file is deleted or renamed. To stop watching manually, call `remove()` on the returned
|
|
151
|
+
* subscription.
|
|
152
|
+
*/
|
|
153
|
+
watch(callback, options) {
|
|
154
|
+
return new FileSystemWatcher(this.uri, callback, options, uri => new File(uri));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// Cannot use `static` keyword in class declaration because of a runtime error (matches upstream's
|
|
158
|
+
// own comment — assigning after the class body avoids whatever native interop issue upstream ran
|
|
159
|
+
// into with `SharedObject`-extending classes).
|
|
160
|
+
File.downloadFileAsync = async function downloadFileAsync(url, to, options) {
|
|
161
|
+
const needsUuid = options?.onProgress || options?.signal;
|
|
162
|
+
const downloadUuid = needsUuid ? uuid.v4() : undefined;
|
|
163
|
+
let subscription;
|
|
164
|
+
let abortHandler;
|
|
165
|
+
let lastProgress;
|
|
166
|
+
try {
|
|
167
|
+
if (options?.signal?.aborted) {
|
|
168
|
+
throw createAbortError(options.signal.reason);
|
|
169
|
+
}
|
|
170
|
+
if (downloadUuid && options?.onProgress) {
|
|
171
|
+
subscription = expoFileSystemNext.addListener('downloadProgress', event => {
|
|
172
|
+
if (event.uuid === downloadUuid) {
|
|
173
|
+
lastProgress = event.data;
|
|
174
|
+
options.onProgress(lastProgress);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
if (downloadUuid && options?.signal) {
|
|
179
|
+
abortHandler = () => {
|
|
180
|
+
expoFileSystemNext.cancelDownloadAsync(downloadUuid);
|
|
181
|
+
};
|
|
182
|
+
options.signal.addEventListener('abort', abortHandler, { once: true });
|
|
183
|
+
}
|
|
184
|
+
const outputURI = await expoFileSystemNext.downloadFileAsync(url, to, options, downloadUuid);
|
|
185
|
+
const file = new File(outputURI);
|
|
186
|
+
const fileSize = file.size ?? 0;
|
|
187
|
+
if (options?.onProgress &&
|
|
188
|
+
fileSize > 0 &&
|
|
189
|
+
(lastProgress?.bytesWritten !== fileSize ||
|
|
190
|
+
lastProgress?.totalBytes !== fileSize)) {
|
|
191
|
+
options.onProgress({ bytesWritten: fileSize, totalBytes: fileSize });
|
|
192
|
+
}
|
|
193
|
+
return file;
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
if (options?.signal?.aborted) {
|
|
197
|
+
throw createAbortError(options.signal.reason);
|
|
198
|
+
}
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
finally {
|
|
202
|
+
subscription?.remove();
|
|
203
|
+
if (abortHandler && options?.signal) {
|
|
204
|
+
options.signal.removeEventListener('abort', abortHandler);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
//# sourceMappingURL=file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/next/file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAA0B,MAAM,mBAAmB,CAAC;AAEjE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EACL,8BAA8B,EAC9B,sBAAsB,GACvB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EACL,QAAQ,GAcT,MAAM,SAAS,CAAC;AAEjB,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pC,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC3D,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { type EventSubscription } from 'expo-modules-core';
|
|
2
|
+
import type { Directory } from './directory';
|
|
3
|
+
import type { File } from './file';
|
|
4
|
+
import type { IDirectoryCreateOptions, IDirectoryInfo, IFileCreateOptions, IFileInfo, IFileSystemDownloadOptions, IFileSystemDownloadProgress, IFileSystemHandle, IFileSystemInfoOptions, IFileSystemUploadProgress, IFileSystemUploadResult, IFileSystemWatchEvent, IFileSystemWatchOptions, IFileWriteOptions, IPathInfo, IPickMultipleFilesOptions, IPickSingleFileOptions, IRelocationOptions, FileMode } from './types';
|
|
5
|
+
export declare class NativeFileSystemDirectory {
|
|
6
|
+
constructor(...uris: (string | File | Directory)[]);
|
|
7
|
+
readonly uri: string;
|
|
8
|
+
validatePath(): void;
|
|
9
|
+
delete(): void;
|
|
10
|
+
exists: boolean;
|
|
11
|
+
create(options?: IDirectoryCreateOptions): void;
|
|
12
|
+
createFile(name: string, mimeType: string | null): File;
|
|
13
|
+
createDirectory(name: string): Directory;
|
|
14
|
+
copy(destination: Directory | File, options?: IRelocationOptions): Promise<void>;
|
|
15
|
+
copySync(destination: Directory | File, options?: IRelocationOptions): void;
|
|
16
|
+
move(destination: Directory | File, options?: IRelocationOptions): Promise<void>;
|
|
17
|
+
moveSync(destination: Directory | File, options?: IRelocationOptions): void;
|
|
18
|
+
rename(newName: string): void;
|
|
19
|
+
listAsRecords(): {
|
|
20
|
+
isDirectory: boolean;
|
|
21
|
+
uri: string;
|
|
22
|
+
}[];
|
|
23
|
+
list(): (Directory | File)[];
|
|
24
|
+
info(): IDirectoryInfo;
|
|
25
|
+
size: number | null;
|
|
26
|
+
}
|
|
27
|
+
export declare class NativeFileSystemFile {
|
|
28
|
+
constructor(...uris: (string | File | Directory)[]);
|
|
29
|
+
get uri(): string;
|
|
30
|
+
validatePath(): void;
|
|
31
|
+
text(): Promise<string>;
|
|
32
|
+
textSync(): string;
|
|
33
|
+
base64(): Promise<string>;
|
|
34
|
+
base64Sync(): string;
|
|
35
|
+
bytes(): Promise<Uint8Array<ArrayBuffer>>;
|
|
36
|
+
bytesSync(): Uint8Array;
|
|
37
|
+
write(content: string | Uint8Array, options?: IFileWriteOptions): void;
|
|
38
|
+
delete(): void;
|
|
39
|
+
info(options?: IFileSystemInfoOptions): IFileInfo;
|
|
40
|
+
exists: boolean;
|
|
41
|
+
create(options?: IFileCreateOptions): void;
|
|
42
|
+
copy(destination: Directory | File, options?: IRelocationOptions): Promise<void>;
|
|
43
|
+
copySync(destination: Directory | File, options?: IRelocationOptions): void;
|
|
44
|
+
move(destination: Directory | File, options?: IRelocationOptions): Promise<void>;
|
|
45
|
+
moveSync(destination: Directory | File, options?: IRelocationOptions): void;
|
|
46
|
+
rename(newName: string): void;
|
|
47
|
+
open(mode?: FileMode): IFileSystemHandle;
|
|
48
|
+
size: number;
|
|
49
|
+
md5: string | null;
|
|
50
|
+
modificationTime: number | null;
|
|
51
|
+
lastModified: number | null;
|
|
52
|
+
creationTime: number | null;
|
|
53
|
+
type: string;
|
|
54
|
+
contentUri: string;
|
|
55
|
+
}
|
|
56
|
+
export declare class NativeFileSystemUploadTask {
|
|
57
|
+
start(url: string, file: File, options: Record<string, unknown>): Promise<IFileSystemUploadResult>;
|
|
58
|
+
cancel(): void;
|
|
59
|
+
release(): void;
|
|
60
|
+
addListener(eventName: 'progress', listener: (data: IFileSystemUploadProgress) => void): EventSubscription;
|
|
61
|
+
}
|
|
62
|
+
export declare class NativeFileSystemDownloadTask {
|
|
63
|
+
start(url: string, to: File | Directory, options?: Record<string, unknown>): Promise<string | null>;
|
|
64
|
+
pause(): Promise<{
|
|
65
|
+
resumeData?: string;
|
|
66
|
+
} | undefined>;
|
|
67
|
+
resume(url: string, to: File | Directory, resumeData: string, options?: Record<string, unknown>): Promise<string | null>;
|
|
68
|
+
cancel(): void;
|
|
69
|
+
release(): void;
|
|
70
|
+
addListener(eventName: 'progress', listener: (data: IFileSystemDownloadProgress) => void): EventSubscription;
|
|
71
|
+
}
|
|
72
|
+
export type INativeFileSystemWatcherEvent = {
|
|
73
|
+
type: IFileSystemWatchEvent<File | Directory>['type'];
|
|
74
|
+
path: string;
|
|
75
|
+
isDirectory: boolean;
|
|
76
|
+
nativeEventFlags?: number;
|
|
77
|
+
newPath?: string;
|
|
78
|
+
newPathIsDirectory?: boolean;
|
|
79
|
+
};
|
|
80
|
+
export declare class NativeFileSystemWatcher {
|
|
81
|
+
constructor(path: string, options?: IFileSystemWatchOptions);
|
|
82
|
+
start(): void;
|
|
83
|
+
stop(): void;
|
|
84
|
+
addListener(eventName: 'change', listener: (event: INativeFileSystemWatcherEvent) => void): EventSubscription;
|
|
85
|
+
}
|
|
86
|
+
export type INativeFileSystemNextModule = {
|
|
87
|
+
FileSystemDirectory: typeof NativeFileSystemDirectory;
|
|
88
|
+
FileSystemFile: typeof NativeFileSystemFile;
|
|
89
|
+
FileSystemUploadTask: typeof NativeFileSystemUploadTask;
|
|
90
|
+
FileSystemDownloadTask: typeof NativeFileSystemDownloadTask;
|
|
91
|
+
FileSystemWatcher: typeof NativeFileSystemWatcher;
|
|
92
|
+
downloadFileAsync(url: string, destination: File | Directory, options?: IFileSystemDownloadOptions, uuid?: string): Promise<string>;
|
|
93
|
+
cancelDownloadAsync(uuid: string): void;
|
|
94
|
+
pickDirectoryAsync(initialUri?: string): Promise<Directory>;
|
|
95
|
+
pickFileAsync(options: IPickSingleFileOptions): Promise<File>;
|
|
96
|
+
pickFileAsync(options: IPickMultipleFilesOptions): Promise<File[]>;
|
|
97
|
+
info(uri: string): IPathInfo;
|
|
98
|
+
totalDiskSpace: number;
|
|
99
|
+
availableDiskSpace: number;
|
|
100
|
+
documentDirectory: string;
|
|
101
|
+
cacheDirectory: string;
|
|
102
|
+
bundleDirectory: string;
|
|
103
|
+
appleSharedContainers?: Record<string, string>;
|
|
104
|
+
addListener(eventName: 'downloadProgress', listener: (data: {
|
|
105
|
+
uuid: string;
|
|
106
|
+
data: IFileSystemDownloadProgress;
|
|
107
|
+
}) => void): EventSubscription;
|
|
108
|
+
};
|
|
109
|
+
export declare const expoFileSystemNext: INativeFileSystemNextModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-module.js","sourceRoot":"","sources":["../../src/next/native-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAA0B,MAAM,mBAAmB,CAAC;AA0LhF,MAAM,CAAC,MAAM,kBAAkB,GAC7B,mBAAmB,CAA8B,YAAY,CAAC,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { EventSubscription } from 'expo-modules-core';
|
|
2
|
+
import { Directory } from './directory';
|
|
3
|
+
import { File } from './file';
|
|
4
|
+
import { type IFileSystemDownloadPauseState, type IFileSystemDownloadProgress, type IFileSystemDownloadTaskOptions, type IFileSystemDownloadTaskState, type IFileSystemUploadOptions, type IFileSystemUploadProgress, type IFileSystemUploadResult, type IFileSystemUploadTaskState } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Represents an upload task with progress tracking and cancellation support.
|
|
7
|
+
*
|
|
8
|
+
* Upload tasks start in the `idle` state. Calling `uploadAsync()` moves the task to `active`,
|
|
9
|
+
* then to `completed`, `cancelled`, or `error`.
|
|
10
|
+
*/
|
|
11
|
+
export declare class UploadTask {
|
|
12
|
+
private _state;
|
|
13
|
+
private _file;
|
|
14
|
+
private _url;
|
|
15
|
+
private _options?;
|
|
16
|
+
private _subscription?;
|
|
17
|
+
private _abortHandler?;
|
|
18
|
+
private readonly _nativeTask;
|
|
19
|
+
/**
|
|
20
|
+
* Creates an upload task. The task does not start automatically — call `uploadAsync()` to
|
|
21
|
+
* begin uploading.
|
|
22
|
+
*/
|
|
23
|
+
constructor(file: File, url: string, options?: IFileSystemUploadOptions);
|
|
24
|
+
/** The current state of the upload task. */
|
|
25
|
+
get state(): IFileSystemUploadTaskState;
|
|
26
|
+
/**
|
|
27
|
+
* Starts the upload operation. Can only be called once, while the task is `idle`. The promise
|
|
28
|
+
* resolves with response metadata and body for completed HTTP responses, including non-2xx
|
|
29
|
+
* status codes. It is rejected when the file cannot be read, the request fails, or the task is
|
|
30
|
+
* cancelled. If `options.signal` is aborted, the promise is rejected with an `AbortError`.
|
|
31
|
+
*/
|
|
32
|
+
uploadAsync(): Promise<IFileSystemUploadResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Adds a listener for upload progress events. Prefer the `onProgress` option unless manual
|
|
35
|
+
* subscription control is needed.
|
|
36
|
+
*/
|
|
37
|
+
addListener(eventName: 'progress', listener: (data: IFileSystemUploadProgress) => void): EventSubscription;
|
|
38
|
+
/** Releases the native task handle manually. */
|
|
39
|
+
release(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Cancels the upload operation. If `uploadAsync()` is pending, its promise is rejected after
|
|
42
|
+
* the native request is cancelled. Has no effect once the task reaches a terminal state.
|
|
43
|
+
*/
|
|
44
|
+
cancel(): void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Represents a download task with pause/resume support and progress tracking.
|
|
48
|
+
*
|
|
49
|
+
* Download tasks start in the `idle` state. Calling `downloadAsync()` moves the task to
|
|
50
|
+
* `active`; pausing moves it to `paused`, and a completed, cancelled, or failed transfer moves
|
|
51
|
+
* it to the corresponding terminal state.
|
|
52
|
+
*/
|
|
53
|
+
export declare class DownloadTask {
|
|
54
|
+
private _state;
|
|
55
|
+
private _url;
|
|
56
|
+
private _destination;
|
|
57
|
+
private _options?;
|
|
58
|
+
private _resumeData?;
|
|
59
|
+
private _subscription?;
|
|
60
|
+
private _abortHandler?;
|
|
61
|
+
private _inFlightOperation?;
|
|
62
|
+
private _pauseRequest?;
|
|
63
|
+
private readonly _nativeTask;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a download task. The task does not start automatically — call `downloadAsync()` to
|
|
66
|
+
* begin downloading.
|
|
67
|
+
*/
|
|
68
|
+
constructor(url: string, destination: File | Directory, options?: IFileSystemDownloadTaskOptions);
|
|
69
|
+
/** The current state of the download task. */
|
|
70
|
+
get state(): IFileSystemDownloadTaskState;
|
|
71
|
+
/**
|
|
72
|
+
* Starts the download operation. Can only be called once, while the task is `idle`. Resolves
|
|
73
|
+
* with the downloaded file when the transfer completes, or with `null` if the task is paused
|
|
74
|
+
* before completion.
|
|
75
|
+
*/
|
|
76
|
+
downloadAsync(): Promise<File | null>;
|
|
77
|
+
/**
|
|
78
|
+
* Requests pausing the active download operation. The pending `downloadAsync()`/`resumeAsync()`
|
|
79
|
+
* promise resolves with `null` once native code produces resume data. Use `pauseAsync()` to
|
|
80
|
+
* wait for that to happen.
|
|
81
|
+
*/
|
|
82
|
+
pause(): void;
|
|
83
|
+
/**
|
|
84
|
+
* Requests pausing the active download operation and waits until the task reaches the
|
|
85
|
+
* `paused` state.
|
|
86
|
+
*/
|
|
87
|
+
pauseAsync(): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Resumes a paused download operation. Resolves with the downloaded file when the transfer
|
|
90
|
+
* completes, or with `null` if paused again before completion.
|
|
91
|
+
*/
|
|
92
|
+
resumeAsync(): Promise<File | null>;
|
|
93
|
+
/**
|
|
94
|
+
* Adds a listener for download progress events. Prefer the `onProgress` option unless manual
|
|
95
|
+
* subscription control is needed.
|
|
96
|
+
*/
|
|
97
|
+
addListener(eventName: 'progress', listener: (data: IFileSystemDownloadProgress) => void): EventSubscription;
|
|
98
|
+
/** Releases the native task handle manually. */
|
|
99
|
+
release(): void;
|
|
100
|
+
/**
|
|
101
|
+
* Cancels the download operation. If `downloadAsync()`/`resumeAsync()` is pending, its promise
|
|
102
|
+
* is rejected after the native request is cancelled. Has no effect once the task reaches a
|
|
103
|
+
* terminal state.
|
|
104
|
+
*/
|
|
105
|
+
cancel(): void;
|
|
106
|
+
/**
|
|
107
|
+
* Returns the paused task state that can be persisted and restored later. Can only be called
|
|
108
|
+
* while the task is `paused`.
|
|
109
|
+
*/
|
|
110
|
+
savable(): IFileSystemDownloadPauseState;
|
|
111
|
+
/**
|
|
112
|
+
* Creates a paused download task from saved state, to continue a download after persisting the
|
|
113
|
+
* value returned by `savable()`.
|
|
114
|
+
*/
|
|
115
|
+
static fromSavable(state: IFileSystemDownloadPauseState, options?: IFileSystemDownloadTaskOptions): DownloadTask;
|
|
116
|
+
private _runDownloadOperation;
|
|
117
|
+
private _emitFinalProgressEvent;
|
|
118
|
+
}
|