UNPKG

univ-fs-webnfs

Version:

The universal Filesystem for Web File System Access API (Native File System API)

43 lines 1.41 kB
import { AbstractDirectory, EntryType, joinPaths } from "univ-fs"; export class WnfsDirectory extends AbstractDirectory { constructor(wfs, path) { super(wfs, path); this.wfs = wfs; } async _doDelete() { if (this.path === "/") { return; } const { parent, name } = await this.wfs._getParent(this.path); await parent.removeEntry(name); } async _doList() { const directoryHandle = await this._getDirectoryHandle(false); const items = []; const entries = directoryHandle.entries(); let result = await entries.next(); while (!result.done) { const [name, handle] = result.value; items.push({ path: joinPaths(this.path, name), type: handle.kind === "file" ? EntryType.File : EntryType.Directory, }); result = await entries.next(); } return items; } async _doMkcol() { if (this.path === "/") { return; } await this._getDirectoryHandle(true); } async _getDirectoryHandle(create) { if (this.path === "/") { return await this.wfs._getRoot(); } const { parent, name } = await this.wfs._getParent(this.path); return await parent.getDirectoryHandle(name, { create }); } } //# sourceMappingURL=WnfsDirectory.js.map