### Example Backend Implementation Source: https://zenfs.dev/core/documents/Backends.html An example of how a backend can be implemented in ZenFS, defining options and a create method for a FileSystem instance. ```typescript interface ExampleOptions { raw: RawExampleData; // e.g. `Storage` for a backend that works with `localStorage` } const Example = { name: 'ExampleStorage', options: { raw: { type: 'object', required: true }, }, async create({ raw }: ExampleOptions) { await raw.doSomethingAsync(); return new ExampleFS(raw); }, } as const satisfies Backend; ``` -------------------------------- ### Install ZenFS Core Source: https://zenfs.dev/core/index.html Install the ZenFS core package using npm. This is the first step to using ZenFS in your project. ```bash npm install @zenfs/core Copy ``` -------------------------------- ### Resolve and Mount a File System Instance Source: https://zenfs.dev/core/documents/Configuration.html This example shows how to resolve a mount configuration, instantiate a file system instance using an asynchronous backend, and then mount it. ```typescript import { resolveMountConfig, InMemory, mount } from '@zenfs/core'; const tmpfs = await resolveMountConfig({ backend: InMemory, label: 'temp-storage', }); mount('/mnt/tmp', tmpfs); ``` -------------------------------- ### Implement a Custom Null Device Driver Source: https://zenfs.dev/core/documents/Devices_and_Device_Drivers Example implementation of a custom null device driver, demonstrating the structure required for a DeviceDriver. ```javascript const customNullDevice = { name: 'custom_null', // only 1 can exist per DeviceFS singleton: true, // optional if false isBuffered: false, read() { return 0; }, write() { return 0; }, }; ``` -------------------------------- ### get Source: https://zenfs.dev/core/classes/index.SyncTransaction.html Retrieves data asynchronously from the store. ```APIDOC ## get(id: number, offset: number, end?: number) ### Description Retrieves data asynchronously from the store. ### Parameters * **id** (number) - The key to look under for data. * **offset** (number) - The starting offset for retrieval. * **end** (number) - Optional. The ending offset for retrieval. ### Returns Promise | undefined> ``` -------------------------------- ### get Method Source: https://zenfs.dev/core/classes/index.SyncMapTransaction.html Asynchronously retrieves data associated with a given key from the store. ```APIDOC ## get(id: number): Promise | undefined> ### Description Retrieves data asynchronously from the store. ### Parameters * **id** (number) - Required - The key to look under for data. ### Returns * Promise | undefined> - A promise that resolves with the data as a Uint8Array or undefined if the key does not exist. ``` -------------------------------- ### Configure Single ZenFS Backend with WebStorage Source: https://zenfs.dev/core Configure ZenFS to use a single backend, WebStorage, mounted on the root path. This example demonstrates writing and reading a file that persists across reloads. ```javascript import { configureSingle, fs } from '@zenfs/core'; import { WebStorage } from '@zenfs/dom'; await configureSingle({ backend: WebStorage }); if (!fs.existsSync('/test.txt')) { fs.writeFileSync('/test.txt', 'This will persist across reloads!'); } const contents = fs.readFileSync('/test.txt', 'utf-8'); console.log(contents); ``` -------------------------------- ### Configure Multiple Backends Source: https://zenfs.dev/core/index.html Configure ZenFS to use multiple backends mounted at different paths. This example mounts a Zip backend, an InMemory backend, and an IndexedDB backend. ```javascript import { configure, InMemory } from '@zenfs/core'; import { IndexedDB } from '@zenfs/dom'; import { Zip } from '@zenfs/archives'; const res = await fetch('mydata.zip'); await configure({ mounts: { '/mnt/zip': { backend: Zip, data: await res.arrayBuffer() }, '/tmp': InMemory, '/home': IndexedDB, }, }); ``` -------------------------------- ### Configure Single Backend with WebStorage Source: https://zenfs.dev/core/index.html Configure ZenFS to use a single backend, specifically WebStorage, mounted at the root path. This example demonstrates persisting data across reloads. ```javascript import { configureSingle, fs } from '@zenfs/core'; import { WebStorage } from '@zenfs/dom'; await configureSingle({ backend: WebStorage }); if (!fs.existsSync('/test.txt')) { fs.writeFileSync('/test.txt', 'This will persist across reloads!'); } const contents = fs.readFileSync('/test.txt', 'utf-8'); console.log(contents); ``` -------------------------------- ### Static get Source: https://zenfs.dev/core/classes/index.SuperBlock.html Get a value from a buffer. ```APIDOC ## Static get(buffer, offset) ### Description Get a value from a buffer. ### Method `BigUint64Array.get(buffer, offset)` ### Parameters #### Path Parameters - **buffer** (ArrayBufferLike) - Required - The buffer to get the value from. - **offset** (number) - Required - The offset within the buffer. ### Returns ArrayBufferView ``` -------------------------------- ### ready Source: https://zenfs.dev/core/classes/index.FileSystem.html Asynchronously prepares the file system. ```APIDOC ## ready ### Description Asynchronously prepares the file system. ### Returns * Promise ``` -------------------------------- ### get(path: string, name: XattrName, opt: fs.xattr.Options & ObjectEncodingOptions): Promise Source: https://zenfs.dev/core/functions/index.fs.xattr.get.html Gets the value of an extended attribute. This overload returns a string when a string encoding is specified. ```APIDOC ## Function get (String return) ### Description Gets the value of an extended attribute. ### Parameters * **path** (string) - Required - Path to the file * **name** (string) - Required - Name of the attribute to get. Must be one of `system.*`, `user.*`, `trusted.*`, or `security.*`. * **opt** (fs.xattr.Options & ObjectEncodingOptions) - Required - Options for the operation. ### Returns Promise - A string when a string encoding is specified. ``` -------------------------------- ### ready Source: https://zenfs.dev/core/interfaces/index.RPC.Methods.html Indicates if the system is ready. Returns void. ```APIDOC ## ready ### Description Checks and returns the readiness status of the system. ### Method RPC ### Endpoint Methods.ready ### Returns - **void** ``` -------------------------------- ### get(path: string, name: XattrName, opt?: Options & (BufferEncodingOption | { encoding?: null | undefined; })): Promise Source: https://zenfs.dev/core/functions/index.fs.xattr.get.html Gets the value of an extended attribute. This overload returns a Uint8Array or ArrayBufferLike when encoding is 'buffer' or undefined. ```APIDOC ## Function get (Buffer/ArrayBufferLike return) ### Description Gets the value of an extended attribute. ### Parameters * **path** (string) - Required - Path to the file * **name** (string) - Required - Name of the attribute to get. Must be one of `system.*`, `user.*`, `trusted.*`, or `security.*`. * **opt** (Options & (BufferEncodingOption | { encoding?: null | undefined; })) - Optional - Options for the operation. ### Returns Promise - A buffer containing the attribute value when encoding is 'buffer' or undefined. ``` -------------------------------- ### ready Source: https://zenfs.dev/core/classes/index.IndexFS.html Asynchronously prepares the file system for operations. ```APIDOC ## ready ### Description Asynchronously prepares the file system for operations. ### Method `Promise` ### Endpoint Not specified ### Returns Promise ``` -------------------------------- ### ready Source: https://zenfs.dev/core/classes/index.FetchFS.html Asynchronously prepares the file system for operations. ```APIDOC ## ready ### Description Asynchronously prepares the file system for operations. ### Method Asynchronous ### Returns Promise ``` -------------------------------- ### Journal.listenerCount Source: https://zenfs.dev/core/classes/index.Journal.html Gets the number of listeners for a specific event. ```APIDOC ## Method ### `listenerCount(event: "delete" | "update"): number` Returns the number of listeners registered for a given event. #### Parameters - **event** (`"delete" | "update"`): The event to count listeners for. #### Returns - `number`: The number of listeners. ``` -------------------------------- ### ready Source: https://zenfs.dev/core/classes/index.CopyOnWriteFS.html Asynchronously prepares the file system for operations. ```APIDOC ## ready() ### Description Asynchronously prepares the file system for operations. ### Returns Promise ``` -------------------------------- ### readySync Source: https://zenfs.dev/core/classes/index.FileSystem.html Synchronously prepares the file system. ```APIDOC ## readySync ### Description Synchronously prepares the file system. ### Returns * void ``` -------------------------------- ### get Source: https://zenfs.dev/core/modules/index.fs.xattr.html Retrieves the value of an extended attribute for a given file. ```APIDOC ## get ### Description Retrieves the value of an extended attribute for a given file. ### Method [Not specified, likely a function call in an SDK] ### Endpoint [Not applicable for SDK functions] ### Parameters [Parameters not explicitly defined in the source] ### Response [Response details not explicitly defined in the source] ``` -------------------------------- ### Static get Source: https://zenfs.dev/core/classes/index.MetadataBlock.html Retrieves a value from a given ArrayBuffer at a specified offset. ```APIDOC ## Static get ### Description Retrieves an ArrayBufferView value from a buffer at a specific offset. ### Method `get(buffer: ArrayBufferLike, offset: number): ArrayBufferView` ### Parameters #### Path Parameters * **buffer** (ArrayBufferLike) - Required - The buffer to read from. * **offset** (number) - Required - The starting offset within the buffer. ### Returns ArrayBufferView - The value retrieved from the buffer. ``` -------------------------------- ### readySync Source: https://zenfs.dev/core/classes/index.IndexFS.html Synchronously prepares the file system for operations. ```APIDOC ## readySync ### Description Synchronously prepares the file system for operations. ### Method `void` ### Endpoint Not specified ### Returns void ``` -------------------------------- ### readySync Source: https://zenfs.dev/core/classes/index.FetchFS.html Synchronously prepares the file system for operations. ```APIDOC ## readySync ### Description Synchronously prepares the file system for operations. ### Method Synchronous ### Returns void ``` -------------------------------- ### Static get Source: https://zenfs.dev/core/classes/index.Attributes.html Retrieves a BufferView from a given ArrayBuffer at a specified offset. ```APIDOC ## Static get ### Description Get a value from a buffer. ### Method `get(buffer: ArrayBufferLike, offset: number): BufferView & ArrayBufferView` ### Parameters #### Path Parameters - **buffer** (ArrayBufferLike) - Required - The buffer to read from. - **offset** (number) - Required - The offset within the buffer to start reading. ### Returns BufferView & ArrayBufferView ``` -------------------------------- ### get Source: https://zenfs.dev/core/classes/index.SingleBufferStore.html Retrieves data from the store by its ID. Returns undefined if the ID is not found. ```APIDOC ## get ### Description Retrieves data from the store by its ID. ### Parameters * `id` (number): The ID of the entry to retrieve. ### Returns * `Uint8Array | undefined`: The data associated with the ID, or undefined if not found. ``` -------------------------------- ### readySync Source: https://zenfs.dev/core/classes/index.CopyOnWriteFS.html Synchronously prepares the file system for operations. ```APIDOC ## readySync() ### Description Synchronously prepares the file system for operations. ### Returns void ``` -------------------------------- ### get Source: https://zenfs.dev/core/classes/index.Transaction.html Asynchronously retrieves data from the store based on the provided ID and offset. ```APIDOC ## get ### Description Retrieves data from the store. ### Method GET (conceptual) ### Parameters #### Path Parameters * **id** (number) - Required - The key to look under for data. * **offset** (number) - Required - The starting offset for retrieval. * **end** (number) - Optional - The ending offset for retrieval. ### Returns Promise | undefined> ``` -------------------------------- ### mkdir Source: https://zenfs.dev/core/interfaces/index.RPC.Methods.html Creates a directory at the specified path with given options. Returns a Uint8Array. ```APIDOC ## mkdir ### Description Creates a new directory at the specified path with given options. ### Method RPC ### Endpoint Methods.mkdir ### Parameters #### Path Parameters - **path** (string) - Required - The path where the directory will be created. - **options** (CreationOptions) - Required - Options for directory creation. ### Returns - **Uint8Array** - The result of the directory creation operation. ``` -------------------------------- ### FileSystem Constructor Source: https://zenfs.dev/core/classes/index.FileSystem.html Initializes a new instance of the FileSystem class. ```APIDOC ## constructor FileSystem ### Description Initializes a new instance of the FileSystem class. ### Parameters * **type** (number) - A unique ID for this kind of file system. Currently unused internally, but could be used for partition tables or something. * **name** (string) - The name for this file system. For example, tmpfs for an in memory one. ### Returns * FileSystem ``` -------------------------------- ### isLocked Accessor Source: https://zenfs.dev/core/classes/index.MutexLock.html Gets a value indicating whether the MutexLock is currently locked. ```APIDOC ## isLocked ### Description Gets a value indicating whether the MutexLock is currently locked. ### Method get isLocked() ### Returns boolean ``` -------------------------------- ### setUint8 Source: https://zenfs.dev/core/classes/index.Attributes.html Stores an Uint8 value at the specified byte offset from the start of the view. ```APIDOC ## setUint8 ### Description Stores an Uint8 value at the specified byte offset from the start of the view. ### Method `setUint8(byteOffset: number, value: number): void` ### Parameters #### Path Parameters - **byteOffset** (number) - Required - The place in the buffer at which the value should be set. - **value** (number) - Required - The value to set. ### Returns void ``` -------------------------------- ### ready Source: https://zenfs.dev/core/classes/index.StoreFS.html Asynchronously prepares the StoreFS for use. This method should be called before other operations. ```APIDOC ## ready ### Description Asynchronously prepares the StoreFS for use. This method should be called before performing other file system operations. ### Method (Asynchronous) ### Returns Promise ``` -------------------------------- ### mkdir Source: https://zenfs.dev/core/classes/index.CopyOnWriteFS.html Asynchronously creates a directory at the specified path with the given options. ```APIDOC ## mkdir(path: string, options: CreationOptions) ### Description Asynchronously creates a directory at the specified path with the given options. ### Parameters * **path** (string) - The path where the directory will be created. * **options** (CreationOptions) - The options for directory creation. ### Returns Promise> ``` -------------------------------- ### setInt8 Source: https://zenfs.dev/core/classes/index.Attributes.html Stores an Int8 value at the specified byte offset from the start of the view. ```APIDOC ## setInt8 ### Description Stores an Int8 value at the specified byte offset from the start of the view. ### Method `setInt8(byteOffset: number, value: number): void` ### Parameters #### Path Parameters - **byteOffset** (number) - Required - The place in the buffer at which the value should be set. - **value** (number) - Required - The value to set. ### Returns void ``` -------------------------------- ### read(fd, buffer, offset, length, position?, cb?) Source: https://zenfs.dev/core/functions/index.fs.read.html Reads data from the file specified by the file descriptor (fd). Data is written into the provided buffer starting at the specified offset, for a given length. An optional position can be provided to specify the read start point in the file. A callback function is invoked upon completion. ```APIDOC ## Function read ### Description Reads data from the file specified by `fd` into the provided `buffer`. ### Signature `read(this: unknown, fd: number, buffer: Uint8Array, offset: number, length: number, position?: number, cb?: Callback<[number, Uint8Array]>): void` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters * **fd** (number) - The file descriptor of the file to read from. * **buffer** (Uint8Array) - The buffer that the data will be written to. * **offset** (number) - The offset within the buffer where writing will start. * **length** (number) - An integer specifying the number of bytes to read. * **position** (number) - Optional. An integer specifying where to begin reading from in the file. If null, data will be read from the current file position. * **cb** (Callback<[number, Uint8Array]>) - Optional. The callback function to be invoked upon completion. The callback receives the number of bytes read and the buffer. ### Request Example * None (This is a function call, not an HTTP request) ### Response #### Success Response * **void**: This function does not return a value directly; results are passed to the callback. #### Response Example * None (Results are handled by the callback) ``` -------------------------------- ### ready Source: https://zenfs.dev/core/interfaces/index.AsyncFSMethods.html Indicates if the file system is ready. ```APIDOC ## ready ### Description Indicates if the file system is ready. ### Method ready ### Returns Promise ``` -------------------------------- ### mkdir Source: https://zenfs.dev/core/classes/index.FileSystem.html Creates a directory at the specified path with the given options asynchronously. ```APIDOC ## mkdir ### Description Creates a directory. ### Parameters * **path** (string) - The path for the new directory. * **options** (CreationOptions) - Options for directory creation. ### Returns * Promise> ``` -------------------------------- ### fill Source: https://zenfs.dev/core/classes/index.MetadataBlock.html Changes all array elements from `start` to `end` index to a static `value` and returns the modified array. ```APIDOC ## fill ### Description Changes all array elements from `start` to `end` index to a static `value` and returns the modified array. ### Method Not applicable (Class Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **value** (number) - Required - The value to fill the array section with. * **start** (number) - Optional - The index to start filling the array at. If negative, it's treated as `length + start`. * **end** (number) - Optional - The index to stop filling the array at. If negative, it's treated as `length + end`. ### Returns * **this** - The modified array instance. ``` -------------------------------- ### mkdirSync (non-recursive) Source: https://zenfs.dev/core/functions/index.fs.mkdirSync.html Synchronously creates a directory. Mode defaults to 0o777. If the directory already exists, it does nothing. ```APIDOC ## mkdirSync (non-recursive) ### Description Synchronously creates a directory. Mode defaults to 0o777. If the directory already exists, it does nothing. ### Method Synchronous function call ### Parameters #### Path Parameter * **path** (PathLike) - The path of the directory to create. #### Options Parameter * **options** (Mode | MakeDirectoryOptions & { recursive?: false } | null) - Optional. An object specifying the mode or options for directory creation. `recursive` defaults to `false`. ### Returns * void - This function does not return a value. ``` -------------------------------- ### getSync (String Encoding) Source: https://zenfs.dev/core/functions/index.fs.xattr.getSync.html Synchronously gets the value of an extended attribute. Returns a string when a string encoding is specified. ```APIDOC ## Function getSync (String Encoding) ### Description Synchronously gets the value of an extended attribute. Returns a string when a string encoding is specified. ### Signature ```typescript getSync( this: unknown, path: string, name: "system.${string}" | "user.${string}" | "trusted.${string}" | "security.${string}", opt: fs.xattr.Options & ObjectEncodingOptions ): string ``` ### Parameters * **this**: unknown * **path** (string): Path to the file * **name** (`system.${string}` | `user.${string}` | `trusted.${string}` | `security.${string}`): Name of the attribute to get * **opt** (`fs.xattr.Options & ObjectEncodingOptions`): Options for the operation ### Returns * **string**: A string containing the attribute value when a string encoding is specified. ``` -------------------------------- ### statSync Source: https://zenfs.dev/core/classes/index.PassthroughFS.html Gets file statistics synchronously. This method takes the file path as a string argument and returns InodeLike. ```APIDOC ## statSync ### Description Gets file statistics synchronously. ### Method Synchronous ### Parameters #### Path Parameters - **path** (string) - Required - The path to the file. ### Returns InodeLike ``` -------------------------------- ### Dir Constructor Source: https://zenfs.dev/core/classes/index.fs.Dir.html Initializes a new Dir instance. It takes a path and a context as arguments. ```APIDOC ## new Dir(path: string, context: unknown): Dir ### Description Initializes a new Dir instance. ### Parameters * **path** (string) - The path to the directory. * **context** (unknown) - The context for the directory stream. ``` -------------------------------- ### setUint32 Source: https://zenfs.dev/core/classes/index.Attributes.html Stores an Uint32 value at the specified byte offset from the start of the view. Supports optional endianness specification. ```APIDOC ## setUint32 ### Description Stores an Uint32 value at the specified byte offset from the start of the view. ### Method `setUint32(byteOffset: number, value: number, littleEndian?: boolean): void` ### Parameters #### Path Parameters - **byteOffset** (number) - Required - The place in the buffer at which the value should be set. - **value** (number) - Required - The value to set. - **littleEndian** (boolean) - Optional - If false or undefined, a big-endian value should be written. ### Returns void ``` -------------------------------- ### setUint16 Source: https://zenfs.dev/core/classes/index.Attributes.html Stores an Uint16 value at the specified byte offset from the start of the view. Supports optional endianness specification. ```APIDOC ## setUint16 ### Description Stores an Uint16 value at the specified byte offset from the start of the view. ### Method `setUint16(byteOffset: number, value: number, littleEndian?: boolean): void` ### Parameters #### Path Parameters - **byteOffset** (number) - Required - The place in the buffer at which the value should be set. - **value** (number) - Required - The value to set. - **littleEndian** (boolean) - Optional - If false or undefined, a big-endian value should be written. ### Returns void ``` -------------------------------- ### mkdir Source: https://zenfs.dev/core/interfaces/index.AsyncFSMethods.html Creates a directory at the specified path with the given options. ```APIDOC ## mkdir ### Description Creates a directory at the specified path with the given options. ### Method mkdir ### Parameters #### Path Parameters - **path** (string) - Required - The path where the directory will be created. - **options** (CreationOptions) - Required - Options for directory creation. ### Returns Promise> ``` -------------------------------- ### from Source: https://zenfs.dev/core/classes/index.fs.Dirent.html Creates a Dirent object from a virtual file system Dirent. ```APIDOC ### `Static`from * from( vfs: vfs.Dirent, encoding?: "buffer" | BufferEncoding | null, ): fs.Dirent `Internal` #### Parameters * vfs: vfs.Dirent * `Optional`encoding: "buffer" | BufferEncoding | null #### Returns fs.Dirent ``` -------------------------------- ### setInt32 Source: https://zenfs.dev/core/classes/index.Attributes.html Stores an Int32 value at the specified byte offset from the start of the view. Supports optional endianness specification. ```APIDOC ## setInt32 ### Description Stores an Int32 value at the specified byte offset from the start of the view. ### Method `setInt32(byteOffset: number, value: number, littleEndian?: boolean): void` ### Parameters #### Path Parameters - **byteOffset** (number) - Required - The place in the buffer at which the value should be set. - **value** (number) - Required - The value to set. - **littleEndian** (boolean) - Optional - If false or undefined, a big-endian value should be written. ### Returns void ``` -------------------------------- ### mkdir Source: https://zenfs.dev/core/classes/index.DeviceFS.html Asynchronously creates a directory. ```APIDOC ## mkdir ### Description Asynchronously creates a directory. ### Method Not specified (likely asynchronous class method) ### Parameters #### Path Parameters - **path** (string) - Required - The path for the new directory. - **options** (CreationOptions) - Required - Options for directory creation. ### Returns Promise> ``` -------------------------------- ### setInt16 Source: https://zenfs.dev/core/classes/index.Attributes.html Stores an Int16 value at the specified byte offset from the start of the view. Supports optional endianness specification. ```APIDOC ## setInt16 ### Description Stores an Int16 value at the specified byte offset from the start of the view. ### Method `setInt16(byteOffset: number, value: number, littleEndian?: boolean): void` ### Parameters #### Path Parameters - **byteOffset** (number) - Required - The place in the buffer at which the value should be set. - **value** (number) - Required - The value to set. - **littleEndian** (boolean) - Optional - If false or undefined, a big-endian value should be written. ### Returns void ``` -------------------------------- ### mkdirSync Source: https://zenfs.dev/core/classes/index.CopyOnWriteFS.html Synchronously creates a directory at the specified path with the given options. ```APIDOC ## mkdirSync(path: string, options: CreationOptions) ### Description Synchronously creates a directory at the specified path with the given options. ### Parameters * **path** (string) - The path where the directory will be created. * **options** (CreationOptions) - The options for directory creation. ### Returns InodeLike ``` -------------------------------- ### setFloat64 Source: https://zenfs.dev/core/classes/index.Attributes.html Stores a Float64 value at the specified byte offset from the start of the view. Supports optional endianness specification. ```APIDOC ## setFloat64 ### Description Stores an Float64 value at the specified byte offset from the start of the view. ### Method `setFloat64(byteOffset: number, value: number, littleEndian?: boolean): void` ### Parameters #### Path Parameters - **byteOffset** (number) - Required - The place in the buffer at which the value should be set. - **value** (number) - Required - The value to set. - **littleEndian** (boolean) - Optional - If false or undefined, a big-endian value should be written. ### Returns void ``` -------------------------------- ### setFloat32 Source: https://zenfs.dev/core/classes/index.Attributes.html Stores a Float32 value at the specified byte offset from the start of the view. Supports optional endianness specification. ```APIDOC ## setFloat32 ### Description Stores an Float32 value at the specified byte offset from the start of the view. ### Method `setFloat32(byteOffset: number, value: number, littleEndian?: boolean): void` ### Parameters #### Path Parameters - **byteOffset** (number) - Required - The place in the buffer at which the value should be set. - **value** (number) - Required - The value to set. - **littleEndian** (boolean) - Optional - If false or undefined, a big-endian value should be written. ### Returns void ``` -------------------------------- ### mkdirSync Source: https://zenfs.dev/core/classes/index.FileSystem.html Synchronously creates a directory at the specified path with the given options. ```APIDOC ## mkdirSync ### Description Creates a directory. ### Parameters * **path** (string) - The path for the new directory. * **options** (CreationOptions) - Options for directory creation. ### Returns * InodeLike ``` -------------------------------- ### setFloat16 Source: https://zenfs.dev/core/classes/index.Attributes.html Stores a Float16 value at the specified byte offset from the start of the view. Supports optional endianness specification. ```APIDOC ## setFloat16 ### Description Stores an Float16 value at the specified byte offset from the start of the view. ### Method `setFloat16(byteOffset: number, value: number, littleEndian?: boolean): void` ### Parameters #### Path Parameters - **byteOffset** (number) - Required - The place in the buffer at which the value should be set. - **value** (number) - Required - The value to set. - **littleEndian** (boolean) - Optional - If false or undefined, a big-endian value should be written. ### Returns void ``` -------------------------------- ### Basic ZenFS Usage Source: https://zenfs.dev/core/index.html Demonstrates basic file operations like writing and reading a file using the default in-memory backend. This can be used anywhere, including browsers. ```javascript import { fs } from '@zenfs/core'; // You can also use the default export fs.writeFileSync('/test.txt', 'You can do this anywhere, including browsers!'); const contents = fs.readFileSync('/test.txt', 'utf-8'); console.log(contents); ``` -------------------------------- ### Configure ZenFS with Automatic Device Addition Source: https://zenfs.dev/core/documents/Devices_and_Device_Drivers Enables automatic addition of normal devices and demonstrates writing to '/dev/null' and reading from '/dev/random'. ```javascript await configure({ mounts: { /* ... */ }, addDevices: true, }); fs.writeFileSync('/dev/null', 'Some data to be discarded'); const randomData = new Uint8Array(100); const random = fs.openSync('/dev/random', 'r'); fs.readSync(random, randomData); fs.closeSync(random); ``` -------------------------------- ### setBigUint64 Source: https://zenfs.dev/core/classes/index.Attributes.html Stores a BigUint64 value at the specified byte offset from the start of the view. Supports optional endianness specification. ```APIDOC ## setBigUint64 ### Description Stores a BigUint64 value at the specified byte offset from the start of the view. ### Method `setBigUint64(byteOffset: number, value: bigint, littleEndian?: boolean): void` ### Parameters #### Path Parameters - **byteOffset** (number) - Required - The place in the buffer at which the value should be set. - **value** (bigint) - Required - The value to set. - **littleEndian** (boolean) - Optional - If false or undefined, a big-endian value should be written. ### Returns void ``` -------------------------------- ### mkdir with general options Source: https://zenfs.dev/core/functions/index.fs.promises.mkdir.html Creates a directory with general options, which can include recursive creation. Returns the resolved path upon success. ```APIDOC ## mkdir(path, options) ### Description Asynchronous mkdir(2) - create a directory. ### Method Asynchronous ### Parameters #### Path Parameters * **path** (PathLike) - Required - A path to a file. If a URL is provided, it must use the `file:` protocol. * **options** (Mode | MakeDirectoryOptions | null) - Optional - Either the file mode, or an object optionally specifying the file mode and whether parent folders should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`. ### Returns Promise - The resolved path upon success. ``` -------------------------------- ### setBigInt64 Source: https://zenfs.dev/core/classes/index.Attributes.html Stores a BigInt64 value at the specified byte offset from the start of the view. Supports optional endianness specification. ```APIDOC ## setBigInt64 ### Description Stores a BigInt64 value at the specified byte offset from the start of the view. ### Method `setBigInt64(byteOffset: number, value: bigint, littleEndian?: boolean): void` ### Parameters #### Path Parameters - **byteOffset** (number) - Required - The place in the buffer at which the value should be set. - **value** (bigint) - Required - The value to set. - **littleEndian** (boolean) - Optional - If false or undefined, a big-endian value should be written. ### Returns void ``` -------------------------------- ### Get File or Directory Stats Source: https://zenfs.dev/core/interfaces/index.AsyncFSMethods.html Retrieves metadata (like size, modification time) for a file or directory at the specified path. ```typescript stat(path: string): Promise> ``` -------------------------------- ### readySync Source: https://zenfs.dev/core/classes/index.PortFS.html Synchronously checks if the file system is ready. Returns void. ```APIDOC ## readySync(): void ### Description Synchronously checks if the file system is ready. ### Returns void ``` -------------------------------- ### ready Source: https://zenfs.dev/core/classes/index.PortFS.html Returns a Promise that resolves when the file system is ready. This is typically used to ensure all connections and initializations are complete before performing operations. ```APIDOC ## ready(): Promise ### Description Returns a Promise that resolves when the file system is ready. ### Returns Promise ``` -------------------------------- ### Get listeners for an event Source: https://zenfs.dev/core/classes/index.fs.WriteStream.html Retrieves a copy of the array of listeners for a specific event. Useful for inspecting or debugging event handlers. ```javascript server.on('connection', (stream) => { console.log('someone connected!'); }); console.log(util.inspect(server.listeners('connection'))); // Prints: [ [Function] ] ``` -------------------------------- ### Getting Registered Event Names Source: https://zenfs.dev/core/classes/index.fs.WriteStream.html Retrieves an array of all event names for which listeners are registered on an EventEmitter. Useful for introspection and debugging. ```javascript import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.on('foo', () => {}); myEE.on('bar', () => {}); const sym = Symbol('symbol'); myEE.on(sym, () => {}); console.log(myEE.eventNames()); // Prints: [ 'foo', 'bar', Symbol(symbol) ] ``` -------------------------------- ### createCredentials Source: https://zenfs.dev/core/functions/index.createCredentials.html Initializes and returns Credentials. It takes a CredentialsInit object as input and returns a Credentials object. ```APIDOC ## Function createCredentials ### Description Initializes and returns Credentials. It takes a CredentialsInit object as input and returns a Credentials object. ### Parameters #### source - **source** (CredentialsInit) - Required - The initialization object for credentials. ``` -------------------------------- ### getSync (Buffer or Undefined Encoding) Source: https://zenfs.dev/core/functions/index.fs.xattr.getSync.html Synchronously gets the value of an extended attribute. Returns a Uint8Array if encoding is 'buffer' or undefined. ```APIDOC ## Function getSync (Buffer or Undefined Encoding) ### Description Synchronously gets the value of an extended attribute. Returns a Uint8Array when encoding is 'buffer' or undefined. ### Signature ```typescript getSync( this: unknown, path: string, name: "system.${string}" | "user.${string}" | "trusted.${string}" | "security.${string}", opt?: Options & (BufferEncodingOption | { encoding?: null | undefined }) ): Uint8Array ``` ### Parameters * **this**: unknown * **path** (string): Path to the file * **name** (`system.${string}` | `user.${string}` | `trusted.${string}` | `security.${string}`): Name of the attribute to get * **opt** (Optional) `Options & (BufferEncodingOption | { encoding?: null | undefined })`: Options for the operation ### Returns * **Uint8Array**: A buffer containing the attribute value when encoding is 'buffer' or undefined. ``` -------------------------------- ### open Source: https://zenfs.dev/core/functions/index.vfs.sync.open.html Opens a file at the specified path with the given options and returns a handle to the file. ```APIDOC ## open ### Description Opens a file at the specified path with the given options and returns a handle to the file. ### Method open ### Parameters #### Path Parameters * **path** (PathLike) - Required - The path to the file to open. * **opt** (OpenOptions) - Required - Options for opening the file. #### Returns * **Handle** - A handle to the opened file. ``` -------------------------------- ### subarray Source: https://zenfs.dev/core/classes/index.MetadataBlock.html Gets a new Int32Array view of the ArrayBuffer store for this array, referencing the elements at begin, inclusive, up to end, exclusive. ```APIDOC ## subarray ### Description Gets a new Int32Array view of the ArrayBuffer store for this array, referencing the elements at begin, inclusive, up to end, exclusive. ### Parameters #### begin * `Optional`begin: number - The index of the beginning of the array. #### end * `Optional`end: number - The index of the end of the array. ### Returns * Int32Array ``` -------------------------------- ### mkdir Source: https://zenfs.dev/core/functions/index.vfs.mkdir.html Creates a directory at the specified path. The options parameter can be used to specify additional settings for directory creation. ```APIDOC ## mkdir ### Description Creates a directory at the specified path. The options parameter can be used to specify additional settings for directory creation. ### Signature ```typescript mkdir( this: unknown, path: PathLike, options?: MkdirOptions ): Promise ``` ### Parameters * **path** (`PathLike`) - The path of the directory to create. * **options** (`MkdirOptions`, optional) - An object containing options for directory creation. Defaults to `{}`. ``` -------------------------------- ### Capture Rejection Symbol Example Source: https://zenfs.dev/core/classes/index.fs.WriteStream.html Demonstrates how to use the captureRejectionSymbol to handle promise rejections when emitting events with captureRejections enabled. ```javascript import { EventEmitter, captureRejectionSymbol } from 'node:events'; class MyClass extends EventEmitter { constructor() { super({ captureRejections: true }); } [captureRejectionSymbol](err, event, ...args) { console.log('rejection happened for', event, 'with', err, ...args); this.destroy(err); } destroy(err) { // Tear the resource down here. } } ``` -------------------------------- ### readySync Source: https://zenfs.dev/core/classes/index.StoreFS.html Synchronously prepares the StoreFS for use. This method should be called before other operations. ```APIDOC ## readySync ### Description Synchronously prepares the StoreFS for use. This method should be called before performing other file system operations. ### Method (Synchronous) ### Returns void ``` -------------------------------- ### readv (with position) Source: https://zenfs.dev/core/functions/index.fs.readv.html Reads data from a file descriptor into multiple buffers starting from a specified position. This allows for non-sequential reads. ```APIDOC ## readv (with position) ### Description Reads data from a file descriptor into multiple buffers starting from a specified position. This allows for non-sequential reads. ### Signature ```typescript readv( this: unknown, fd: number, buffers: ArrayBufferView[], position: number, cb: readvCb ): void ``` ### Parameters * **fd** (number) - The file descriptor to read from. * **buffers** (ArrayBufferView[]) - An array of ArrayBufferViews to store the read data. * **position** (number) - The starting position within the file to begin reading. * **cb** (readvCb) - The callback function to be executed after the read operation completes. ``` -------------------------------- ### write Source: https://zenfs.dev/core/classes/index.PortFS.html Writes data from a buffer to a file asynchronously. The `start` and `end` parameters define the range of bytes to write from the buffer. ```APIDOC ## write(path: string, buffer: Uint8Array, start: number, end: number): Promise ### Description Writes data from a buffer to a file. ### Parameters * `path` (string): The path of the file to write to. * `buffer` (Uint8Array): The buffer containing the data to write. * `start` (number): The offset into the buffer to start writing from. * `end` (number): The position in the buffer to stop writing. ### Returns Promise ``` -------------------------------- ### mkdirSync Source: https://zenfs.dev/core/classes/index.FetchFS.html Synchronously creates a directory at the specified path with the given options. Returns the directory's InodeLike representation. ```APIDOC ## mkdirSync ### Description Synchronously creates a directory at the specified path with the given options. Returns the directory's InodeLike representation. ### Method POST ### Endpoint /mkdirSync ### Parameters #### Path Parameters * **path** (string) - Required - The path where the directory will be created. * **options** (CreationOptions) - Required - Options for directory creation. ### Returns InodeLike ``` -------------------------------- ### getSync Source: https://zenfs.dev/core/classes/index.AsyncTransaction.html Synchronously retrieves data from the store. This method is a synchronous counterpart to `get` and will throw an error if the key does not exist or an error occurs. ```APIDOC ## getSync(id: number, offset: number, end?: number) ### Description Retrieves data synchronously from the store. Throws an error if an error occurs or if the key does not exist. ### Parameters * **id** (number) - The key to look under for data. * **offset** (number) - The starting offset for retrieving data. * **end** (number) - Optional. The ending offset for retrieving data. ### Returns Uint8Array | undefined - The data stored under the key, or undefined if not present. ``` -------------------------------- ### opendir with options and callback Source: https://zenfs.dev/core/functions/index.fs.opendir.html Opens a directory with additional options and provides a callback with the directory handle. This allows for more granular control over how the directory is opened. ```APIDOC ## opendir(path, options, cb) ### Description Opens a directory at the specified path with the given options and calls the provided callback function with the directory handle upon success. ### Method N/A (SDK function) ### Parameters #### Path Parameters * **path** (PathLike) - Required - The path to the directory to open. * **options** (OpenDirOptions) - Required - An object containing options for opening the directory. * **cb** (Callback<[Dir]>) - Required - The callback function to execute with the directory handle. ### Returns void ``` -------------------------------- ### Configure ZenFS with Asynchronous Mounts Source: https://zenfs.dev/core/documents/Configuration.html Use this snippet to initialize ZenFS with multiple mounts, including asynchronous backends. Ensure all necessary imports are included. ```typescript import { configure, InMemory } from '@zenfs/core'; await configure({ mounts: { '/tmp': { backend: InMemory, label: 'temp-storage' }, }, }); ``` -------------------------------- ### stat Source: https://zenfs.dev/core/classes/index.PassthroughFS.html Gets file statistics asynchronously. This method takes the file path as a string argument and returns a Promise that resolves to InodeLike. ```APIDOC ## stat ### Description Gets file statistics asynchronously. ### Method Asynchronous ### Parameters #### Path Parameters - **path** (string) - Required - The path to the file. ### Returns Promise> ``` -------------------------------- ### mkdir Source: https://zenfs.dev/core/classes/index.FetchFS.html Asynchronously creates a directory at the specified path with the given options. Returns a Promise that resolves to the directory's InodeLike representation. ```APIDOC ## mkdir ### Description Asynchronously creates a directory at the specified path with the given options. Returns a Promise that resolves to the directory's InodeLike representation. ### Method POST ### Endpoint /mkdir ### Parameters #### Path Parameters * **path** (string) - Required - The path where the directory will be created. * **options** (CreationOptions) - Required - Options for directory creation. ### Returns Promise> ``` -------------------------------- ### Register and Use a Custom Device Driver Source: https://zenfs.dev/core/documents/Devices_and_Device_Drivers Shows how to add a custom device driver to ZenFS and write data to a custom device file. ```javascript import { addDevice, fs } from '@zenfs/core'; addDevice(customNullDevice); fs.writeFileSync('/dev/custom', 'This gets discarded.'); ```