question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resolve toBuffer Promise with an array (was: When using promises, how do you get image info)

See original GitHub issue

if a callback is used with toBuffer for example the image info is passed to the callback, how do you get this info when using a promise ?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:3
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
lovellcommented, Feb 9, 2017

@Vispercept The data and info attributes “returned” by toBuffer are highly related to each other; info contains properties computed whilst processing the final output image. Perhaps you’re thinking of the existing metadata call to access input image info?

Rather than the Promise resolving with an Array, how about resolving with an Object, which would allow for destructuring e.g.:

sharp(input)
  .resize(123)
  .toBuffer({ resolveWithObject: true })
  .then( ({ data, info }) => {
    ...
  });
2reactions
lovellcommented, Mar 4, 2017

Commit 6fe5b30 adds the new resolveWithObject option to toBuffer. This will be in v0.17.3.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get the index of the Promise returned by Promise.any ...
I 've tried finding the index by comparing each promise of the array to the one returned by Promise.any , but that didn't...
Read more >
Promise.resolve() - JavaScript - MDN Web Docs
The Promise.resolve() method "resolves" a given value to a Promise. If the value is a promise, that promise is returned; if the value...
Read more >
Processing images with sharp in Node.js - LogRocket Blog
sharp is a high-performance image processing module for Node.js. ... We use the metadata() function to extract the image metadata.
Read more >
Input metadata - High performance Node.js image processing
Fast access to (uncached) image metadata without decoding any compressed pixel data. This is taken from the header of the input image. It...
Read more >
JavaScript Promise Tutorial – How to Resolve or Reject ...
We will use the PokeAPI to get information about Pokémon and resolve/reject them using Promises. First, let us create a generic function that ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found