-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
- zstd multi-threaded compression supported behind `zstdmt` feature Signed-off-by: Tom Fay <tomfay@microsoft.com>
There was a problem hiding this 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> { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!)
Maybe this could serve as inspiration: |
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 |
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. 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>
let len = self.inner.write(buf)?; | ||
self.sha.update(&buf[..len]); |
There was a problem hiding this comment.
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.
I think this is an interesting idea for sure...worth putting up a PR for discussion? |
for reference in #23