Skip to content

Commit

Permalink
File size redirect upgrades (#12)
Browse files Browse the repository at this point in the history
* Added a test server and new test for append vs write (#5)

* Added new test express server that serves a random binary file

* Added test to not append file

* Upgraded to version 2.0.0 (#6)

* Integrate circle (#7)

* Added test command, added circle.yml

* Switched filesize to a number, added handleing of unknown filesizes instead of returning NAN

* 1) added redirect tests
2) added infinite redirect tests
3) filesize is now a number instead of a string
4) No longer returns NaN if the server does not send a content length
	a) If there is no content length, the "filesize" will be set to 10^length(numberofdownloadedbytes)
	b) this will make progress bars continue to work, but they may jump between 0-99% multiple times
5) Added file size tests

* Formatting

* Added handling of unspecified content length
  • Loading branch information
bearjaws authored May 20, 2018
1 parent 90b338b commit 32d2f8c
Show file tree
Hide file tree
Showing 9 changed files with 1,018 additions and 122 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store
node_modules
.idea
coverage
.nyc_output
37 changes: 25 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
wget-improved simplifies retrieving files from any URL

Improvements over [wuchengwei/node-wget](https://github.com/wuchengwei/node-wget)
- Handles 302 redirects (including infinite redirect loops)
- Handles 3xx redirects (including infinite redirect loops)
- Passes URL parameters
- Better error reporting
- Does not write using append (uses w+ identical to wget)
Expand All @@ -18,13 +18,13 @@ npm install wget-improved --save
## download(src, output, options)

```js
var wget = require('wget-improved');
var src = 'http://nodejs.org/images/logo.svg';
var output = '/tmp/logo.svg';
var options = {
const wget = require('wget-improved');
const src = 'http://nodejs.org/images/logo.svg';
const output = '/tmp/logo.svg';
const options = {
// see options below
};
var download = wget.download(src, output, options);
let download = wget.download(src, output, options);
download.on('error', function(err) {
console.log(err);
});
Expand All @@ -35,23 +35,24 @@ download.on('end', function(output) {
console.log(output);
});
download.on('progress', function(progress) {
typeof progress === 'number'
// code to show progress bar
});
```

## request(options, callback)

```js
var wget = require('wget');
var options = {
const wget = require('wget');
const options = {
protocol: 'https',
host: 'raw.github.com',
path: '/Fyrd/caniuse/master/data.json',
proxy: 'http://host:port',
method: 'GET'
};
var req = wget.request(options, function(res) {
var content = '';
let req = wget.request(options, function(res) {
let content = '';
if (res.statusCode === 200) {
res.on('error', function(err) {
console.log(err);
Expand Down Expand Up @@ -98,6 +99,18 @@ nwget https://raw.github.com/Fyrd/caniuse/master/data.json -O /tmp/data.json
./node_modules/.bin/nwget https://raw.github.com/Fyrd/caniuse/master/data.json -O /tmp/data.json
```

## Todo
## Changes from 2.0.0 to 3.0.0
**Progress is now returned as a Number instead of a String**

**On start filesize can return null when the remote server does not provided content-lenth**

Exception for not specifying protocol is now: `Your URL must use either HTTP or HTTPS.`

Supports handling redirects that return a relative URL.

You can now get events for the **total** number of bytes downloaded `download.on('bytes', function(bytes) {}...)`

Request headers can be specified by passing an object to options.headers.

Unit tests have been added for most download functionality and error cases and are a requirement for all PRs going forward!

- Enable gzip when using request method
3 changes: 3 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
machine:
node:
version: 6.10.0
Loading

0 comments on commit 32d2f8c

Please sign in to comment.