After you convert some text into series of integers, like 66|65|256
, you should not write it to a file as a series of 9 characters in text mode. You should open the output file in binary mode and write the numbers in binary (and not write seperation marks like |
at all).
In case of LZW there are two approaches: either you use fixed binary width, and thus limit the size of dictionary, or implement (a little bit harder) variable width version, in which each number uses as many binary digits as the NEXT free dictionary key.
Back to your example, 66|65|256|257|65|260|65
with fixed width of 9 bits gives you 7 * 9 = 63
bits, which is 8
bytes.