int BlobResourceHandle::readFileSync(const BlobDataItem& item, char* buf, int length) { ASSERT(isMainThread()); ASSERT(!m_async); if (!m_fileOpened) { long long bytesToRead = m_itemLengthList[m_readItemCount] - m_currentItemReadSize; if (bytesToRead > m_totalRemainingSize) bytesToRead = m_totalRemainingSize; bool success = m_stream->openForRead(item.file()->path(), item.offset() + m_currentItemReadSize, bytesToRead); m_currentItemReadSize = 0; if (!success) { m_errorCode = notReadableError; return 0; } m_fileOpened = true; } int bytesRead = m_stream->read(buf, length); if (bytesRead < 0) { m_errorCode = notReadableError; return 0; } if (!bytesRead) { m_stream->close(); m_fileOpened = false; m_readItemCount++; } else m_totalRemainingSize -= bytesRead; return bytesRead; }
void NetworkDataTaskBlob::readFile(const BlobDataItem& item) { ASSERT(m_stream); if (m_fileOpened) { m_stream->read(m_buffer.data(), m_buffer.size()); return; } long long bytesToRead = m_itemLengthList[m_readItemCount] - m_currentItemReadSize; if (bytesToRead > m_totalRemainingSize) bytesToRead = static_cast<int>(m_totalRemainingSize); m_stream->openForRead(item.file()->path(), item.offset() + m_currentItemReadSize, bytesToRead); m_fileOpened = true; m_currentItemReadSize = 0; }
void BlobResourceHandle::readFileAsync(const BlobDataItem& item) { ASSERT(isMainThread()); ASSERT(m_async); if (m_fileOpened) { m_asyncStream->read(m_buffer.data(), m_buffer.size()); return; } long long bytesToRead = m_itemLengthList[m_readItemCount] - m_currentItemReadSize; if (bytesToRead > m_totalRemainingSize) bytesToRead = static_cast<int>(m_totalRemainingSize); m_asyncStream->openForRead(item.file()->path(), item.offset() + m_currentItemReadSize, bytesToRead); m_fileOpened = true; m_currentItemReadSize = 0; }