Make sure buffer is offset correctly when written to stream