Exemplo n.º 1
0
Blob* File::slice(long long start,
                  long long end,
                  const String& contentType,
                  ExceptionState& exceptionState) const {
  if (isClosed()) {
    exceptionState.throwDOMException(InvalidStateError,
                                     "File has been closed.");
    return nullptr;
  }

  if (!m_hasBackingFile)
    return Blob::slice(start, end, contentType, exceptionState);

  // FIXME: This involves synchronous file operation. We need to figure out how
  // to make it asynchronous.
  long long size;
  double modificationTimeMS;
  captureSnapshot(size, modificationTimeMS);
  clampSliceOffsets(size, start, end);

  long long length = end - start;
  std::unique_ptr<BlobData> blobData = BlobData::create();
  blobData->setContentType(contentType);
  if (!m_fileSystemURL.isEmpty()) {
    blobData->appendFileSystemURL(m_fileSystemURL, start, length,
                                  modificationTimeMS / msPerSecond);
  } else {
    ASSERT(!m_path.isEmpty());
    blobData->appendFile(m_path, start, length,
                         modificationTimeMS / msPerSecond);
  }
  return Blob::create(BlobDataHandle::create(std::move(blobData), length));
}
Exemplo n.º 2
0
Blob* Blob::slice(long long start, long long end, const String& contentType, ExceptionState& exceptionState) const
{
    if (hasBeenClosed()) {
        exceptionState.throwDOMException(InvalidStateError, "Blob has been closed.");
        return nullptr;
    }

    long long size = this->size();
    clampSliceOffsets(size, start, end);

    long long length = end - start;
    OwnPtr<BlobData> blobData = BlobData::create();
    blobData->setContentType(contentType);
    blobData->appendBlob(m_blobDataHandle, start, length);
    return Blob::create(BlobDataHandle::create(blobData.release(), length));
}