Smart and easy-to-use fetch-based downloader for Node.js compatible runtimes.
Installations
npm install dler
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
>=17.5.0
Node Version
20.17.0
NPM Version
10.8.2
Score
71.1
Supply Chain
98.8
Quality
79.3
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (83.24%)
JavaScript (16.76%)
Developer
YieldRay
Download Statistics
Total Downloads
5,338
Last Day
3
Last Week
37
Last Month
252
Last Year
1,932
GitHub Statistics
1 Stars
36 Commits
1 Watching
1 Branches
1 Contributors
Package Meta Information
Latest Version
0.7.2
Package Id
dler@0.7.2
Unpacked Size
19.28 kB
Size
6.61 kB
File Count
9
NPM Version
10.8.2
Node Version
20.17.0
Publised On
02 Oct 2024
Total Downloads
Cumulative downloads
Total Downloads
5,338
Last day
-66.7%
3
Compared to previous day
Last week
-53.8%
37
Compared to previous week
Last month
71.4%
252
Compared to previous month
Last year
0.6%
1,932
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
2
dler
Smart and easy-to-use fetch
-based downloader for Node.js compatible runtimes.
[!IMPORTANT]
dler
is ESM only, and since it uses the built-infetch
, it requiresnodejs>=17.5.0
.
Features
- Automatically detect the download file name.
- Bing your own
fetch
. - Dependency free.
- Supports resuming downloads.
Limitations
- Does not support multi-threaded or segmented downloads; only sequential downloads are supported.
- Proxy support depends on the runtime's implementation of the
fetch
function. For example, Deno supports automatic proxy, while Node.js and Bun do not.
However, this can be addressed by customizing thefetch
function.
Installation
1$ npm install dler
Usage
1import { download } from 'dler'; 2 3const url = 'https://api.ip.sb/ip'; 4 5// simple 6download(url, './ipinfo.txt'); 7 8// auto detect file name 9download(url); 10download(url, 'dirname/'); 11 12// with options 13download(url, { 14 filePath: 'dirname/', 15 onProgress: (receivedLength, totalLength) => { 16 if (totalLength) console.log((100 * (receivedLength / totalLength)).toFixed(2) + '%'); 17 }, 18 onReady: (resp, saveAs) => console.log(`Downloading ${resp.url} to ${saveAs}`), 19 /* other options in RequestInit */ 20 headers: { 21 Authorization: 'Bearer xxx', 22 }, 23 signal: AbortSignal.timeout(1000), 24});
1// use promise 2download(url [,options]).then(path => console.log(`File saved to ${path}`)); 3 4// use async/await 5const absolutePath = await download(url [,options]);
1/** 2 * Interface representing the initialization options for the downloader. 3 * Extends the `RequestInit` interface. 4 * 5 * Boolean options default to `false` if not specified. 6 */ 7interface DlerInit extends RequestInit { 8 /** 9 * Optional file path where the downloaded file will be saved. 10 * If not provided or if provided as a string ending with '/', the file name will be derived from 11 * the `Content-Disposition` header or the basename of the requested URL. 12 */ 13 filePath?: string; 14 15 /** 16 * Flag to bypass the default check for HTTP status. 17 * By default, the response is considered OK if `response.ok` is true. 18 * Set this to `true` to disable this check. 19 */ 20 doNotCheckOK?: boolean; 21 22 /** 23 * Flag to enable resuming the download if the file already exists. 24 * By default, resumption is not attempted. 25 * Set this to `true` to enable download resumption. 26 * By default, resumption commences at the file size, which may not be desirable. 27 * Specify a number to reset the starting range. 28 */ 29 tryResumption?: boolean | number; 30 31 /** 32 * Callback function for monitoring download progress. 33 * If `Content-Length` is not provided, `totalLength` will be set to `0`. 34 * 35 * @param receivedLength - The number of bytes received so far. 36 * @param totalLength - The total number of bytes to be received. 37 */ 38 onProgress?: (receivedLength?: number, totalLength?: number) => void; 39 40 /** 41 * Callback function invoked when the file is ready to be saved to disk. 42 * If a string is returned, the file will be saved to the specified path. 43 * This path overrides the `filePath` option. 44 * 45 * @param resp - The response object from the fetch request. 46 * @param saveAs - Suggested file path for saving the file. 47 * @returns A string representing the file path where the file should be saved, or a void/Promise resolving to such a string or void. 48 */ 49 onReady?: (resp: Response, saveAs: string) => string | void | Promise<string | void>; 50}
Use as a CLI tool (will log a progress bar in console).
1import { downloadInCLI } from 'dler'; 2const progressBarWidth = 50; // default value 3await downloadInCLI(url, [options[, progressBarWidth]]);
Use as a global command.
1$ npm i dler -g 2$ dler --help
Bring your own fetch
function.
1import { downloadFromFetch } from 'dler'; 2 3const myFetch: typeof fetch = async (input, init) => { 4 const res = await fetch(input, init); 5 console.log(res); // do something... 6 return res; 7}; 8 9const path = await downloadFromFetch(myFetch, 'https://example.net/test.html', { 10 filePath: './', 11});
Example
See ./test
No vulnerabilities found.
No security vulnerabilities found.