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

123
Visualizações
Checking stream byteLength never resolves on some images

I'm new to streams, and I'm trying to check for stream length before uploading it to s3. It's not that efficient, but performance is not an issue at the moment.

The below code works fine for many images, but for one specific image it stops at the bytelength validation.

//using graphql-upload
const { createReadStream, filename, encoding, mimetype } = file;
  const stream: ReadStream = createReadStream();

  const validationStream = stream.pipe(new Stream.PassThrough());
  const uploadStream = stream.pipe(new Stream.PassThrough());

  try {
    debugConsoleLog("File upload begun"); //Ok
    //... extension validation
    //... mime validation

    debugConsoleLog("Type check good"); //Ok

    let byteLength = 0;
    for await (const uploadChunk of validationStream) {
      debugConsoleLog(byteLength); // prints 0 once, never prints again
      byteLength += (uploadChunk as Buffer).byteLength;
    }
    debugConsoleLog("Counted byteSize"); //Never called

    //... Check if size is too big and upload //Never called

  } catch (err) {
    console.log(err);
    throw err;
  } finally {
    stream.destroy();
    validationStream.destroy();
    uploadStream.destroy();
  }

The image that doesn't work is a snapshot of a mac touchbar. Not that anyone will upload it, but it shows that some images are getting permanently stuck in the processing code.

Snapshot of mac touchbar that wont upload

There is something wrong in this part of the code for that image. How can I prevent the endless processing at this file if something is wrong with the image.

    let byteLength = 0;
    for await (const uploadChunk of validationStream) {
      debugConsoleLog(byteLength); // prints 0 once, never prints again
      byteLength += (uploadChunk as Buffer).byteLength;
    }

Please tell if you need more info about the stream in question! Thank you.

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