Skip to content

Commit

Permalink
fix(README): events
Browse files Browse the repository at this point in the history
  • Loading branch information
ido-pluto committed Feb 24, 2024
1 parent f49c314 commit e7d4163
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -220,8 +244,11 @@ try {
}
```

### Custom Downloader

<details>
<summary>
<h3>Custom Downloader (click to expand)
</h3>
</summary>
In this example, there will be one progress bar for all the files

```ts
Expand Down Expand Up @@ -261,6 +288,8 @@ for (const downloader of await Promise.all(downloadsPromise)) {

![custom-progress-bar](assets/custom-progress.png)

</details>

<br />

<div align="center" width="360">
Expand Down

0 comments on commit e7d4163

Please sign in to comment.