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

Divergence in the number of bytes read #4

Open
wsilverio opened this issue Jul 12, 2022 · 0 comments
Open

Divergence in the number of bytes read #4

wsilverio opened this issue Jul 12, 2022 · 0 comments

Comments

@wsilverio
Copy link

wsilverio commented Jul 12, 2022

I'm doing some tests with TinyDeflate, but I noticed a divergence in the number of bytes read.

In both cases I have the same gzip file loaded into a std::vector<uint8_t> (this approach is just for a proof of concept).

The code below returns 80275 bytes consumed:

std::vector<uint8_t> gzip_content{ /*...*/ };  // 80283 bytes
std::vector<uint8_t> bin_content;

auto result = Deflate(
    [&]() {
        static size_t i = 0;
        if (i < gzip_content.size())
            return (int)gzip_content[i++];
        return EOF;
    },
    [&](uint8_t data) { bin_content.push_back(data); },
    DeflateTrackBothSize{});

// result.first = 0
// result.second.first = 80275 (8 bytes less: chesksum + trailer ?)
// result.second.second = 221863
// bin_content is OK

However, the code below returns 81850 bytes consumed:

std::vector<uint8_t> gzip_content{ /*...*/ };  // 80283 bytes

size_t n = /* ... */;
uint8_t *bin_content = new uint8_t[n];

auto result = Deflate(
    (uint8_t *)gzip_content.data(),
    (uint8_t *)gzip_content.data() + gzip_content.size(),
    (uint8_t *)bin_content,
    (uint8_t *)bin_content + n,
    DeflateTrackBothSize{});

// result.first = 0
// result.second.first = 81850 (1567 bytes more)
// result.second.second = 221863
// bin_content is OK

Is this because of sentence (15)?

"This method is backtrackable, meaning that some bytes in the input may be read twice."

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

No branches or pull requests

1 participant