download
Download and extract files over HTTP(S) with a single async call
Repository Health
Technical Analysis
download is a small Node.js library for fetching files over HTTP(S) that layers convenience on top of the got HTTP client. A single call returns both a Promise and a Node.js Duplex stream, so callers can await the downloaded buffer or pipe it directly to a destination.
Beyond plain fetching, download detects filenames from Content-Disposition headers or the URL path, infers missing extensions from the response MIME type, and can automatically extract downloaded archives (zip, tar, etc.) via the decompress package when the extract option is set.
What You Get
- A single function that returns both a Promise<Buffer> and a readable/writable Duplex stream
- Automatic destination filename resolution from Content-Disposition headers, URL path, or MIME type
- Optional automatic extraction of downloaded archives via the
decompresspackage - Pass-through of all
gotHTTP client options (proxies, headers, retries, etc.) - Support for downloading multiple URLs concurrently via
Promise.all
Common Use Cases
- Fetching a remote asset (image, dataset, binary) into memory during a build or CLI script
- Downloading and unpacking a release tarball or zip as part of a scaffolding tool
- Streaming a large remote file directly to disk without buffering it all in memory
- Batch-downloading a list of URLs in parallel during a data pipeline
Under The Hood
Architecture: download’s entire implementation lives in a single ~100-line index.js. The exported function creates a got.stream(uri, opts) request stream immediately, then attaches a Promise chain via pEvent(stream, 'response') that buffers the response with get-stream, optionally runs it through decompress when opts.extract is set and the buffer is recognized as an archive by archive-type, or writes it to disk via make-dir + a promisified fs.writeFile. The Promise’s .then/.catch are copied onto the returned stream object, so callers can treat the same value as either a stream or a thenable. Tech Stack: built on got for the HTTP layer, decompress/archive-type/file-type for archive detection and extraction, content-disposition and ext-name for filename/extension resolution, and filenamify/make-dir/pify for filesystem safety — all CommonJS, targeting Node >=10. Code Quality: a single test.js (via ava + nock) covers the main download, extract, and stream-piping paths; the module is linted with xo. There are no type definitions and no code comments beyond the README, but the code is short enough that intent stays clear from structure alone. API Design: the API is a single function with heavily overloaded arguments (output can be omitted and shift into the options position), which keeps common calls terse but makes the signature harder to read from the type alone; documentation is limited to the README’s three usage snippets, and the package has been unmaintained since 2020 with contributors recommending got directly or newer alternatives for new projects.
Used by 2 apps in this directory
Amplication
Developer Tools · AI Code Assistants · Automation
Create production-ready backend services with your organization's standards baked in — generating NestJS, Prisma, and GraphQL code that you own and control.
Budibase
Low Code Platforms · No Code Platforms
Build AI agents, automations, and internal apps on a single open-source platform with full self-hosting control.