From e7d4163c864a778d3031abcad058fc8127338ef4 Mon Sep 17 00:00:00 2001 From: ido Date: Sun, 25 Feb 2024 00:01:08 +0200 Subject: [PATCH] fix(README): events --- README.md | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 97d7d31..a1099e0 100644 --- a/README.md +++ b/README.md @@ -31,19 +31,40 @@ npx ipull http://example.com/file.large - CLI Progress bar - Download statistics (speed, time left, etc.) -### NodeJS API +## NodeJS API ```ts import {downloadFile} from 'ipull'; const downloader = downloadFile('https://example.com/file.large', { directory: './this/path', + fileName: 'file.large', // optional cliProgress: true // Show progress bar in the CLI (default: true) }); await downloader.download(); ``` +### Events + +```ts +import {downloadFile} from 'ipull'; + +const downloader = downloadFile('https://example.com/file.large', { + onInit(engine) { + }, // retrive the file size and other details + onStart(engine) { + }, // download has started + onProgress(engine) { + console.log(`Time left: ${engine.timeLeft}, download speed: ${engine.speed}`) + }, + onFinished(engine) { + }, // download has finished (file is still open) + onClosed(engine) { + } // download has finished and the file is closed +}); +``` + ## Browser support Download a file in the browser using multiple connections @@ -210,7 +231,10 @@ with [async-retry](https://www.npmjs.com/package/async-retry) import {downloadFile} from 'ipull'; const downloader = downloadFile('https://example.com/file.large', { - directory: './this/path' + directory: './this/path', + retry: { + retries: 20 // default: 10 + } }); try { @@ -220,8 +244,11 @@ try { } ``` -### Custom Downloader - +
+ +

Custom Downloader (click to expand) +

+
In this example, there will be one progress bar for all the files ```ts @@ -261,6 +288,8 @@ for (const downloader of await Promise.all(downloadsPromise)) { ![custom-progress-bar](assets/custom-progress.png) +
+