Fix bug in wrap()

Oversight where length in characters was used instead of number of bytes
when encoded.