@zenfs/dom 1.2.1 → 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/dist/access.d.ts +3 -2
- package/dist/access.js +13 -3
- package/package.json +1 -1
package/dist/access.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface WebAccessOptions {
|
|
|
9
9
|
*/
|
|
10
10
|
disableHandleCache?: boolean;
|
|
11
11
|
}
|
|
12
|
-
type HKindToType<T extends FileSystemHandleKind> = T extends 'directory' ? FileSystemDirectoryHandle : T extends 'file' ? FileSystemFileHandle : FileSystemHandle;
|
|
12
|
+
type HKindToType<T extends FileSystemHandleKind | null> = T extends 'directory' ? FileSystemDirectoryHandle : T extends 'file' ? FileSystemFileHandle : FileSystemHandle;
|
|
13
13
|
declare const WebAccessFS_base: import("@zenfs/core").Mixin<typeof IndexFS, import("@zenfs/core").AsyncMixin>;
|
|
14
14
|
/**
|
|
15
15
|
* @todo Consider supporting synchronous stuff with `FileSystemFileHandle.createSyncAccessHandle()`\
|
|
@@ -40,6 +40,7 @@ export declare class WebAccessFS extends WebAccessFS_base {
|
|
|
40
40
|
_sync: FileSystem;
|
|
41
41
|
constructor(root: FileSystemDirectoryHandle, disableHandleCache?: boolean);
|
|
42
42
|
stat(path: string): Promise<Inode>;
|
|
43
|
+
readdir(path: string): Promise<string[]>;
|
|
43
44
|
protected remove(path: string): Promise<void>;
|
|
44
45
|
protected removeSync(): void;
|
|
45
46
|
read(path: string, buffer: Uint8Array, offset: number, end: number): Promise<void>;
|
|
@@ -50,7 +51,7 @@ export declare class WebAccessFS extends WebAccessFS_base {
|
|
|
50
51
|
*/
|
|
51
52
|
writeFile(path: string, data: Uint8Array): Promise<void>;
|
|
52
53
|
mkdir(path: string, options: CreationOptions): Promise<InodeLike>;
|
|
53
|
-
protected get<const T extends FileSystemHandleKind | null>(kind: T | undefined, path: string): Promise<
|
|
54
|
+
protected get<const T extends FileSystemHandleKind | null>(kind: T | undefined, path: string): Promise<HKindToType<T>>;
|
|
54
55
|
}
|
|
55
56
|
declare const _WebAccess: {
|
|
56
57
|
readonly name: "WebAccess";
|
package/dist/access.js
CHANGED
|
@@ -107,6 +107,10 @@ export class WebAccessFS extends Async(IndexFS) {
|
|
|
107
107
|
return inode;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
+
async readdir(path) {
|
|
111
|
+
const dirHandle = await this.get('directory', path);
|
|
112
|
+
return await Array.fromAsync(dirHandle.keys());
|
|
113
|
+
}
|
|
110
114
|
async remove(path) {
|
|
111
115
|
const handle = await this.get('directory', dirname(path));
|
|
112
116
|
await handle.removeEntry(basename(path), { recursive: true }).catch(ex => _throw(convertException(ex, path)));
|
|
@@ -204,10 +208,16 @@ export class WebAccessFS extends Async(IndexFS) {
|
|
|
204
208
|
return handle;
|
|
205
209
|
}
|
|
206
210
|
catch (ex) {
|
|
207
|
-
if (ex.name
|
|
208
|
-
throw withErrno(kind == 'file' ? 'EISDIR' : 'ENOTDIR');
|
|
209
|
-
else
|
|
211
|
+
if (ex.name != 'TypeMismatchError')
|
|
210
212
|
throw convertException(ex, path);
|
|
213
|
+
else if (kind === null) {
|
|
214
|
+
const handle = await dir.getFileHandle(parts.at(-1)).catch(ex => _throw(convertException(ex, path)));
|
|
215
|
+
if (!this.disableHandleCache)
|
|
216
|
+
this._handles.set(path, handle);
|
|
217
|
+
return handle;
|
|
218
|
+
}
|
|
219
|
+
else
|
|
220
|
+
throw withErrno(kind == 'file' ? 'EISDIR' : 'ENOTDIR');
|
|
211
221
|
}
|
|
212
222
|
}
|
|
213
223
|
}
|