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

add support for zstd layers #24

Merged
merged 2 commits into from
Sep 30, 2024
Merged

add support for zstd layers #24

merged 2 commits into from
Sep 30, 2024

Conversation

tofay
Copy link
Collaborator

@tofay tofay commented Sep 25, 2024

for reference in #23

- zstd multi-threaded compression supported behind `zstdmt` feature

Signed-off-by: Tom Fay <tomfay@microsoft.com>
Copy link
Collaborator

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

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

Looks sane to me, glad you made it an optional feature.

It's kind of tempting for the next semver break to make gzip optional too and just make it more obvious/easy how to plug in a custom compressor + set mime type; basically you just pass us an impl Write and the desired mime type right?


#[cfg(feature = "zstd")]
/// Wraps a writer and calculates the sha256 digest of data written to the inner writer
struct Sha256Writer<W> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm this could be factored out and reused for gzip too right?

Copy link
Collaborator Author

@tofay tofay Sep 26, 2024

Choose a reason for hiding this comment

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

yes, done. didn't do it for blobwriter since that also determines the size (and I thought adding a SizeWriter that keeps track of data size, and making blobwriter have a SizeWriter or similar was too much!)

@ariel-miculas
Copy link
Collaborator

It's kind of tempting for the next semver break to make gzip optional too and just make it more obvious/easy how to plug in a custom compressor + set mime type; basically you just pass us an impl Write and the desired mime type right?

Maybe this could serve as inspiration:
https://github.com/project-machine/puzzlefs/blob/master/puzzlefs-lib/src/oci.rs#L55

@cgwalters
Copy link
Collaborator

Maybe this could serve as inspiration:
https://github.com/project-machine/puzzlefs/blob/master/puzzlefs-lib/src/oci.rs#L55

Code looks good, but we never need to decompress in this library, right? So I think that simplifies our needs.

There's an argument actually that tar is also something that should be made into an optional feature itself - it's just a convenience sugar really here.

@tofay
Copy link
Collaborator Author

tofay commented Sep 26, 2024

basically you just pass us an impl Write and the desired mime type right?

Since encoders typically wrap an underlying writer, the user could tell us how to make an impl Write from a blobwriter, so they can wrap that writer.
We'd also need to know how to get the blobwriter back on completion.

So we could have:

/// A writer that can be finalized to return an inner writer.
pub trait WriteComplete<W>: Write {
    fn complete(self) -> std::io::Result<W>;
}

...

impl Ocidir {
    pub fn create_generic_layer<W: WriteComplete>(
        &self,
        create: impl FnOnce(BlobWriter) -> W,
        media_type: MediaType,
    ) -> Result<GenericLayerWriter<W>> {
todo()!
    }

Edit: I pushed an example tofay@af68ed7 that removes zstd/gzip layer writers

Signed-off-by: Tom Fay <tomfay@microsoft.com>
@tofay tofay marked this pull request as ready for review September 26, 2024 14:48
Comment on lines +748 to +749
let len = self.inner.write(buf)?;
self.sha.update(&buf[..len]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah you know what, this is clearly better code than what it replaces. We need to handle short writes, and I think that's what I messed up in the original.

@cgwalters cgwalters merged commit a5f5bfe into containers:main Sep 30, 2024
3 checks passed
@cgwalters
Copy link
Collaborator

Edit: I pushed an example tofay/ocidir-rs@af68ed7 that removes zstd/gzip layer writers

I think this is an interesting idea for sure...worth putting up a PR for discussion?

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.

3 participants