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

Return stream instance synchronously #82

Open
TheLudd opened this issue Sep 26, 2014 · 3 comments
Open

Return stream instance synchronously #82

TheLudd opened this issue Sep 26, 2014 · 3 comments

Comments

@TheLudd
Copy link

TheLudd commented Sep 26, 2014

In the documentation, this is declared:

var webshot = require('webshot');
var fs      = require('fs');

webshot('google.com', function(err, renderStream) {
  var file = fs.createWriteStream('google.png', {encoding: 'binary'});

  renderStream.on('data', function(data) {
    file.write(data.toString('binary'), 'binary');
  });
});

The stream instance is returned asynchronously. Why is this? Should the code not look like this?

var webshot = require('webshot');
var fs      = require('fs');
var file = fs.createWriteStream('google.png', {encoding: 'binary'});

var renderStream = webshot('google.com');
renderStream.pipe(file);
@Wizek
Copy link

Wizek commented Sep 26, 2014

👍

@lukepolo
Copy link

Its because it spins up a instance of phantom

@OleMchls
Copy link

I stumbled upon this today as well, if i understand the code correctly returning the writable stream sync should not a problem

cb(null, s);
should be

cb(null, s);
return s;

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

No branches or pull requests

4 participants