@zenfs/core
Version:
A filesystem, anywhere
168 lines (167 loc) • 5.94 kB
TypeScript
import type { ArrayOf } from 'memium';
import type { UUID } from 'node:crypto';
import { BufferView } from 'utilium/buffer';
import type { UsageInfo } from '../internal/filesystem.js';
import { StoreFS } from './store/fs.js';
import { SyncMapTransaction, type SyncMapStore } from './store/map.js';
import type { Store } from './store/store.js';
type Lock = Disposable & (() => void);
declare const MetadataEntry_base: import("memium").StructConstructor<BufferView<any>>;
declare class MetadataEntry extends MetadataEntry_base {
static name: string;
/** Inode or data ID */
accessor id: number;
/** Reserved for 64-bit offset expansion */
protected accessor offset_: number;
/** Offset into the buffer the data is stored at. */
accessor offset: number;
/** The size of the data */
accessor size: number;
toString(): string;
}
declare const MetadataBlock_base: import("memium/decorators").StructFromTypedArray<Int32Array<ArrayBuffer>>;
/**
* A block of metadata for a single-buffer file system.
* This metadata maps IDs (for inodes and data) to actual offsets in the buffer.
* This is done since IDs are not guaranteed to be sequential.
*/
export declare class MetadataBlock extends MetadataBlock_base<ArrayBufferLike> {
static name: string;
readonly ['constructor']: typeof MetadataBlock;
private static readonly lockIndex;
/**
* The crc32c checksum for the metadata block.
* @privateRemarks Keep this first!
*/
accessor checksum: number;
/** The (last) time this metadata block was updated */
accessor timestamp: bigint;
/** Offset to the previous metadata block */
accessor previous_offset: number;
protected _previous?: MetadataBlock;
get previous(): MetadataBlock | undefined;
/** Metadata entries. */
accessor items: ArrayOf<MetadataEntry>;
toString(long?: boolean): string;
/**
* If non-zero, this block is locked for writing.
* Note a int32 is used for `Atomics.wait`
*/
accessor locked: number;
/**
* Wait for the block to be unlocked.
*/
waitUnlocked(depth?: number): void;
lock(): Lock;
}
declare const SuperBlock_base: import("memium/decorators").StructFromTypedArray<BigUint64Array<ArrayBuffer>>;
/**
* The super block structure for a single-buffer file system
*/
export declare class SuperBlock extends SuperBlock_base<ArrayBufferLike> {
static name: string;
readonly ['constructor']: typeof SuperBlock;
constructor(...args: ConstructorParameters<typeof BigUint64Array<ArrayBufferLike>>);
/**
* The crc32c checksum for the super block.
* @privateRemarks Keep this first!
*/
accessor checksum: number;
/** Signature for the superblock. */
accessor magic: number;
/** The version of the on-disk format */
accessor version: number;
/** Which format of `Inode` is used */
accessor inode_format: number;
/** Flags for the file system. Currently unused */
accessor flags: number;
/** The number of used bytes, including the super block and metadata */
accessor used_bytes: bigint;
/** The total size of the entire file system, including the super block and metadata */
accessor total_bytes: bigint;
/** A UUID for this file system */
accessor uuid: Uint8Array;
/**
* The size in bytes of a metadata block.
* Not currently configurable.
*/
accessor metadata_block_size: number;
/** Reserved for 64-bit offset expansion */
protected accessor metadata_offset_: number;
/** Offset of the current metadata block */
accessor metadata_offset: number;
metadata: MetadataBlock;
/** An optional label for the file system */
accessor label: Uint8Array;
/** Padded to 256 bytes */
accessor _padding: Uint8Array;
/**
* Rotate out the current metadata block.
* Allocates a new metadata block, moves the current one to backup,
* and updates used_bytes accordingly.
* @returns the new metadata block
*/
rotateMetadata(): MetadataBlock;
/**
* Checks to see if `length` bytes are unused, starting at `offset`.
* @internal Not for external use!
*/
isUnused(offset: number, length: number): boolean;
}
/**
*
* @category Stores and Transactions
*/
export declare class SingleBufferStore extends BufferView implements SyncMapStore {
readonly flags: readonly [];
readonly name = "sbfs";
readonly type = 1935828595;
get uuid(): UUID;
protected superblock: SuperBlock;
/**
* @internal @hidden
*/
protected readonly _view: DataView;
protected readonly _u8: Uint8Array;
constructor(...args: ConstructorParameters<typeof BufferView>);
keys(): Iterable<number>;
get(id: number): Uint8Array | undefined;
set(id: number, data: Uint8Array): void;
delete(id: number): void;
protected _fs?: StoreFS<Store> | undefined;
get fs(): StoreFS<Store> | undefined;
set fs(fs: StoreFS<Store> | undefined);
sync(): Promise<void>;
usage(): UsageInfo;
transaction(): SyncMapTransaction;
}
/**
* Options for the `SingleBuffer` backend
* @category Backends and Configuration
*/
export interface SingleBufferOptions {
buffer: ArrayBufferLike | ArrayBufferView;
}
declare const _SingleBuffer: {
readonly name: "SingleBuffer";
readonly options: {
readonly buffer: {
readonly type: "object";
readonly required: true;
};
};
readonly create: (opt: SingleBufferOptions) => StoreFS<SingleBufferStore>;
};
type _SingleBuffer = typeof _SingleBuffer;
/**
* A backend that uses a single buffer for storing data
* @category Backends and Configuration
*/
export interface SingleBuffer extends _SingleBuffer {
}
/**
* A backend that uses a single buffer for storing data
* @category Backends and Configuration
*/
export declare const SingleBuffer: SingleBuffer;
export {};