@wolfpld That code has the right idea, but I went a little further. For my own uses, I did away with the "safe" part and require the output buffer to be 8 bytes larger than required to allow writing past the end. A small speed bump, but I only wrote it for myself.