From 885b135348e2c227a124349d53470ab7594d9c22 Mon Sep 17 00:00:00 2001 From: tforbus Date: Sat, 14 Sep 2013 22:20:00 -0500 Subject: [PATCH] Put callback on an event from the file stream --- README.md | 6 +++--- screenshot.js | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7c63f01..2b5ec31 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ You can also clone this repository into your `node_modules` directory. var snapito = require('screenshot'); var screenshot = new snapito('yourapikey'); -screenshot.screenshot('http://www.google.com', 'google.png', {screen: 'desktop'}, function(file){ +screenshot.screenshot('http://www.google.com', 'google.png', {screen: 'desktop'}).on('close', function(file){ if (file) { console.log('The file ' + file + ' was written correctly'); } else { @@ -49,8 +49,8 @@ call to Snapito. Here is a list of them: var snapito = require('screenshot'); var screenshot = new snapito('yourapikey'); -// screenshot.screenshot(url, file, options, callback) -screenshot.screenshot('http://www.google.com', 'google.png', {screen: 'desktop'}, function(file){ +// screenshot.screenshot(url, file, options).on('event', callback) +screenshot.screenshot('http://www.google.com', 'google.png', {screen: 'desktop'}).on('close', function(file){ if (file) { console.log('The file ' + file + ' was written correctly'); } else { diff --git a/screenshot.js b/screenshot.js index 437488b..e8a3e9e 100644 --- a/screenshot.js +++ b/screenshot.js @@ -71,7 +71,9 @@ Screenshot.prototype.screenshot = function(url, file, options, callback) { options += params_string; // Send request - request(options).pipe(fs.createWriteStream(file)); + var fileStream = fs.createWriteStream(file); + request(options).pipe(fileStream); + return fileStream }; module.exports = Screenshot; \ No newline at end of file