Repository navigation
[io] Compress buffers larger than 16 MiB in blocks of equal size #23707
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,9 @@ | |
| *************************************************************************/ | ||
| #include "Compression.h" | ||
|
|
||
| #include <cassert> | ||
| #include <cstdint> | ||
|
|
||
| /** | ||
| * These are definitions of various free functions for the C-style compression routines in ROOT. | ||
| */ | ||
|
|
@@ -39,4 +42,26 @@ extern "C" int R__unzip_header(int *srcsize, const unsigned char *src, int *tgts | |
|
|
||
| enum { kMAXZIPBUF = 0xffffff }; // 16 MB | ||
|
|
||
| namespace ROOT::Internal { | ||
|
|
||
| /// Number and size of the blocks in which a buffer is compressed. | ||
| struct RZipBlocks { | ||
| int fNBlocks; | ||
| int fBlockSize; | ||
| }; | ||
|
|
||
| /// Number of blocks and the size of the blocks in which a buffer of `nbytes` > 0 bytes is compressed. | ||
| /// The buffer is cut into the fewest blocks of at most kMAXZIPBUF bytes, `1 + (nbytes - 1) / kMAXZIPBUF`, all | ||
| /// of the same size but the last, which is smaller by less than the number of blocks. Full blocks followed by | ||
| /// the remainder would end a buffer just above a multiple of kMAXZIPBUF in a block of a few bytes, which cannot | ||
| /// be compressed, so that the whole buffer would be stored uncompressed. | ||
| constexpr RZipBlocks GetZipBlocks(std::uint64_t nbytes) | ||
| { | ||
| assert(nbytes > 0); | ||
| const std::uint64_t nblocks = 1 + (nbytes - 1) / kMAXZIPBUF; | ||
| return RZipBlocks{static_cast<int>(nblocks), static_cast<int>((nbytes + nblocks - 1) / nblocks)}; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe let's add an
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I think it is better to change the |
||
| } | ||
|
|
||
| } // namespace ROOT::Internal | ||
|
|
||
| #endif | ||
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.