fgb-vt - v1.0.6
    Preparing search index...

    Class LocalConnector

    Local filesystem connector using Node.js FileHandle with LRU pooling.

    Opens FGB files on demand and caches the resulting FileHandle in an LRU map. Subsequent reads against the same path reuse the cached handle, avoiding repeated open() syscalls; concurrent first reads of a path share a single open(). When the pool exceeds LocalConnectorOptions.maxOpenFiles, least-recently-used handles that no read is using are evicted and closed. Handles in use are never closed underneath a read, so the limit is soft while every handle is busy.

    import { LocalConnector } from '@geozelot/fgb-vt';

    const connector = new LocalConnector({ maxOpenFiles: 128 });

    // Read 1024 bytes starting at offset 0
    const bytes = await connector.read('./data/buildings.fgb', 0, 1024);

    // Clean up when done
    await connector.close();

    Implements

    Index
    cacheNamespace: string = ...

    Paths name files on this machine, relative ones from the working directory.

    hints: ConnectorHints = ...

    Local reads are cheap: merge only near-adjacent ranges, read a modest prefix.

    • Close all pooled file handles and clear the LRU pool.

      Idle handles are closed immediately; handles still in use by in-flight reads are closed as soon as those reads finish. A later read reopens its file, so calling close() repeatedly is safe.

      Returns Promise<void>

      Resolves when every idle handle has been closed.

    • Read a contiguous byte range from a local file.

      The file handle is obtained from the LRU pool (or opened on first access). The returned Uint8Array may be shorter than length if the file is smaller than offset + length.

      With ReadOptions.ifMatch, the version tag (inode, size and modification time) is checked first, both of the file the read goes through and of the file now at path.

      Parameters

      • path: string

        Absolute or relative filesystem path to the FGB file.

      • offset: number

        Zero-based byte offset to begin reading from.

      • length: number

        Number of bytes to read.

      • Optionaloptions: ReadOptions

        Optional version check and abort signal.

      Returns Promise<Uint8Array<ArrayBufferLike>>

      The requested byte range.

      If the file cannot be opened or read (status 404 for ENOENT, 403 for EACCES/EPERM).

      If ifMatch no longer matches the file.

      If offset or length is negative or not an integer.

    • Read the first length bytes of a file together with its size and version tag (inode, size and modification time).

      If the file at path was replaced since its handle was pooled, the stale handle is dropped first, so bytes and metadata always describe the same file.

      Parameters

      • path: string

        Absolute or relative filesystem path to the FGB file.

      • length: number

        Number of leading bytes to read.

      • Optionaloptions: ReadOptions

        Optional abort signal.

      Returns Promise<ReadHeadResult>

      The leading bytes plus size and version tag.

    • Read multiple byte ranges from the same local file in parallel.

      All ranges are dispatched concurrently via Promise.all, letting the OS I/O scheduler optimize disk access order.

      Parameters

      • path: string

        Absolute or relative filesystem path to the FGB file.

      • ranges: readonly { length: number; offset: number }[]

        Array of { offset, length } byte-range descriptors.

      • Optionaloptions: ReadOptions

        Optional version check (performed once) and abort signal.

      Returns Promise<Uint8Array<ArrayBufferLike>[]>

      Array of Uint8Array chunks in the same order as the input ranges.

      If the file cannot be opened or any individual read fails.

      If ifMatch no longer matches the file.