During the debugging phase of my personal version of ZPAQ I ran into a problem.
The existence of "holes", that is, sequences of zero bytes that ZPAQ does not store and does not restore.
So I have to calculate the CRC-32 of "virtual" blocks to calculate the correct CRC
Example
unsigned char allzeros[1000000];
memset(allzeros,0,sizeof(allzeros));
(...)
if ((g_crc32[i].crc32start+g_crc32[i].crc32size) != (g_crc32[i+1].crc32start))
{
printf("############################## HOUSTON WE HAVE AN HOLE %d %d\n",i,g_crc32.size());
printf("Start %08ld\n",g_crc32[i].crc32start);
printf("Size %08ld\n",g_crc32[i].crc32size);
printf("End %08ld\n",g_crc32[i].crc32start+g_crc32[i].crc32size);
printf("Next %08ld\n",g_crc32[i+1].crc32start);
uint64_t holestart=g_crc32[i].crc32start+g_crc32[i].crc32size;
printf("Start %08ld\n",holestart);
uint64_t holesize=g_crc32[i+1].crc32start-(g_crc32[i].crc32start+g_crc32[i].crc32size);
printf("Size %08ld\n",holesize);
uint32_t zerocrc;
zerocrc=crc32_16bytes (allzeros,(uint32_t)holesize); <<<======= very quick, very dirty
printf("zero %08X\n",zerocrc);
currentcrc32=crc32_combine(currentcrc32, zerocrc,(uint32_t)holesize);
In this first development approach I brutally allocate a vector of a million characters, zeroed, on which I take the CRC32 for the length I need (obviously it's just a skeleton).
For example, given a
3.536.704 bytes file (mysql.exe)
ZPAQ create some fragments
24/12/2020 18:34 2.050.374 globals_00000000000000_00000002050374_791FBF21
24/12/2020 18:34 497.149 globals_00000002091717_00000002588866_4514DF59
24/12/2020 18:34 306.965 globals_00000002630209_00000002937174_56B179E2
24/12/2020 18:34 558.187 globals_00000002978517_00000003536704_19F30641
... but some "padding" (virtual 0s chunk) may be needed,
in this case 3x41.343 bytes
24/12/2020 18:34 2.050.374 globals_00000000000000_00000002050374_791FBF21
24/12/2020 18:34 41.343 globals_00000002050374_00000002091717_448030DD_zero
24/12/2020 18:34 497.149 globals_00000002091717_00000002588866_4514DF59
24/12/2020 18:34 41.343 globals_00000002588866_00000002630209_448030DD_zero
24/12/2020 18:34 306.965 globals_00000002630209_00000002937174_56B179E2
24/12/2020 18:34 41.343 globals_00000002937174_00000002978517_448030DD_zero
24/12/2020 18:34 558.187 globals_00000002978517_00000003536704_19F30641
Is there a (quick) function calc_crc32_of_a_zero_block_of_length_n?
uint32_t crczero(uint32_t N)
{
unsigned char allzeros[1000000];
memset(allzeros,0,sizeof(allzeros)); ==>> I know, I know...
uint32_t=crc32(allzeros,N);
}
Thank you