Skip to main content
Version: 1.1.0

Client

The Client type provides methods for pushing and pulling files to OCI registries.

Creating a Client

NewClient

func NewClient(opts ...ClientOption) (*Client, error)

Creates a new blobber client.

Parameters:

NameTypeDescription
opts...ClientOptionConfiguration options

Returns:

TypeDescription
*ClientThe configured client
errorError if configuration fails

Example:

client, err := blobber.NewClient()
if err != nil {
log.Fatal(err)
}

With options:

client, err := blobber.NewClient(
blobber.WithInsecure(true),
blobber.WithLogger(slog.Default()),
)

Methods

Push

func (c *Client) Push(ctx context.Context, ref string, src fs.FS, opts ...PushOption) (string, error)

Uploads files to an OCI registry.

Parameters:

NameTypeDescription
ctxcontext.ContextContext for cancellation
refstringImage reference (e.g., ghcr.io/org/repo:tag)
srcfs.FSFilesystem to upload
opts...PushOptionPush options

Returns:

TypeDescription
stringManifest digest (e.g., sha256:abc...)
errorError if push fails

Example:

digest, err := client.Push(ctx, "ghcr.io/org/config:v1", os.DirFS("./config"))

With options:

digest, err := client.Push(ctx, ref, files,
blobber.WithCompression(blobber.ZstdCompression()),
blobber.WithAnnotations(map[string]string{
"org.opencontainers.image.source": "https://github.com/org/repo",
}),
)

Pull

func (c *Client) Pull(ctx context.Context, ref, destDir string, opts ...PullOption) error

Downloads all files from an image to a local directory.

Parameters:

NameTypeDescription
ctxcontext.ContextContext for cancellation
refstringImage reference
destDirstringDestination directory (created if needed)
opts...PullOptionPull options

Returns:

TypeDescription
errorError if pull fails

Example:

err := client.Pull(ctx, "ghcr.io/org/config:v1", "./output")

With extraction limits:

err := client.Pull(ctx, ref, "./output",
blobber.WithExtractLimits(blobber.ExtractLimits{
MaxFiles: 1000,
MaxTotalSize: 100 * 1024 * 1024, // 100MB
}),
)

OpenImage

func (c *Client) OpenImage(ctx context.Context, ref string) (*Image, error)

Opens a remote image for reading without downloading the full blob.

Parameters:

NameTypeDescription
ctxcontext.ContextContext for cancellation
refstringImage reference

Returns:

TypeDescription
*ImageHandle for reading files
errorError if open fails

Example:

img, err := client.OpenImage(ctx, "ghcr.io/org/config:v1")
if err != nil {
return err
}
defer img.Close()

entries, err := img.List()

See Also

  • Image - Reading files from opened images
  • Options - Client and operation options
  • Errors - Error handling