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

feat(zip): enable ZipOuputStream to write precompressed files #683

Merged
merged 7 commits into from Nov 17, 2021

Conversation

Temtaime
Copy link
Contributor

@Temtaime Temtaime commented Nov 2, 2021

I certify that I own, and have sufficient rights to contribute, all source code and related material intended to be compiled or integrated with the source code for the SharpZipLib open source product (the "Contribution"). My Contribution is licensed under the MIT License.

@piksel piksel changed the title Fix #682 Enable ZipOuputStream to write precompressed files Nov 2, 2021
@piksel piksel linked an issue Nov 2, 2021 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Nov 2, 2021

Codecov Report

Merging #683 (2e05458) into master (612969e) will increase coverage by 0.02%.
The diff coverage is 90.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #683      +/-   ##
==========================================
+ Coverage   73.79%   73.82%   +0.02%     
==========================================
  Files          68       68              
  Lines        8332     8353      +21     
==========================================
+ Hits         6149     6167      +18     
- Misses       2183     2186       +3     
Impacted Files Coverage Δ
src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs 87.77% <90.00%> (-0.18%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 612969e...2e05458. Read the comment docs.

Copy link
Member

@piksel piksel left a comment

Choose a reason for hiding this comment

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

I really think this needs to be more of an explicit opt-in, especially since it would be a breaking change otherwise.
Perhaps adding a PutNextPassthroughEntry or something similar that sets the flag and then calls PutNextEntry.
Also, perhaps naming the flag entryNeedsUpdating more clearly states why certain blocks are skipped?

@@ -313,6 +313,8 @@ internal void PutNextEntry(Stream stream, ZipEntry entry, long streamOffset = 0)
throw new InvalidOperationException("The Password property must be set before AES encrypted entries can be added");
}

entryIsPrecompressed = string.IsNullOrEmpty(Password) && method == CompressionMethod.Deflated && entry.Size >= 0 && entry.HasCrc && entry.CompressedSize >= 0;
Copy link
Member

Choose a reason for hiding this comment

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

This seems really volatile (and there are no tests for this).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there any way user can know compressed size and crc? Compressed size could be changed because of compression level or simply compressor logic change. So i think no one will pass it and expect that it will match internal deflator deflated size. Except if user wants to pass its own data

Copy link
Member

Choose a reason for hiding this comment

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

So i think no one will pass it and expect

We can't consider this a non-breaking change just because it would seem illogical to use it in this way.
It's still the fact that code that put something in those properties for any reason (copying an entry object from another file, serialization, left-over code?) would suddenly stop working. At least it would throw an exception, but it's change of behavior which would warrant a new major release if done this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is already broken because any fixes in compression engine will make the code fail as compressed size will differ.
Anyway, i got the point and reworked the PR

src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs Outdated Show resolved Hide resolved
@Temtaime
Copy link
Contributor Author

Temtaime commented Nov 8, 2021

Fixed failed test.
Rerun the pipeline please.
Is there anything else to fix/modify ?

@piksel piksel self-assigned this Nov 9, 2021
allowing other compression methods that are not implemented inside sharpziplib itself could be a good future use case for this. "not implemented" better conveys that it might be supported in the future.
@piksel
Copy link
Member

piksel commented Nov 17, 2021

I added some tests for the uncovered parts (and moved them to it's own file) in a PR to to your branch to get past the coverage check.

@Temtaime
Copy link
Contributor Author

Temtaime commented Nov 17, 2021

Sorry, totally missed it
Thank you very much

@piksel piksel changed the title Enable ZipOuputStream to write precompressed files feat(zip): enable ZipOuputStream to write precompressed files Nov 17, 2021
@piksel piksel merged commit ff64d0a into icsharpcode:master Nov 17, 2021
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.

ZipOuputStream does not support writing custom entries
2 participants