Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# node-wget

A download tool, now supporting http/https resource and http/https proxy, written in nodejs.
Forked from https://github.com/wuchengwei/node-wget

# Installing
```
npm install wget
npm install mfx-wget
```

# Usage
Expand All @@ -13,7 +14,7 @@ npm install wget
## download(src, output, options)

```js
var wget = require('wget');
var wget = require('mfx-wget');
var src = 'https://raw.github.com/Fyrd/caniuse/master/data.json';
var output = '/tmp/data.json';
var options = {
Expand All @@ -24,6 +25,7 @@ download.on('error', function(err) {
console.log(err);
});
download.on('end', function(output) {
// output is { name: filename, size: fileSize }
console.log(output);
});
download.on('progress', function(progress) {
Expand Down
7 changes: 4 additions & 3 deletions lib/wget.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function download(src, output, options) {
protocol: srcUrl.protocol,
host: srcUrl.hostname,
port: srcUrl.port,
path: srcUrl.pathname,
path: srcUrl.path || srcUrl.pathname,
proxy: options?options.proxy:undefined,
method: 'GET'
}, function(res) {
Expand All @@ -33,7 +33,8 @@ function download(src, output, options) {
downloadedSize = 0;
fileSize = res.headers['content-length'];
writeStream = fs.createWriteStream(output, {
flags: 'a',
//flags: 'a',
flags: 'w',
encoding: 'binary'
});

Expand All @@ -50,7 +51,7 @@ function download(src, output, options) {
writeStream.end();
});
writeStream.on('close', function(){
downloader.emit('end', output);
downloader.emit('end', { name: output, size: fileSize } );
});
} else {
downloader.emit('error', 'Server respond ' + res.statusCode);
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "wget",
"version": "0.0.1",
"name": "mfx-wget",
"version": "0.0.4",
"description": "wget in nodejs.",
"keywords": ["download", "http", "https", "ftp", "proxy"],
"author": "Chengwei Wu <meegodevelop@gmail.com>",
"author": "Marco Foschian <marco.foschian@gmail.com>",
"repository":{
"type": "git",
"url": "git://github.com/wuchengwei/node-wget.git"
"url": "https://github.com/mfoschian/node-wget.git"
},
"main": "./index.js",
"bin": {
Expand Down
5 changes: 3 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
var wget = require('../lib/wget');

var download = wget.download('https://raw.github.com/Fyrd/caniuse/master/data.json', '/tmp/README.md');
var download = wget.download('http://www.google.com', 'google.html');
// with a proxy:
// var download = wget.download('https://raw.github.com/Fyrd/caniuse/master/data.json', '/tmp/README.md', {proxy: 'http://proxyhost:port'});
//var download = wget.download('http://www.google.com', 'google.html', {proxy: 'http://proxyhost:port'});

download.on('error', function(err) {
console.log(err);
});
Expand Down