fast-fs-hash - v0.0.0-rc4
    Preparing search index...

    Class XxHash128Stream

    Streaming (incremental) and one-shot xxHash3-128 hasher.

    Streaming usage: create an instance, feed data via addBuffer, addString, addFile, etc., then call digest() to finalize.

    One-shot usage: call static methods like XxHash128Stream.digestBuffer(data) or XxHash128Stream.hash(input) directly.

    Busy guard: Async methods (addFile, addFiles, addFilesParallel) mark the instance as busy while the native worker is in flight. During this time, calling any synchronous method (addBuffer, addString, digest, reset, clone) or starting another async operation will throw. Check busy to inspect the state, or simply await each async call before invoking another method.

    // Streaming
    const h = new XxHash128Stream();
    h.addString("hello ");
    h.addBuffer(Buffer.from("world"));
    console.log(h.digest().toString("hex"));

    // One-shot
    const hash = XxHash128Stream.digestBuffer(myData);
    Index

    Constructors

    • Creates a new streaming hash instance with an optional 64-bit seed.

      Parameters

      • seedLow: number = 0

        Lower 32 bits of the 64-bit seed. Default: 0.

      • seedHigh: number = 0

        Upper 32 bits of the 64-bit seed. Default: 0.

      Returns XxHash128Stream

    Properties

    seedHigh: number

    Upper 32 bits of the 64-bit seed.

    seedLow: number

    Lower 32 bits of the 64-bit seed.

    Accessors

    • get busy(): boolean

      Returns true if an async operation (addFile, addFiles, addFilesParallel) is currently in flight. While busy, synchronous methods will throw.

      Returns boolean

    Methods

    • Feeds an entire binary buffer into the running hash state.

      Parameters

      • input: Uint8Array

        Binary data to feed.

      Returns void

    • Feeds a subrange of a binary buffer into the running hash state.

      Parameters

      • input: Uint8Array

        Binary data.

      • offset: number

        Starting byte offset.

      • Optionallength: number

        Number of bytes. If omitted, feeds to end of buffer.

      Returns void

    • Reads a single file and feeds its content into the running hash state. Marks the instance as busy until the returned promise settles.

      Parameters

      • path: string

        File path.

      • throwOnError: boolean = true

        If true (default), rejects on I/O error. If false, silently skips.

      Returns Promise<void>

      If the instance is already busy (an async operation is pending).

    • Reads multiple files sequentially and feeds each into the running hash state. Marks the instance as busy until the returned promise settles.

      Parameters

      • paths: readonly string[]

        Array of file paths.

      • throwOnError: boolean = true

        If true (default), rejects on I/O error. If false, silently skips.

      Returns Promise<void>

      If the instance is already busy (an async operation is pending).

    • Reads multiple files in parallel and feeds each into the running hash state. Marks the instance as busy until the returned promise settles.

      Per-file digests are computed in parallel and then fed into the stream in path-order.

      Parameters

      • paths: readonly string[]

        File paths.

      • concurrency: number = 0

        Max concurrent I/O lanes (0 = default, max 8).

      • throwOnError: boolean = true

        If true (default), rejects on I/O error. If false, unreadable files produce a zero hash.

      Returns Promise<void>

      If the instance is already busy (an async operation is pending).

    • Feeds a UTF-8 string into the running hash state.

      Parameters

      • input: string

        String to feed.

      Returns void

    • Finalizes and returns the current 128-bit digest. The internal state is not reset — calling digest() again without further feeds returns the same value.

      Returns Buffer

      A new 16-byte Buffer containing the digest.

    • Finalizes and writes the 128-bit digest into an existing output buffer.

      Type Parameters

      • TOut extends Uint8Array<ArrayBufferLike> = Buffer<ArrayBufferLike>

      Parameters

      • out: TOut

        Destination buffer (>= 16 writable bytes at outOffset).

      • OptionaloutOffset: number

        Byte offset in out. Default: 0.

      Returns TOut

      The out buffer for convenience.

    • Resets the internal hash state, discarding all previously fed data.

      Parameters

      • OptionalseedLow: number

        Lower 32 bits of the 64-bit seed. Default: the seed used at construction.

      • OptionalseedHigh: number

        Upper 32 bits of the 64-bit seed. Default: the seed used at construction.

      Returns void

    • Hashes an entire binary buffer and returns the 128-bit digest.

      Parameters

      • input: Uint8Array

        The buffer to hash.

      Returns Buffer

    • Hashes a sub-range of a binary buffer and returns the 128-bit digest.

      Parameters

      • input: Uint8Array

        The buffer to hash.

      • offset: number

        Start offset in bytes.

      • Optionallength: number

        Number of bytes to hash. Defaults to the rest of the buffer.

      Returns Buffer

    • Hashes a sub-range of a binary buffer and writes the digest into out.

      Type Parameters

      • TOut extends Uint8Array<ArrayBufferLike> = Buffer<ArrayBufferLike>

      Parameters

      • input: Uint8Array

        The buffer to hash.

      • offset: number

        Start offset in bytes.

      • length: number

        Number of bytes to hash.

      • out: TOut

        Destination buffer.

      • OptionaloutOffset: number

        Byte offset into out. Default 0.

      Returns TOut

    • Hashes an entire binary buffer and writes the digest into out.

      Type Parameters

      • TOut extends Uint8Array<ArrayBufferLike> = Buffer<ArrayBufferLike>

      Parameters

      • input: Uint8Array

        The buffer to hash.

      • out: TOut

        Destination buffer (must have at least 16 bytes from outOffset).

      • OptionaloutOffset: number

        Byte offset into out. Default 0.

      Returns TOut

    • Reads a file and returns its 128-bit content hash.

      Parameters

      • path: string

        File path.

      • OptionalthrowOnError: boolean

        If false, returns a zeroed digest on error. Default true.

      Returns Promise<Buffer<ArrayBufferLike>>

    • Reads multiple files in parallel and returns the aggregate 128-bit digest.

      Parameters

      • paths: readonly string[]

        Array of file paths.

      • concurrency: number = 0

        Max parallel reads. Default 8.

      • OptionalthrowOnError: boolean

        If false, skips unreadable files. Default true.

      Returns Promise<Buffer<ArrayBufferLike>>

    • Reads multiple files in parallel and writes the aggregate digest into out.

      Type Parameters

      • TOut extends Uint8Array<ArrayBufferLike>

      Parameters

      • paths: readonly string[]

        Array of file paths.

      • out: TOut

        Destination buffer.

      • OptionaloutOffset: number

        Byte offset into out. Default 0.

      • concurrency: number = 0

        Max parallel reads. Default 8.

      • OptionalthrowOnError: boolean

        If false, skips unreadable files. Default true.

      Returns Promise<TOut>

    • Reads multiple files sequentially and returns the aggregate 128-bit digest.

      Parameters

      • paths: readonly string[]

        Array of file paths.

      • OptionalthrowOnError: boolean

        If false, skips unreadable files. Default true.

      Returns Promise<Buffer<ArrayBufferLike>>

    • Reads multiple files sequentially and writes the aggregate digest into out.

      Type Parameters

      • TOut extends Uint8Array<ArrayBufferLike>

      Parameters

      • paths: readonly string[]

        Array of file paths.

      • out: TOut

        Destination buffer.

      • OptionaloutOffset: number

        Byte offset into out. Default 0.

      • OptionalthrowOnError: boolean

        If false, skips unreadable files. Default true.

      Returns Promise<TOut>

    • Reads a file and writes its 128-bit content hash into out.

      Type Parameters

      • TOut extends Uint8Array<ArrayBufferLike> = Buffer<ArrayBufferLike>

      Parameters

      • path: string

        File path.

      • out: TOut

        Destination buffer.

      • OptionaloutOffset: number

        Byte offset into out. Default 0.

      • OptionalthrowOnError: boolean

        If false, writes a zeroed digest on error. Default true.

      Returns Promise<TOut>

    • Hashes a UTF-8 string and returns the 128-bit digest.

      Parameters

      • input: string

        The string to hash.

      Returns Buffer

    • Hashes a UTF-8 string and writes the digest into out.

      Type Parameters

      • TOut extends Uint8Array<ArrayBufferLike> = Buffer<ArrayBufferLike>

      Parameters

      • input: string

        The string to hash.

      • out: TOut

        Destination buffer.

      • OptionaloutOffset: number

        Byte offset into out. Default 0.

      Returns TOut

    • One-shot: hash a buffer or string and return the 128-bit digest.

      Parameters

      • input: string | Uint8Array<ArrayBufferLike>

        Binary data or string to hash.

      Returns Buffer

      A new 16-byte Buffer containing the digest.