summaryrefslogtreecommitdiff
path: root/node_modules/needle/examples/stream-to-file.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/needle/examples/stream-to-file.js')
-rw-r--r--node_modules/needle/examples/stream-to-file.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/node_modules/needle/examples/stream-to-file.js b/node_modules/needle/examples/stream-to-file.js
new file mode 100644
index 0000000..d261bee
--- /dev/null
+++ b/node_modules/needle/examples/stream-to-file.js
@@ -0,0 +1,14 @@
+var fs = require('fs'),
+ needle = require('./..'),
+ path = require('path');
+
+var url = process.argv[2] || 'http://www.google.com/images/errors/robot.png';
+var file = path.basename(url);
+
+console.log('Downloading ' + file + '...');
+needle
+ .get(url)
+ .pipe(fs.createWriteStream(file))
+ .on('done', function() {
+ console.log('Done!')
+ })