Download and extract files

Overview

download Build Status

Download and extract files

See download-cli for the command-line version.

Install

$ npm install download

Usage

const fs = require('fs');
const download = require('download');

(async () => {
	await download('http://unicorn.com/foo.jpg', 'dist');

	fs.writeFileSync('dist/foo.jpg', await download('http://unicorn.com/foo.jpg'));

	download('unicorn.com/foo.jpg').pipe(fs.createWriteStream('dist/foo.jpg'));

	await Promise.all([
		'unicorn.com/foo.jpg',
		'cats.com/dancing.gif'
	].map(url => download(url, 'dist')));
})();

Proxies

To work with proxies, read the got documentation.

API

download(url, destination?, options?)

Returns both a Promise and a Duplex stream with additional events.

url

Type: string

URL to download.

destination

Type: string

Path to where your file will be written.

options

Type: Object

Same options as got and decompress in addition to the ones below.

extract

Type: boolean
Default: false

If set to true, try extracting the file using decompress.

filename

Type: string

Name of the saved file.

Comments
  • strip option is wrong

    strip option is wrong

    According to the docs it's behaviour is equivalent to --strip-components for tar. That argument only strip the first directories until it finds one that has a file or several directories, but download and decompress modules are doing it for all the files, making the decompression wrong. This is particular a problem for Java namespaced classes, where is usual to have several chained namespace folders.

    opened by piranna 19
  • Decompress on real time

    Decompress on real time

    Download waits until the files get completely downloaded before to extract them, making it to consume a lot of memory. Files should be decompress and extracted at the same time they are being downloaded, making it faster and using less memory. This would be fairly easy by using the Streams API on the plugins and the different steps of the decompress pipeline.

    opened by piranna 12
  • Tweaks

    Tweaks

    Some possible tweaks for your consideration:

    1. it gets a header into a variable and then a couple lines down gets it again instead of using the variable. I changed it to reuse the variable.
    2. it does return filenameFromPath(res) in two places within a function. I inverted the header existence check to eliminate the first use so it's only at the end.
    3. the url package is only used for its parse() functions so I changed it to keep the parse function and use it directly.
    4. there are two if statements in a series and both check if there's no output. I changed it to check it once and do the secondary check within that if statement.
    5. Travis CI can cache directories which eases up downloads and speeds up the testing. I configured Travis CI to cache node_modules.
    opened by elidoran 10
  • "Undefined is not a function" error

    buffer.js:203
        buf.copy(buffer, pos);
            ^
    TypeError: undefined is not a function
        at Function.Buffer.concat (buffer.js:203:9)
        at DuplexWrapper.<anonymous> (/home/piranna/Proyectos/NodeOS/node_modules/nodeos-barebones/node_modules/nodeos-cross-toolchain/node_modules/download/node_modules/read-all-stream/index.js:35:21)
        at DuplexWrapper.g (events.js:199:16)
        at DuplexWrapper.emit (events.js:129:20)
        at /home/piranna/Proyectos/NodeOS/node_modules/nodeos-barebones/node_modules/nodeos-cross-toolchain/node_modules/download/node_modules/stream-combiner2/node_modules/duplexer2/node_modules/readable-stream/lib/_stream_readable.js:934:16
        at process._tickCallback (node.js:355:11)
    

    I get this each time that I try to use it, seems Buffer object don't have a copy() method. I'm using Node.js 0.12.0, if that matters... The script is the same as yesterday.

    opened by piranna 9
  • global process events

    global process events

    When downloading several files at a time, the progress callback (for example when using download-status) should notify the progress globally instead of for each individual download progress.

    opened by piranna 9
  • added proxy option

    added proxy option

    This tries to download the required files from the server but if you are behind a corporate proxy server it will fail. By using the environment variables to check for a proxy setting this could be avoided. Also this will fix all imagemin modules like imagemin-optipng and imagemin-pngquant that deep down are trying to download the compiled files for windows.

    opened by radum 9
  • High security vulnerability reported due to dependency on decompress

    High security vulnerability reported due to dependency on decompress

    As reported by npm audit:

    ┌───────────────┬──────────────────────────────────────────────────────────────┐
    │ High          │ Arbitrary File Write                                         │
    ├───────────────┼──────────────────────────────────────────────────────────────┤
    │ Package       │ decompress                                                   │
    ├───────────────┼──────────────────────────────────────────────────────────────┤
    │ Patched in    │ No patch available                                           │
    ├───────────────┼──────────────────────────────────────────────────────────────┤
    │ Dependency of │ download                                                     │
    ├───────────────┼──────────────────────────────────────────────────────────────┤
    │ Path          │ download > decompress                                        │
    ├───────────────┼──────────────────────────────────────────────────────────────┤
    │ More info     │ https://npmjs.com/advisories/1217                            │
    └───────────────┴──────────────────────────────────────────────────────────────┘
    

    https://github.com/kevva/decompress/issues/71

    opened by medikoo 8
  • Fix weirdness from using an older version of decompress

    Fix weirdness from using an older version of decompress

    For some reason [email protected] would occasionally give me an empty array instead of the contents of a tgz I had asked download to fetch and extract. Updating resolves this.

    opened by liath 8
  • Support rfc5987 filename in Content-Disposition

    Support rfc5987 filename in Content-Disposition

    See the filename* directive here. This directive is used to encode UTF-8 filenames as HTTP headers must only contain ASCII characters. Examples based on the RFC:

    filename*=iso-8859-1'en'%A3%20rates
    filename*=UTF-8''%c2%a3%20and%20%e2%82%ac%20rates
    

    I think we can use this module to parse the directive.

    enhancement help wanted 
    opened by silverwind 8
  • fixed environment variables error

    fixed environment variables error

    environment variables always are strings. The string 'false' means true. process.env.npm_config_strict_ssl !== 'false' is also ok. and , the proxy setting should pass to caw not got

    I test it.

    opened by p2227 8
  • EISDIR after extract

    EISDIR after extract

    var download = new Download()
        .get( "https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz", "temp", {extract:true} )
        .use( progress() );
    
    download.run( function(error) {
        if (error) throw error;
    });
    
    /project/lib/install.js:6
        if (error) throw error;
                         ^
    Error: EISDIR, open 'temp/emsdk_portable/'
    
    opened by stevenvachon 8
  • Security Vulnerability: CVE-2022-33987 - got dependency

    Security Vulnerability: CVE-2022-33987 - got dependency

    In the security vulnerability CVE-2022-33987 - got 8.3.1 used in this library has a problem and should likely be upgraded to a fixed version. I don't know if the GitHub dependabots have triggered this for you, but it's considered a "moderate" issue.

    opened by drbobbeaty 1
  • Npm audit failure via older version of got

    Npm audit failure via older version of got

    npm audit is failing in packages that use this, reporting:

    got <11.8.5 Severity: moderate Got allows a redirect to a UNIX socket - https://github.com/advisories/GHSA-pfrx-2q88-qq97

    The got package is currently specified here at version 8. That would have to be updated to at least 11.8.5 to resolve the audit failure.

    opened by wbt 3
  • downloaded file has extension .gi instead of .gif

    downloaded file has extension .gi instead of .gif

    It seems that the last letter is removed when downloading a file that has a long and complex filename.

    example file: https://images.squarespace-cdn.com/content/v1/6124a4fd689c806393eb581b/81dc0346-e123-4880-89dd-104e34a4f596/Kanalbyen+-+a+new+destination+in+Kristiansand%2C+Norway-high+%281%29+%28brugt+p%C3%A5+forsiden%29.gif

    is saved as: Kanalbyen+-+a+new+destination+in+Kristiansand%2C+Norway-high+%281%29+%28brugt+p%C3%A5+forsiden%29.gi

    I'm using a mac

    opened by terchris 0
  • High Vulnerability: Regular Expression Denial of Service in trim-newlines

    High Vulnerability: Regular Expression Denial of Service in trim-newlines

    As stated from npm audit there's a High vulnerability issue with the package trim-newlines used by download-cli version 1.1.1 which is the latest one.

    image
    opened by kristiannotari 0
Releases(v8.0.0)
  • v8.0.0(Apr 2, 2020)

    Breaking

    • Require Node.js 10 7e7378f
    • Remove proxy option a16ba04

    Fixes

    • Update decompress dependency (#192) 9725328

    https://github.com/kevva/download/compare/v7.1.0...v8.0.0

    Source code(tar.gz)
    Source code(zip)
Owner
Kevin Mårtensson
Kevin Mårtensson
HTTP Client for Visual Studio Code to POST JSON, XML, image, ... files to REST APIs

friflo POST Goal Main goal of this extension is storing all HTTP request & response data automatically as files in a VSCode workspace. This ensures th

Ullrich Praetz 2 Nov 18, 2021
Hello! Welcome to Our own Live Code Editor 2!! This is supported tabs and full-screen editing, Console, tabs and more are coming. We uses this one in our all tutorials. Made by @E-Coders & @Genius398

Live Code Editor 2 Hello! this is our live code editor an another second release version of our main Resporibity. This have style as tabs and more fea

Educational Websites 5 Nov 18, 2021
Promise based HTTP client for the browser and node.js

axios Promise based HTTP client for the browser and node.js New axios docs website: click here Table of Contents Features Browser Support Installing E

axios 98k Dec 31, 2022
Ajax for Node.js and browsers (JS HTTP client)

superagent Small progressive client-side HTTP request library, and Node.js module with the same API, supporting many high-level HTTP client features T

Sloth 16.2k Jan 1, 2023
HTTP server mocking and expectations library for Node.js

Nock HTTP server mocking and expectations library for Node.js Nock can be used to test modules that perform HTTP requests in isolation. For instance,

Nock 11.9k Jan 3, 2023
🌐 Human-friendly and powerful HTTP request library for Node.js

Sindre's open source work is supported by the community. Special thanks to: Human-friendly and powerful HTTP request library for Node.js Moving from R

Sindre Sorhus 12.5k Jan 9, 2023
Full-featured, middleware-oriented, programmatic HTTP and WebSocket proxy for node.js

rocky A multipurpose, full-featured, middleware-oriented and hackable HTTP/S and WebSocket proxy with powerful built-in features such as versatile rou

Tom 370 Nov 24, 2022
A fully-featured Node.js REST client built for ease-of-use and resilience

flashheart A fully-featured Node.js REST client built for ease-of-use and resilience flashheart is built on http-transport to provide everything you n

BBC 118 Jun 21, 2022
Bearer provides all of the tools to build, run and manage API integrations.

Bearer - The API Integration Framework Bearer provides all of the tools to build, run and manage API Learn more Archive Status Bearer JS has been arch

Bearer.sh 22 Oct 31, 2022
A collaborative Whiteboard powered by the [matrix] protocol and infrastucture.

TheBoard A collaborative Whiteboard powered by the [Matrix] protocol and infrastructure. Table of Content: Introduction DISCLAIMER How this project ca

Timo 391 Dec 23, 2022
Library agnostic in-process recording of http(s) requests and responses

@gr2m/http-recorder Library agnostic in-process recording of http(s) requests and responses Install npm install @gr2m/http-recorder Usage import http

Gregor Martynus 4 May 12, 2022
A jQuery plugin for make your ajax request's error and success messages auto handled.

sweetAjax A jQuery plugin for make your ajax request's error and success messages auto handled. Installation sweetAjax plugin has built on jQuery-ui w

Eren Sertkaya 2 May 17, 2022
Very very very powerful, extensible http client for both node.js and browser.

ES-Fetch-API 中文 | English Very very very powerful, extensible http client for both node.js and browser. Why should you use ES-Fetch API? Still using a

null 17 Dec 12, 2022
Async node.js implementation of the UDP Minecraft Server Query Protocol and TCP Minecraft Server List Ping Protocol

?? Mc Server Status Async node.js implementation of the UDP Minecraft Server Query Protocol and TCP Minecraft Server List Ping Protocol. Also availabl

Daniel 5 Nov 10, 2022
Highly sophisticated proxy used for evading internet censorship or accessing websites in a controlled sandbox using the power of service-workers and more! Easy deployment version (Node.js)

Ultraviolet-Node The deployable version of Ultraviolet, a highly sophisticated proxy used for evading internet censorship or accessing websites in a c

Titanium Network 27 Jan 2, 2023
Highly sophisticated proxy used for evading internet censorship or accessing websites in a controlled sandbox using the power of service-workers and more! Easy deployment version (Node.js)

Ultraviolet-Node The deployable version of Ultraviolet, a highly sophisticated proxy used for evading internet censorship or accessing websites in a c

Titanium Network 34 Apr 15, 2022
Download all Moodle files with one click. This is a Chrome extension built to save time and effort from downloading files manually one by one!

Moodle Downloader Extension Moodle downloader extension for Chrome. The extension is tested with both the TUM moodle and the official moodle demo. Not

Zhongpin Wang 8 Nov 15, 2022
Extract and merge i18n xliff translation files for angular projects.

Angular extract i18n and merge This extends Angular CLI to improve the i18n extraction and merge workflow. New/removed translations are added/removed

Daniel Schreiber 86 Jan 5, 2023
Download Notion pages as markdown and image files, preserving hierarchy and enabling workflow properties. Works with Docusaurus.

notion-pull notion-pull lets you use Notion as your editor for markdown-based static site generators like Docusaurus. Using Notion instead of raw mark

SIL LSDev 46 Jan 7, 2023
A tiny javascript + Flash library that enables the creation and download of text files without server interaction.

Downloadify: Client Side File Creation Important! The swf has been compiled for online use only. Testing from the file path (i.e. file:// ) will not w

Doug Neiner 853 Nov 21, 2022