copy last byte from writers
fix copying of length and codes. add checking of code
add writing of header
unget last byte
copy last byte