2 ms·
Ok, then what if we save some space for the single bit indicator (compressed/non compressed) by following a simple algorithm: 1. Look for at least two as long
by nuccy 5y ago
Ok, then what if we save some space for the single bit indicator (compressed/non compressed) by following a simple algorithm:
1. Look for at least two as long as possible identical peaces with arbitrary bit offset from the beginning.
2. Record value and length (common for all peaces) and offsets for each peace.
3. Create and prepend a header with following fields:
compressed_flag, piece length, pieces count, piece value, pieces offsets list, content
Obviously if the file is very small this approach will not work. But assuming that we know the file size (which is the loophole here), we can pre-calculate which is a threshold file size to consider to be with a header, and what is too short so uncompressed headerless content is being saved there.
P.S. To remove the loophole possibility the streams of data should be rather considered instead of files.