def consume_remaining_buffer(stack, buf)
      return if buf.length == 0
      stack << buf.dup
      buf.replace('')
    end
def consume_remaining_buffer(stack, buf)
      return if buf.length == 0
      stack << buf.dup
      buf.replace('')
    end
If the passed buf contains any bytes, put them on the stack and
 empty the buffer