Bytes class

An immutable object representing an array of bytes.

Signature:

export declare class Bytes 

Methods

Method Modifiers Description
fromBase64String(base64) static Creates a new Bytes object from the given Base64 string, converting it to bytes.
fromJSON(json) static Builds a Bytes instance from a JSON object created by Bytes.toJSON().
fromUint8Array(array) static Creates a new Bytes object from the given Uint8Array.
isEqual(other) Returns true if this Bytes object is equal to the provided one.
toBase64() Returns the underlying bytes as a Base64-encoded string.
toJSON() Returns a JSON-serializable representation of this Bytes instance.
toString() Returns a string representation of the Bytes object.
toUint8Array() Returns the underlying bytes in a new Uint8Array.

Bytes.fromBase64String()

Creates a new Bytes object from the given Base64 string, converting it to bytes.

Signature:

static fromBase64String(base64: string): Bytes;

Parameters

Parameter Type Description
base64 string The Base64 string used to create the Bytes object.

Returns:

Bytes

Bytes.fromJSON()

Builds a Bytes instance from a JSON object created by Bytes.toJSON().

Signature:

static fromJSON(json: object): Bytes;

Parameters

Parameter Type Description
json object a JSON object represention of a Bytes instance

Returns:

Bytes

an instance of Bytes if the JSON object could be parsed. Throws a FirestoreError if an error occurs.

Bytes.fromUint8Array()

Creates a new Bytes object from the given Uint8Array.

Signature:

static fromUint8Array(array: Uint8Array): Bytes;

Parameters

Parameter Type Description
array Uint8Array The Uint8Array used to create the Bytes object.

Returns:

Bytes

Bytes.isEqual()

Returns true if this Bytes object is equal to the provided one.

Signature:

isEqual(other: Bytes): boolean;

Parameters

Parameter Type Description
other Bytes The Bytes object to compare against.

Returns:

boolean

true if this Bytes object is equal to the provided one.

Bytes.toBase64()

Returns the underlying bytes as a Base64-encoded string.

Signature:

toBase64(): string;

Returns:

string

The Base64-encoded string created from the Bytes object.

Bytes.toJSON()

Returns a JSON-serializable representation of this Bytes instance.

Signature:

toJSON(): object;

Returns:

object

a JSON representation of this object.

Bytes.toString()

Returns a string representation of the Bytes object.

Signature:

toString(): string;

Returns:

string

A string representation of the Bytes object.

Bytes.toUint8Array()

Returns the underlying bytes in a new Uint8Array.

Signature:

toUint8Array(): Uint8Array;

Returns:

Uint8Array

The Uint8Array created from the Bytes object.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-06-30 UTC.