Function randomFillSync

  • Synchronous version of randomFill.

    import { Buffer } from 'buffer';
    const { randomFillSync } = await import('crypto');

    const buf = Buffer.alloc(10);
    console.log(randomFillSync(buf).toString('hex'));

    randomFillSync(buf, 5);
    console.log(buf.toString('hex'));

    // The above is equivalent to the following:
    randomFillSync(buf, 5, 5);
    console.log(buf.toString('hex'));

    Any ArrayBuffer, TypedArray or DataView instance may be passed asbuffer.

    import { Buffer } from 'buffer';
    const { randomFillSync } = await import('crypto');

    const a = new Uint32Array(10);
    console.log(Buffer.from(randomFillSync(a).buffer,
    a.byteOffset, a.byteLength).toString('hex'));

    const b = new DataView(new ArrayBuffer(10));
    console.log(Buffer.from(randomFillSync(b).buffer,
    b.byteOffset, b.byteLength).toString('hex'));

    const c = new ArrayBuffer(10);
    console.log(Buffer.from(randomFillSync(c)).toString('hex'));

    Returns

    The object passed as buffer argument.

    Type Parameters

    • T extends ArrayBufferView

    Parameters

    • buffer: T

      Must be supplied. The size of the provided buffer must not be larger than 2**31 - 1.

    • Optional offset: number
    • Optional size: number

    Returns T

  • Synchronous version of randomFill.

    import { Buffer } from 'buffer';
    const { randomFillSync } = await import('crypto');

    const buf = Buffer.alloc(10);
    console.log(randomFillSync(buf).toString('hex'));

    randomFillSync(buf, 5);
    console.log(buf.toString('hex'));

    // The above is equivalent to the following:
    randomFillSync(buf, 5, 5);
    console.log(buf.toString('hex'));

    Any ArrayBuffer, TypedArray or DataView instance may be passed asbuffer.

    import { Buffer } from 'buffer';
    const { randomFillSync } = await import('crypto');

    const a = new Uint32Array(10);
    console.log(Buffer.from(randomFillSync(a).buffer,
    a.byteOffset, a.byteLength).toString('hex'));

    const b = new DataView(new ArrayBuffer(10));
    console.log(Buffer.from(randomFillSync(b).buffer,
    b.byteOffset, b.byteLength).toString('hex'));

    const c = new ArrayBuffer(10);
    console.log(Buffer.from(randomFillSync(c)).toString('hex'));

    Returns

    The object passed as buffer argument.

    Type Parameters

    • T extends ArrayBufferView

    Parameters

    • buffer: T

      Must be supplied. The size of the provided buffer must not be larger than 2**31 - 1.

    • Optional offset: number
    • Optional size: number

    Returns T

Generated using TypeDoc