LZW has a predictable next data block size. So your encoder should save the number of bits required to save the current code. Your decoder should calculate the number of bits the next code could be and read that number of bits.
so your decoder would look something like
while (read next block){
read next block bits size
decode character block
update dictionary
next block bits size = dictionary next code bit size
}
Compression algorithms never work in the universal case. LZW is good for highly repeating data. With non repeating data the compressed data size will always be larger than the initial data size.