I was running a server that didn’t do log rotation, so when the log grew too big I had to truncate it. This left me with a sparse file with a bunch of 0s (null bytes) at the beginning.
To trim the null bytes, first find the offset of the first non-null byte. This can be done with some C:
I’m using an array to represent ranges of numbers. For example, in this array,
1
[1, 2, 3, 4, 15, 16, 17, 18]
there are two sequences of consequitive numbers: 1-4 and 15-18. In order to save space when serializing this array, it can be represented as ranges of numbers. For example:
1
[ [1, 4], [15, 18] ]
This function takes in an array of numbers, and returns an array of ranges: