GithubHelp home page GithubHelp logo

s73obrien / node-wget Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bearjaws/node-wget

1.0 2.0 0.0 53 KB

A download tool for nodejs that emulates the functionality of wget

License: MIT License

JavaScript 100.00%

node-wget's Introduction

wget-improved

CircleCI

wget-improved simplifies retrieving files from any URL

Improvements over wuchengwei/node-wget

  • Handles 3xx redirects (including infinite redirect loops)
  • Passes URL parameters
  • Better error reporting
  • Does not write using append (uses w+ identical to wget)
  • Handles gzip compression, allow you to automatically gunzip the stream

Install

npm install wget-improved --save

download(src, output, options)

const wget = require('wget-improved');
const src = 'http://nodejs.org/images/logo.svg';
const output = '/tmp/logo.svg';
const options = {
    // see options below
};
let download = wget.download(src, output, options);
download.on('error', function(err) {
    console.log(err);
});
download.on('start', function(fileSize) {
    console.log(fileSize);
});
download.on('end', function(output) {
    console.log(output);
});
download.on('progress', function(progress) {
    typeof progress === 'number'
    // code to show progress bar
});

request(options, callback)

const wget = require('wget');
const options = {
    protocol: 'https',
    host: 'raw.github.com',
    path: '/Fyrd/caniuse/master/data.json',
    proxy: 'http://host:port',
    method: 'GET'
};
let req = wget.request(options, function(res) {
    let content = '';
    if (res.statusCode === 200) {
        res.on('error', function(err) {
            console.log(err);
        });
        res.on('data', function(chunk) {
            content += chunk;
        });
        res.on('end', function() {
            console.log(content);
        });
    } else {
        console.log('Server respond ' + res.statusCode);
    }
});

req.end();
req.on('error', function(err) {
    console.log(err);
});

options

options = {}
    // Set to true to have any gzip stream automatically decompressed before saving
    options.gunzip = false;
    options.proxy = {};
        options.proxy.protocol = 'http';
        options.proxy.host = 'someproxy.org';
        options.proxy.port = 1337;
        options.proxy.proxyAuth = '{basic auth}';
        options.proxy.headers = {'User-Agent': 'Node'};

CLI

# If installed globally
nwget https://raw.github.com/Fyrd/caniuse/master/data.json -O /tmp/data.json

# If not installed globally
./node_modules/.bin/nwget https://raw.github.com/Fyrd/caniuse/master/data.json -O /tmp/data.json

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. Tests are a requirement for all PRs going forward!

node-wget's People

Contributors

bearjaws avatar eternaldeiwos avatar ffflabs avatar gnestor avatar raederdev avatar s73obrien avatar theheretic avatar wuchengwei avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.