% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/write_metadata.R
\name{zarr_consolidate_metadata}
\alias{zarr_consolidate_metadata}
\title{Consolidate Zarr metadata files into a single file}
\usage{
zarr_consolidate_metadata(
  zarr_store_path,
  s3_client = NULL,
  action = c("write", "return"),
  overwrite = TRUE
)
}
\arguments{
\item{zarr_store_path}{A character vector of length 1. This provides the path to a Zarr store.}

\item{s3_client}{A list representing an S3 client.  This should be produced
by \code{\link[paws.storage:s3]{paws.storage::s3()}}.}

\item{action}{A character string specifying the action to take with the consolidated metadata.
If \code{"write"} (the default), the consolidated metadata will be written back to the Zarr store.
If \code{"return"}, the consolidated metadata will be returned as a list without writing it back to the store.
The latter is particularly useful for non-writable stores.}

\item{overwrite}{A logical value (default \code{TRUE}) indicating whether to overwrite existing
consolidated metadata when \code{action} is \code{"write"}. If \code{FALSE} and consolidated metadata
already exists, an error will be raised.}
}
\value{
If \code{action} is \code{"return"}, a list containing the consolidated metadata.
Otherwise, the function is called for its side effect and \code{NULL} is returned invisibly.
}
\description{
This function reads all the metadata files in a Zarr store and consolidates them into a single file.
Thanks to this, a single request can be made to retrieve all the elements and their related metadata for a Zarr store,
which is especially beneficial for remote stores like S3.
}
\examples{
# v2
zarr_v2 <- withr::local_tempfile(fileext = ".zarr")
dir.create(zarr_v2)
jsonlite::write_json(
  list("zarr_format" = 2L),
  file.path(zarr_v2, ".zgroup")
)
write_zarr_array(
  array(1:4, dim = c(2, 2)),
  file.path(zarr_v2, "array1"),
  chunk_dim = c(1, 2),
  zarr_version = 2L
)
write_zarr_array(
  array(c(3.14, 42.42, 12.96, 7.89), dim = c(2, 2)),
  file.path(zarr_v2, "array2"),
  chunk_dim = c(1, 2),
  zarr_version = 2L
)
write_zarr_attributes(
 file.path(zarr_v2, "array1"),
 list(description = "This is array 1")
)
zarr_consolidate_metadata(zarr_v2, action = "return")

zarr_consolidate_metadata(zarr_v2, action = "write")
zarr_overview(zarr_v2)

}
