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

Exposed deflateSetDictionary and inflateSetDictionary functionality when using zlib #74

Merged
merged 7 commits into from
Mar 19, 2018
Merged

Conversation

Lukazoid
Copy link
Contributor

@Lukazoid Lukazoid commented Apr 3, 2017

The functionality is currently only available when using the Compress and Decompress types, deciding upon a usable API for the IO types requires a fair bit more thought and may be something to consider in future.

@alexcrichton
Copy link
Member

Thanks for the PR!

I'm somewhat wary about making this zlib only, but it seems fundamentally incompatible (or unimplemented) with miniz, so in that sense seems fine!

Would it be possible to avoid extending the error enum for now? That way we could land this immediately, otherwise it'll need to wait until 1.0

@RReverser
Copy link
Contributor

I'd love to have access to dictionary API too. @alexcrichton is your question still the primary blocker of this PR? @Lukazoid do you mind either updating it or may I use your branch as base for a new PR?

@alexcrichton
Copy link
Member

@RReverser ah yeah now that this crate has hit 1.0 it'd need to be added in a backwards-compatible fashion, but I'd still be ok landing!

@oyvindln
Copy link
Contributor

It should be relatively simple to add support for this in the rust back-end later as well.

@RReverser
Copy link
Contributor

@alexcrichton To clarify: by "backwards-compatible fashion" you mean that extending Status enum is considered non-backward-compatible, is that correct?

If so, do you mind if I make this part of DecompressError - it's opaque so I guess changing internal () to enum and exposing something like err.needs_dictionary() -> Option<u32> should be fine?

@alexcrichton
Copy link
Member

@RReverser yeah, but exposing it as an error sounds great!

@Lukazoid
Copy link
Contributor Author

Lukazoid commented Mar 19, 2018

Sorry I never got back to you when I originally made this PR @alexcrichton. If @RReverser hasn't implemented this functionality already, I can make those changes (remove the added Status enum member and add a needs_dictionary function to DecompressError) later today.

@RReverser
Copy link
Contributor

@Lukazoid I haven't gotten to it either (beyond some local changes to bring it up-to-date with master), so feel free to update your PR - that's even better.

src/mem.rs Outdated
ffi::inflateSetDictionary(stream, dictionary.as_ptr(), dictionary.len() as ffi::uInt)
};

assert_eq!(rc, ffi::MZ_OK);
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking it would be better to return Result<u32, DecompressError> from this function so that error in case of incorrect dictionary or in case of calling set_dictionary at incorrect time (it has to be called only immediately after Z_NEED_DICT) could be still handled gracefully.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe I originally implemented these methods before flate2 returned Result and simply had asserts against MZ_OK.

Returning an actual Result is definitely better, I assume it's safe to presume the adler code will already be populated from a previous call to inflate. So if inflateSetDictionary works without error I can return that.

src/mem.rs Outdated
ffi::deflateSetDictionary(stream, dictionary.as_ptr(), dictionary.len() as ffi::uInt)
};

assert_eq!(rc, ffi::MZ_OK);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe return Result at least as Result<u32, ()>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As above, I think I was following the old style with assertions. I will make this change this evening.

@alexcrichton alexcrichton merged commit 993c788 into rust-lang:master Mar 19, 2018
@alexcrichton
Copy link
Member

This looks awesome, thanks so much @Lukazoid!

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.

4 participants