UNPKG

univ-fs-webnfs

Version:

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

44 lines 1.43 kB
import { AbstractFile } from "univ-fs"; export class WnfsFile extends AbstractFile { constructor(wfs, path) { super(wfs, path); this.wfs = wfs; } async _doDelete() { const { parent, name } = await this.wfs._getParent(this.path); await parent.removeEntry(name); } async _doRead(_stats, _options) { const { parent, name } = await this.wfs._getParent(this.path); const fileHandle = await parent.getFileHandle(name); return await fileHandle.getFile(); } async _doWrite(data, stats, options) { const { parent, name } = await this.wfs._getParent(this.path); const fileHandle = await parent.getFileHandle(name, { create: stats == null, }); const writable = await fileHandle.createWritable({ keepExistingData: options.append, }); if (options.append) { const stats = await this.head(options); await writable.seek(stats.size); } const conv = await this._getConverter(); const co = { ...options }; delete co.start; const readable = await conv.convert("readablestream", data, co); await conv.pipe(readable, writable); } supportAppend() { return true; } supportRangeRead() { return false; } supportRangeWrite() { return true; } } //# sourceMappingURL=WnfsFile.js.map