|
| 1 | +import {NodeFileSystemHandle} from "./NodeFileSystemHandle"; |
| 2 | +import {basename} from "./util"; |
| 3 | +import type {FsaNodeFs} from "./types"; |
| 4 | + |
| 5 | +/** |
| 6 | + * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle |
| 7 | + */ |
| 8 | +export class NodeFileSystemDirectoryHandle extends NodeFileSystemHandle { |
| 9 | + constructor ( |
| 10 | + protected readonly fs: FsaNodeFs, |
| 11 | + protected readonly path: string, |
| 12 | + ) { |
| 13 | + super('directory', basename(path)); |
| 14 | + } |
| 15 | + |
| 16 | + /** |
| 17 | + * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/entries |
| 18 | + */ |
| 19 | + public entries(): AsyncIterableIterator<[string, NodeFileSystemHandle]> { |
| 20 | + throw new Error('Not implemented'); |
| 21 | + } |
| 22 | + |
| 23 | + /** |
| 24 | + * Returns a new array iterator containing the keys for each item in |
| 25 | + * {@link NodeFileSystemDirectoryHandle} object. |
| 26 | + * |
| 27 | + * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/keys |
| 28 | + */ |
| 29 | + public keys(): AsyncIterableIterator<string> { |
| 30 | + const {path, fs} = this; |
| 31 | + return (async function*() { |
| 32 | + const list = await fs.promises.readdir(path); |
| 33 | + for (const name of list) yield name; |
| 34 | + })(); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Returns a new array iterator containing the values for each index in the |
| 39 | + * {@link FileSystemDirectoryHandle} object. |
| 40 | + * |
| 41 | + * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/values |
| 42 | + */ |
| 43 | + public values(): AsyncIterableIterator<NodeFileSystemHandle> { |
| 44 | + throw new Error('Not implemented'); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/getDirectoryHandle |
| 49 | + * @param name A string representing the {@link NodeFileSystemHandle} name of |
| 50 | + * the subdirectory you wish to retrieve. |
| 51 | + * @param options An optional object containing options for the retrieved |
| 52 | + * subdirectory. |
| 53 | + */ |
| 54 | + public getDirectoryHandle(name: string, options?: GetDirectoryHandleOptions): Promise<NodeFileSystemDirectoryHandle> { |
| 55 | + throw new Error('Not implemented'); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/getFileHandle |
| 60 | + * @param name A string representing the {@link NodeFileSystemHandle} name of |
| 61 | + * the file you wish to retrieve. |
| 62 | + * @param options An optional object containing options for the retrieved file. |
| 63 | + */ |
| 64 | + public getFileHandle(name: string, options?: GetFileHandleOptions): Promise<NodeFileSystemDirectoryHandle> { |
| 65 | + throw new Error('Not implemented'); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/removeEntry |
| 70 | + * @param name A string representing the {@link FileSystemHandle} name of the |
| 71 | + * entry you wish to remove. |
| 72 | + * @param options An optional object containing options. |
| 73 | + */ |
| 74 | + public removeEntry(name: string, options?: RemoveEntryOptions): Promise<void> { |
| 75 | + throw new Error('Not implemented'); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * The `resolve()` method of the {@link FileSystemDirectoryHandle} interface |
| 80 | + * returns an {@link Array} of directory names from the parent handle to the specified |
| 81 | + * child entry, with the name of the child entry as the last array item. |
| 82 | + * |
| 83 | + * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/resolve |
| 84 | + * @param possibleDescendant The {@link NodeFileSystemFileHandle} from which |
| 85 | + * to return the relative path. |
| 86 | + */ |
| 87 | + public resolve(possibleDescendant: NodeFileSystemHandle): Promise<string[] | null> { |
| 88 | + throw new Error('Not implemented'); |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +export interface GetDirectoryHandleOptions { |
| 93 | + /** |
| 94 | + * A boolean value, which defaults to `false`. When set to `true` if the directory |
| 95 | + * is not found, one with the specified name will be created and returned. |
| 96 | + */ |
| 97 | + create?: boolean; |
| 98 | +} |
| 99 | + |
| 100 | +export interface GetFileHandleOptions { |
| 101 | + /** |
| 102 | + * A Boolean. Default `false`. When set to `true` if the file is not found, |
| 103 | + * one with the specified name will be created and returned. |
| 104 | + */ |
| 105 | + create?: boolean; |
| 106 | +} |
| 107 | + |
| 108 | +export interface RemoveEntryOptions { |
| 109 | + /** |
| 110 | + * A boolean value, which defaults to `false`. When set to true entries will |
| 111 | + * be removed recursively. |
| 112 | + */ |
| 113 | + recursive?: boolean; |
| 114 | +} |
0 commit comments