npm.io
1.5.0 • Published 5 months ago

@guoyunhe/downloader

Licence
GPL-3.0
Version
1.5.0
Deps
2
Size
45 kB
Vulns
0
Weekly
0
Stars
5

@guoyunhe/downloader

Download large files with minimum RAM usage. Support tar.gz and zip extraction.

Install

npm i @guoyunhe/downloader

Usage

Download a simple file

import { download } from '@guoyunhe/downloader';

await download('https://example.com/logo.png', 'dist/path/logo.png');

Download and extract tar.gz or zip archive

import { download } from '@guoyunhe/downloader';

await download('https://example.com/data.tar.gz', 'dist/path/', { extract: true });
// Output:
// └── export-2023-01-01
//     └── data
//         ├── spec.xml
//         ├── report.pdf
//         └── raw.dat

Reduce extraction file path by two folder

import { download } from '@guoyunhe/downloader';

await download('https://example.com/data.tar.gz', 'dist/path/', { extract: true, strip: 2 });
// Output:
// ├── spec.xml
// ├── report.pdf
// └── raw.dat

Receive download progress updates

import { download } from '@guoyunhe/downloader';

await download('https://example.com/data.tar.gz', 'dist/path/data.tar.gz', {
  onProgress(progress) {
    if (progress.totalBytes === null) {
      console.log(`${progress.downloadedBytes} bytes downloaded`);
    } else {
      console.log(`${progress.percentage?.toFixed(2)}%`);
    }
  },
});

Keywords