The RLE (Run length encoding) compression method compresses a file by writing repeated data as a byte containing the length, then a byte of the data itself. The 'real' RLE method involves writing control bytes. The first bit says whether the following data is compressed or uncompressed. The remaining bits control the length. For example
1, 1, 2, 3, 3, 4, 1, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6
compresses like this:
8 (8 + 0 for uncompressed bit), 1, 1, 2, 3, 3, 4, 1, 5, 13 (12 + 1 for compressed bit), 6 -> which is a control byte suggesting an uncompressed run of 8 numbers then a control byte suggesting a compressed run of 12 6's
This snippet is a simplified version which just reads bytes 'on the fly' and writes a byte pair - frequency first then the character. It has more wastage as it will try to compress everything (so 1, 2, 3 becomes 1, 1, 1 ,2, 1, 3) but is useful for long repeated sections (6,6, 6, 6 becomes 4, 6)