int read(void* dst, int bytes) { assert(dst); if (m_nc == NULL) { return 0; } // ensure buf while (m_bufsize < m_position + bytes) { m_bufsize += 4096; m_buf = (Uint8*) realloc(m_buf, m_bufsize); } // not enough data in the buffer if (m_position + bytes > m_size) { int n = m_nc->read(m_buf + m_size, m_position + bytes - m_size); m_size += n; } int n = imin(bytes, m_size - m_position); memcpy(dst, m_buf + m_position, n); m_position += n; m_eof = n < bytes ? true : false; return n; }