/////////////////////////////////////////////////////////// // // Return the specified number of bytes from the stream // /////////////////////////////////////////////////////////// void streamReader::read(imbxUint8* pBuffer, imbxUint32 bufferLength) { while(bufferLength != 0) { // Update the data buffer if it is empty /////////////////////////////////////////////////////////// if(m_pDataBufferCurrent == m_pDataBufferEnd) { // EOF? /////////////////////////////////////////////////////////// if(fillDataBuffer() == 0) { throw(streamExceptionEOF("Attempt to read past the end of the file")); } } // Copy the available data into the return buffer /////////////////////////////////////////////////////////// imbxUint32 copySize = bufferLength; imbxUint32 maxSize = (imbxUint32)(m_pDataBufferEnd - m_pDataBufferCurrent); if(copySize > maxSize) { copySize = maxSize; } ::memcpy(pBuffer, m_pDataBufferCurrent, (size_t)copySize); bufferLength -= copySize; pBuffer += copySize; m_pDataBufferCurrent += copySize; } }
/////////////////////////////////////////////////////////// // // Return the specified number of bytes from the stream // /////////////////////////////////////////////////////////// void streamReader::read(imbxUint8* pBuffer, imbxUint32 bufferLength) { while(bufferLength != 0) { // Update the data buffer if it is empty /////////////////////////////////////////////////////////// if(m_pDataBufferCurrent == m_pDataBufferEnd) { if(bufferLength >= m_pDataBufferMaxEnd - m_pDataBufferStart) { // read the data directly into the destination buffer /////////////////////////////////////////////////////////// imbxUint32 readBytes(fillDataBuffer(pBuffer, bufferLength)); m_pDataBufferCurrent = m_pDataBufferEnd = m_pDataBufferStart; m_dataBufferStreamPosition += readBytes; pBuffer += readBytes; bufferLength -= readBytes; if(readBytes == 0) { throw(streamExceptionEOF("Attempt to read past the end of the file")); } continue; } if(fillDataBuffer() == 0) { throw(streamExceptionEOF("Attempt to read past the end of the file")); } } // Copy the available data into the return buffer /////////////////////////////////////////////////////////// imbxUint32 copySize = bufferLength; imbxUint32 maxSize = (imbxUint32)(m_pDataBufferEnd - m_pDataBufferCurrent); if(copySize > maxSize) { copySize = maxSize; } ::memcpy(pBuffer, m_pDataBufferCurrent, (size_t)copySize); bufferLength -= copySize; pBuffer += copySize; m_pDataBufferCurrent += copySize; } }