Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!