Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer issue #37

Closed
Swatto opened this issue May 23, 2014 · 4 comments
Closed

Buffer issue #37

Swatto opened this issue May 23, 2014 · 4 comments
Labels

Comments

@Swatto
Copy link

Swatto commented May 23, 2014

I'm using Knox to download an image on S3 and I'm stocking data in a buffer and place it in sharp constructor method.

res.setEncoding('binary');
var output = new Buffer('', 'binary');
res.on('data', function(chunck){
  output.write(chunck);
});
res.on('end', function(){
  callback(output, false);
});
// ...
sharp(rawImg)
  .resize(target.size, target.size)
  .toBuffer(function(err, image){
    if(err){
      console.log(err);
    }
    callback(image);
  });

But I have an error in the callback : Unsupported input file undefined
The buffer is not corrupted : if I output it with buffer.toString() as an express response, the image is displayed.

Do you have any idea guys ?

@lovell
Copy link
Owner

lovell commented May 23, 2014

Hi Gaël, it hard to tell from this snippet what rawImg contains.

The sharp constructor can handle a native string (=filename) or Buffer object.

What does typeof rawImg and rawImg instanceof Buffer return?

@lovell lovell added the triage label May 23, 2014
@Swatto
Copy link
Author

Swatto commented May 27, 2014

the rawImg instanceof Buffer returns true. I think it's this line message.

@lovell
Copy link
Owner

lovell commented May 27, 2014

Thanks @Swatto, this could happen if the Buffer is empty. What does rawImg.length return?

@Swatto
Copy link
Author

Swatto commented Jun 2, 2014

Yeah it was that stupid thing...

Sorry guys and great project !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants