Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Binary

A read-only binary value with support for binary deltas.

Values are effectively immutable. Instances can be backed by user-supplied buffers. Once a Binary has been constructed around a buffer, care must be taken not to modify the data in the buffer because doing so would violate immutability.

since

5.7

Hierarchy

Index

Methods

apply

  • Apply a delta to this Binary value to create a new value.

    Convenient equivalent to: diffusion.datatypes.binary().deltaSupport(delta).apply(this, delta);

    throws

    an error if the delta is invalid

    Parameters

    • delta: BinaryDelta

      the binary delta to apply to this value

    Returns Binary

    a new instance derived from applying the delta to this value

asBuffer

  • asBuffer(): Buffer
  • Get a copy of the buffer containing this value.

    Returns Buffer

    This value in binary form

copyTo

  • copyTo(target: Buffer, offset?: undefined | number): void
  • Copy the binary data to a provided buffer.

    When running the Diffusion Client in a browser context, access to the Buffer api is made available through diffusion.buffer.

    Parameters

    • target: Buffer

      the buffer to copy data to

    • Optional offset: undefined | number

      the position in the target buffer at which data will be copied

    Returns void

diff

  • Compare this Binary value with an earlier version to create a delta.

    Convenient equivalent to: diffusion.datatypes.binary().deltaSupport(type).diff(original, this);

    Buffers may also be provided as the value to diff instead of a Binary instance. When running the Diffusion Client in a browser context, access to the Buffer api is made available through diffusion.buffer.

    Example:

    var delta = binaryValue.diff(Buffer.from('Hello world'));

    Parameters

    • original: Binary | Buffer

      the value to diff against this

    • Optional type: undefined | string

      the type of delta to generate (default: binary);

    Returns BinaryDelta

    a delta representing the difference between this and the provided value

get

  • get(): Buffer
  • Get the value as a Buffer.

    Returns Buffer

    the buffer value

length

  • length(): number
  • Get the number of bytes

    Returns number

    The length of the data in bytes