I’m not quite sure how easy it is to fetch the binary composition of a file, but suppose we have some file with this representation:
010011
We could make 2 arrays.
One which stores the position of the 0s:
[‘x’, ”, ‘x’, ‘x’, ”, ”]
And another which stores the position of the 1s (which is simply the opposite of the previous array):
[”, ‘x’, ”, ”, ‘x’, ‘x’]
Then we can persist these two arrays into a file, and voila?
I don’t know, is there something i’m not realizing?
I’m not an expert in compression, was just wondering if this would work.
8
The most compact possible representation of your arrays would be 1 bit per entry. You have two arrays, each of length 6. I.e. your compressed file is 6+6 bits long, while your original file is 6 bits long. This is an increase of 100%.
Also, as @jk pointed out in his comment: your second array is identical to your input data. The first array is identical to the inverse of your input data.
010011 # original
101100 010011 # 'compressed'
So, not only is your compressed data twice as long, it also contains an exact copy of the original data.
1