Vector<char>& BlobBuilder::getBuffer() { // If the last item is not a data item, create one. Otherwise, we simply append the new string to the last data item. if (m_items.isEmpty() || m_items[m_items.size() - 1].type != BlobDataItem::Data) m_items.append(BlobDataItem(RawData::create())); return *m_items[m_items.size() - 1].data->mutableData(); }
void BlobBuilder::append(Blob* blob) { if (blob->isFile()) { // If the blob is file that is not snapshoted, capture the snapshot now. // FIXME: This involves synchronous file operation. We need to figure out how to make it asynchronous. File* file = static_cast<File*>(blob); long long snapshotSize; double snapshotModificationTime; file->captureSnapshot(snapshotSize, snapshotModificationTime); m_size += snapshotSize; m_items.append(BlobDataItem(file->path(), 0, snapshotSize, snapshotModificationTime)); } else { long long blobSize = static_cast<long long>(blob->size()); m_size += blobSize; m_items.append(BlobDataItem(blob->url(), 0, blobSize)); } }
PassRefPtr<Blob> BlobBuilder::getBlob(const String& contentType) { OwnPtr<BlobData> blobData = BlobData::create(); blobData->setContentType(contentType); blobData->swapItems(m_items); RefPtr<Blob> blob = Blob::create(blobData.release(), m_size); // After creating a blob from the current blob data, we do not need to keep the data around any more. Instead, we only // need to keep a reference to the URL of the blob just created. m_items.append(BlobDataItem(blob->url(), 0, m_size)); return blob; }
void BlobData::appendBlob(const KURL& url, long long offset, long long length) { m_items.append(BlobDataItem(url, offset, length)); }
void BlobData::appendFile(const String& path, long long offset, long long length, double expectedModificationTime) { m_items.append(BlobDataItem(path, offset, length, expectedModificationTime)); }
void BlobData::appendFile(const String& path) { m_items.append(BlobDataItem(path)); }
void BlobData::appendData(PassRefPtr<RawData> data, long long offset, long long length) { m_items.append(BlobDataItem(data, offset, length)); }
void BlobData::appendData(const CString& data, long long offset, long long length) { m_items.append(BlobDataItem(data, offset, length)); }
void BlobData::appendData(const CString& data) { m_items.append(BlobDataItem(data)); }