OCI Runtime, Image and Distribution Spec in Zig.
This library provides a convenient way to interact with the specifications defined by the Open Container Initiative (OCI).
Zig version >= 0.16
Fetch latest tagged release or lated build of oci-spec-zs master branch.
# Version of oci-spec-zig that works with a tagged release of Zig
# Replace `<REPLACE ME>` with the version of oci-spec-zig that you want to use
# See: https://github.com/navidys/oci-spec-zig/releases
zig fetch --save https://github.com/navidys/oci-spec-zig/archive/refs/tags/<REPLACE ME>.tar.gz
# oci-spec-zig latest build (master branch)
zig fetch --save git+https://github.com/navidys/oci-spec-zigThen add the following toe build.zig:
const ocispec = b.dependency("ocispec", .{});
exe.root_module.addImport("ocispec", ocispec.module("ocispec"));To explore additional examples, navigate to the examples/ directory.
const std = @import("std");
const ocispec = @import("ocispec");
const image = ocispec.image;
pub fn main(init: std.process.Init) !void {
const allocator = init.arena.allocator();
const media_manifest = image.MediaType.ImageManifest;
const media_config = image.MediaType.ImageConfig;
const media_layer = image.MediaType.ImageLayerGzip;
var mlayers: std.ArrayListUnmanaged(image.Descriptor) = .empty;
try mlayers.append(allocator, image.Descriptor{
.mediaType = media_layer,
.digest = try image.Digest.initFromString(
allocator,
"sha256:9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f",
),
.size = 32654,
});
const manifest_layers: []image.Descriptor = try mlayers.toOwnedSlice(allocator);
defer allocator.free(manifest_layers);
const manifest = image.Manifest{
.mediaType = media_manifest,
.config = image.Descriptor{
.mediaType = media_config,
.digest = try image.Digest.initFromString(
allocator,
"sha256:b5b2b2c507a0944348e0303114d8d93aaaa081732b86451d9bce1f432a537bc7",
),
.size = 7023,
},
.layers = manifest_layers,
};
const manifest_content = try manifest.toStringPretty(allocator);
defer allocator.free(manifest_content);
var write_buf: [4096]u8 = undefined;
var stdout_wrtiter = std.Io.File.stdout().writer(init.io, &write_buf);
const stdout = &stdout_wrtiter.interface;
try stdout.print("{s}\n", .{manifest_content});
stdout.flush() catch {};
}
Licensed under the MIT License.