Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
Concat blobs to store them in a single Cache entry, and then retrieve them

I need to download an heavy file from the network, this file is then processed client-side and it results in a list of File entities.

Right now I'm using the Cache API to make sure downloading the same file doesn't need to go through the network again, but this requires my code to always process the cached file locally to obtain the list of files.

I'd like, instead, to store in cache the output of the process operation so that subsequent accesses don't require to process the single file to generate the multiple output files.

The problem I'm having is that I need a way to concat multiple File (or Blob?) entities into a single Blob that can then be added to my cache.

Below is the code I'm using right now, which doesn't handle the caching of the processed file:

async function getFile(url) {
  const cache = await caches.open('V1');
  
  const cached = await caches.match(url);
  if (cached != null) {
    return cached;
  }

  const response = await fetch(url, {
    credentials: 'include',
  });

  if (!response.ok) {
    throw new TypeError('bad response status');
  }

  await cache.put(url, response);

  return cache.match(url);
}

const download = await getFile('https://example.org/big.tar.gz');
const downloadArrayBuffer = await download.arrayBuffer();

// I'd like the cache to contain the output of the following operation
const files = await untar(downloadArrayBuffer);
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda