https://github.com/navidys/oci-spec-zig
OCI Runtime, Image and Distribution Spec in Zig
https://github.com/navidys/oci-spec-zig
Last synced: 22 days ago
JSON representation
OCI Runtime, Image and Distribution Spec in Zig
- Host: GitHub
- URL: https://github.com/navidys/oci-spec-zig
- Owner: navidys
- License: mit
- Created: 2025-03-16T06:46:33.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2026-01-30T22:20:25.000Z (23 days ago)
- Last Synced: 2026-01-30T22:27:26.465Z (23 days ago)
- Language: Zig
- Size: 76.2 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Maintainers: MAINTAINERS.md
Awesome Lists containing this project
- awesome-zig - oci-spec-zig - OCI (Open Container Initiative) runtime, image and distribution spec in Zig. (Systems Programming / Emulators)
README


[](https://codecov.io/gh/navidys/oci-spec-zig)

[](https://github.com/zigcc/awesome-zig)
# oci-spec-zig
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)](https://opencontainers.org).
- [Image Format Specification](https://github.com/opencontainers/image-spec/blob/main/spec.md)
- [Runtime Specification](https://github.com/opencontainers/runtime-spec/blob/master/spec.md)
- [Distribution Specification](https://github.com/opencontainers/distribution-spec/blob/main/spec.md)
## Requirements
Zig version >= 0.14.1
## Installation
Fetch latest tagged release or lated build of oci-spec-zs master branch.
```shell
# Version of oci-spec-zig that works with a tagged release of Zig
# Replace `` 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/.tar.gz
# oci-spec-zig latest build (master branch)
zig fetch --save git+https://github.com/navidys/oci-spec-zig
```
Then add the following toe build.zig:
```shell
const ocispec = b.dependency("ocispec", .{});
exe.root_module.addImport("ocispec", ocispec.module("ocispec"));
```
## Example
To explore additional examples, navigate to the [examples/](./examples/) directory.
```shell
const std = @import("std");
const ocispec = @import("ocispec");
const image = ocispec.image;
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();
const media_manifest = image.MediaType.ImageManifest;
const media_config = image.MediaType.ImageConfig;
const media_layer = image.MediaType.ImageLayerGzip;
var mlayers = std.ArrayList(image.Descriptor).init(allocator);
try mlayers.append(image.Descriptor{
.mediaType = media_layer,
.digest = try image.Digest.initFromString(
allocator,
"sha256:9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f",
),
.size = 32654,
});
const manifest_layers: []image.Descriptor = try mlayers.toOwnedSlice();
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);
const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
try stdout.print("{s}\n", .{manifest_content});
try bw.flush();
}
```
## License
Licensed under the [MIT License](https://github.com/navidys/oci-spec-zig/blob/main/LICENSE).