Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda