Gnat.Jetstream.API.Object (gnat v1.18.1)

View Source

API for interacting with the JetStream Object Store

Learn more about Object Store: https://docs.nats.io/nats-concepts/jetstream/obj_store

Summary

Functions

Streams an object's chunks through chunk_fun and verifies its size and SHA-256 digest.

Returns true if the provided stream is an Object bucket, false otherwise

Lists object metadata in a bucket.

Returns a list of all Object buckets

Types

bucket_opt()

@type bucket_opt() ::
  {:description, String.t()}
  | {:max_bucket_size, integer()}
  | {:max_chunk_size, integer()}
  | {:placement, Gnat.Jetstream.API.Stream.placement()}
  | {:replicas, non_neg_integer()}
  | {:storage, :file | :memory}
  | {:ttl, non_neg_integer()}

list_option()

@type list_option() ::
  {:show_deleted, boolean()}
  | {:timeout, non_neg_integer()}
  | {:total_timeout, non_neg_integer() | :infinity}

Functions

create_bucket(conn, bucket_name, params \\ [])

@spec create_bucket(Gnat.t(), String.t(), [bucket_opt()]) ::
  {:ok, Gnat.Jetstream.API.Stream.info()} | {:error, any()}

delete(conn, bucket_name, object_name)

@spec delete(Gnat.t(), String.t(), String.t()) :: :ok | {:error, any()}

delete_bucket(conn, bucket_name)

@spec delete_bucket(Gnat.t(), String.t()) :: :ok | {:error, any()}

get(conn, bucket_name, object_name, chunk_fun, opts \\ [])

@spec get(Gnat.t(), String.t(), String.t(), (binary() -> any()), keyword()) ::
  :ok | {:error, any()}

Streams an object's chunks through chunk_fun and verifies its size and SHA-256 digest.

Chunks reach the callback before the final integrity check. Treat the result as unverified until this function returns :ok. Callback exceptions propagate after subscription and consumer cleanup is attempted.

Options

  • :timeout - (non-negative integer) the maximum wait for each object chunk, in milliseconds. The wait restarts after each data callback returns. Heartbeats and flow-control messages don't restart it. Defaults to 10_000.

  • :total_timeout - (non-negative integer or :infinity) the total receive deadline, in milliseconds, starting after consumer creation. Each wait is limited by both this deadline and :timeout. Callback time counts toward the deadline, but callbacks aren't interrupted. Defaults to :infinity.

info(conn, bucket_name, object_name)

@spec info(Gnat.t(), String.t(), String.t()) ::
  {:ok, Gnat.Jetstream.API.Object.Meta.t()} | {:error, any()}

is_object_bucket_stream?(stream_name)

@spec is_object_bucket_stream?(stream_name :: binary()) :: boolean()

Returns true if the provided stream is an Object bucket, false otherwise

Parameters

  • stream_name - the stream name to test

list(conn, bucket_name, options \\ [])

@spec list(Gnat.t(), String.t(), [list_option()]) ::
  {:error, any()} | {:ok, [Gnat.Jetstream.API.Object.Meta.t()]}

Lists object metadata in a bucket.

Options

  • :show_deleted - (boolean) whether to include deleted objects in the result. Defaults to false.

  • :timeout - (non-negative integer) the maximum wait for each object's metadata, in milliseconds. The wait restarts after each metadata message. Heartbeats and flow-control messages don't restart it. Defaults to 10_000.

  • :total_timeout - (non-negative integer or :infinity) the total receive deadline, in milliseconds, starting after consumer creation. Each wait is limited by both this deadline and :timeout. Defaults to :infinity.

list_buckets(conn)

@spec list_buckets(conn :: Gnat.t()) :: {:error, term()} | {:ok, [String.t()]}

Returns a list of all Object buckets

put(conn, bucket_name, object_name, io)

@spec put(Gnat.t(), String.t(), String.t(), File.io_device()) ::
  {:ok, Gnat.Jetstream.API.Object.Meta.t()} | {:error, any()}