void BlobResourceHandle::consumeData(const char* data, int bytesRead) { ASSERT(m_async); m_totalRemainingSize -= bytesRead; // Notify the client. if (bytesRead) notifyReceiveData(data, bytesRead); if (m_fileOpened) { // When the current item is a file item, the reading is completed only if bytesRead is 0. if (!bytesRead) { // Close the file. m_fileOpened = false; m_asyncStream->close(); // Move to the next item. m_readItemCount++; } } else { // Otherwise, we read the current text item as a whole and move to the next item. m_readItemCount++; } // Continue the reading. readAsync(); }
int BlobResourceHandle::readSync(char* buf, int length) { ASSERT(isMainThread()); ASSERT(!m_async); Ref<BlobResourceHandle> protect(*this); int offset = 0; int remaining = length; while (remaining) { // Do not continue if the request is aborted or an error occurs. if (m_aborted || m_errorCode) break; // If there is no more remaining data to read, we are done. if (!m_totalRemainingSize || m_readItemCount >= m_blobData->items().size()) break; const BlobDataItem& item = m_blobData->items().at(m_readItemCount); int bytesRead = 0; if (item.type == BlobDataItem::Data) bytesRead = readDataSync(item, buf + offset, remaining); else if (item.type == BlobDataItem::File) bytesRead = readFileSync(item, buf + offset, remaining); else ASSERT_NOT_REACHED(); if (bytesRead > 0) { offset += bytesRead; remaining -= bytesRead; } } int result; if (m_aborted || m_errorCode) result = -1; else result = length - remaining; if (result > 0) notifyReceiveData(buf, result); if (!result) notifyFinish(); return result; }