Last change
on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
583 bytes
|
Line | |
---|
1 | var fs = require('fs'),
|
---|
2 | needle = require('./..'),
|
---|
3 | path = require('path');
|
---|
4 |
|
---|
5 | var url = process.argv[2] || 'https://upload.wikimedia.org/wikipedia/commons/a/af/Tux.png';
|
---|
6 | var file = path.basename(url);
|
---|
7 |
|
---|
8 | console.log('Downloading ' + file);
|
---|
9 |
|
---|
10 | needle.get(url, { output: file, follow: 3 }, function(err, resp, data){
|
---|
11 | console.log('File saved: ' + process.cwd() + '/' + file);
|
---|
12 |
|
---|
13 | var size = fs.statSync(file).size;
|
---|
14 | if (size == resp.bytes)
|
---|
15 | console.log(resp.bytes + ' bytes written to file.');
|
---|
16 | else
|
---|
17 | throw new Error('File size mismatch: ' + size + ' != ' + resp.bytes);
|
---|
18 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.