How to use the blob-util.blobToArrayBuffer function in blob-util

To help you get started, we’ve selected a few blob-util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github signalapp / Signal-Desktop / js / modules / types / visual_attachment.js View on Github external
exports.makeVideoThumbnail = async ({
  size,
  videoObjectUrl,
  logger,
  contentType,
}) => {
  let screenshotObjectUrl;
  try {
    const blob = await exports.makeVideoScreenshot({
      objectUrl: videoObjectUrl,
      contentType,
      logger,
    });
    const data = await blobToArrayBuffer(blob);
    screenshotObjectUrl = arrayBufferToObjectURL({
      data,
      type: contentType,
    });

    // We need to wait for this, otherwise the finally below will run first
    const resultBlob = await exports.makeImageThumbnail({
      size,
      objectUrl: screenshotObjectUrl,
      contentType,
      logger,
    });

    return resultBlob;
  } finally {
    exports.revokeObjectUrl(screenshotObjectUrl);
github signalapp / Signal-Desktop / js / modules / types / attachment.js View on Github external
exports.autoOrientJPEG = async attachment => {
  if (!MIME.isJPEG(attachment.contentType)) {
    return attachment;
  }

  // If we haven't downloaded the attachment yet, we won't have the data
  if (!attachment.data) {
    return attachment;
  }

  const dataBlob = await arrayBufferToBlob(
    attachment.data,
    attachment.contentType
  );
  const newDataBlob = await dataURLToBlob(await autoOrientImage(dataBlob));
  const newDataArrayBuffer = await blobToArrayBuffer(newDataBlob);

  // IMPORTANT: We overwrite the existing `data` `ArrayBuffer` losing the original
  // image data. Ideally, we’d preserve the original image data for users who want to
  // retain it but due to reports of data loss, we don’t want to overburden IndexedDB
  // by potentially doubling stored image data.
  // See: https://github.com/signalapp/Signal-Desktop/issues/1589
  const newAttachment = Object.assign({}, attachment, {
    data: newDataArrayBuffer,
    size: newDataArrayBuffer.byteLength,
  });

  // `digest` is no longer valid for auto-oriented image data, so we discard it:
  delete newAttachment.digest;

  return newAttachment;
};
github WorldBrain / Memex / src / local-page / local-page.jsx View on Github external
async function showPage(pageId) {
    const page = await getPage({pageId, followRedirects: true})
    if (page._id !== pageId) {
        // Apparently getPage followed one or more redirects. Reload the viewer
        // with the resolved page's id in the ?page query.
        const location = new URL(window.location)
        location.searchParams.set('page', page._id)
        window.location = location
    }
    const timestamp = getTimestamp(page)

    // Read the html file from the database.
    const blob = await db.getAttachment(pageId, 'frozen-page.html')
    // We assume utf-8 encoding. TODO: read encoding from document.
    const html = new TextDecoder('utf-8').decode(await blobToArrayBuffer(blob))

    document.title = `📄 ${page.title}`

    const bar = (
        <div id="bar">
            <span id="description">
                
                Snapshot of
                <a style="{{margin:" href="{page.url}">
                    {shortUrl(page.url)}
                </a>
                
                <time datetime="{new">
                    {niceTime(timestamp)}
                </time>
            </span></div>