handles
Documentation / @wtf/platform-fs-adapter / handles
Handles of the WHATWG File System Standard over any file system shaped as Node’s fs/promises:
fromNodeShaped, the handle of a folder of it. Node’s, Bun’s or Deno’s node:fs is one,
and so is memfs’, in a browser or a test; it imports nothing of Node, and
@wtf/platform-fs-node gives it Node’s own. A file is read as it streams, and written on a file
beside it, <name>.<n>.crswap, which takes its place as the writable closes; what the file system
throws is the standard’s DOMException, by domExceptionOf of ./errors.
Each handle is a class of this module, made to be extended: a folder makes the handle of each
entry in it by one method, handleOf, which a class that extends them
overrides to make its own; and NodeShapedDirectoryHandle.root makes the root of the class
it is called of. A handle that extends them reaches what it is of by its protected members: its
context, the file system and the writables open of it, its path, and its stats().
import { memfs } from 'memfs'
const { fs } = memfs()const root = await fromNodeShaped(fs.promises as unknown as NodeShapedFileSystem, '/', { create: true})