Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow users to get ZstdLayerWriter directly #30

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

tofay
Copy link
Collaborator

@tofay tofay commented Oct 1, 2024

... rather than wrapping in a tar builder. Apologies for missing this in #24

In rpmoci I'm wanting to give the user a choice of gzip or zstd compression. I want to create an enum like

enum LayerWriter<'a> {
    Gzip(ocidir::GzipLayerWriter<'a>),
    Zstd(ocidir::ZstdLayerWriter<'a>),
}

impl<'a> Write for LayerWriter<'a> {
    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
        match self {
            Self::Gzip(writer) => writer.write(buf),
            Self::Zstd(writer) => writer.write(buf),
        }
    }

    fn flush(&mut self) -> std::io::Result<()> {
        match self {
            Self::Gzip(writer) => writer.flush(),
            Self::Zstd(writer) => writer.flush(),
        }
    }
}

I'll then create a tar::Builder<LayerWriter<'a>>. But I can't currently create an ZstdLayerWriter.

Signed-off-by: Tom Fay <tomfay@microsoft.com>
examples/zstd.rs Outdated
@@ -5,31 +5,36 @@ fn main() {
use oci_spec::image::Platform;
use ocidir::{cap_std::fs::Dir, new_empty_manifest, OciDir};
let dir = Dir::open_ambient_dir(env::temp_dir(), ocidir::cap_std::ambient_authority()).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let dir = Dir::open_ambient_dir(env::temp_dir(), ocidir::cap_std::ambient_authority()).unwrap();
let dir = Dir::open_ambient_dir(env::temp_dir(), ocidir::cap_std::ambient_authority()).unwrap();
let tmpdir = "zstd-example";
dir.create_dir_all(tmpdir).unwrap();
let dir = dir.open_dir(tmpdir).unwrap();

I suggest creating a separate directory in /tmp for the oci directory, otherwise we end up with /tmp/index.json and /tmp/blobs/sha256.

Signed-off-by: Tom Fay <tomfay@microsoft.com>
@ariel-miculas ariel-miculas merged commit 111ed71 into containers:main Oct 4, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants