Skip to content

Commit 9daddf4

Browse files
authored
feat: v4
- Global CLI, you do not need to wrap active downloads with downloadSequence - Auto increase parallel stream, maximize download speed - Not reusing redirected URL by default - prevent token expires for long downloads - Performance & stability improvements - Remote CLI progress, show download progress in another process easily BREAKING CHANGE: - `partsURL` removed in favor of `partURLs` - Not reusing redirected URL by default - Different chunk size based on programType - You can recall `.download()` and it will not throw an error - will return the same promise of downloading (do *not* redownload the file) - You can change the parallel stream count after download has started
1 parent 4ac36ac commit 9daddf4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1671
-700
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ jobs:
2222
- name: Generate docs
2323
run: npm run generate-docs
2424
- name: Upload build artifact
25-
uses: actions/upload-artifact@v3
25+
uses: actions/upload-artifact@v4
2626
with:
2727
name: "build"
2828
path: "dist"
2929
- name: Upload build artifact
30-
uses: actions/upload-artifact@v3
30+
uses: actions/upload-artifact@v4
3131
with:
3232
name: "docs"
3333
path: "docs"
3434

3535
release:
3636
name: Release
37-
if: github.ref == 'refs/heads/main'
37+
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/beta'
3838
runs-on: ubuntu-latest
3939
concurrency: release-${{ github.ref }}
4040
environment:
@@ -52,10 +52,10 @@ jobs:
5252
- uses: actions/checkout@v3
5353
- uses: actions/setup-node@v3
5454
with:
55-
node-version: "20"
55+
node-version: "22"
5656
- name: Install modules
5757
run: npm ci --ignore-scripts
58-
- uses: actions/download-artifact@v3
58+
- uses: actions/download-artifact@v4
5959
with:
6060
path: artifacts
6161
- name: Move artifacts
@@ -73,16 +73,16 @@ jobs:
7373
id: set-npm-url
7474
run: |
7575
if [ -f .semanticRelease.npmPackage.deployedVersion.txt ]; then
76-
echo "npm-url=https://www.npmjs.com/package/node-llama-cpp/v/$(cat .semanticRelease.npmPackage.deployedVersion.txt)" >> $GITHUB_OUTPUT
76+
echo "npm-url=https://www.npmjs.com/package/ipull/v/$(cat .semanticRelease.npmPackage.deployedVersion.txt)" >> $GITHUB_OUTPUT
7777
fi
7878
- name: Upload docs to GitHub Pages
7979
if: steps.set-npm-url.outputs.npm-url != ''
80-
uses: actions/upload-pages-artifact@v2
80+
uses: actions/upload-pages-artifact@v3
8181
with:
8282
name: pages-docs
8383
path: docs
8484
- name: Deploy docs to GitHub Pages
85-
if: steps.set-npm-url.outputs.npm-url != ''
86-
uses: actions/deploy-pages@v2
85+
if: steps.set-npm-url.outputs.npm-url != '' && github.ref == 'refs/heads/main'
86+
uses: actions/deploy-pages@v4
8787
with:
8888
artifact_name: pages-docs

.releaserc.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"branches": [
3-
"main"
3+
"main",
4+
{
5+
"name": "beta",
6+
"prerelease": true
7+
}
48
],
59
"ci": true,
610
"plugins": [

README.md

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ npx ipull http://example.com/file.large
2525
## Features
2626

2727
- Download using parallels connections
28+
- Maximize download speed (automatic parallelization, 3+)
2829
- Pausing and resuming downloads
2930
- Node.js and browser support
3031
- Smart retry on fail
@@ -73,8 +74,9 @@ import {downloadFileBrowser} from "ipull/dist/browser.js";
7374

7475
const downloader = await downloadFileBrowser({
7576
url: 'https://example.com/file.large',
76-
onWrite: (cursor: number, buffer: Uint8Array, options) => {
77-
console.log(`Writing ${buffer.length} bytes at cursor ${cursor}, with options: ${JSON.stringify(options)}`);
77+
onWrite: (cursor: number, buffers: Uint8Array[], options) => {
78+
const totalLength = buffers.reduce((acc, buffer) => acc + buffer.length, 0);
79+
console.log(`Writing ${totalLength} bytes at cursor ${cursor}, with options: ${JSON.stringify(options)}`);
7880
}
7981
});
8082

@@ -234,12 +236,12 @@ If the maximum reties was reached the download will fail and an error will be th
234236
```ts
235237
import {downloadFile} from 'ipull';
236238

237-
const downloader = await downloadFile({
238-
url: 'https://example.com/file.large',
239-
directory: './this/path'
240-
});
241-
242239
try {
240+
const downloader = await downloadFile({
241+
url: 'https://example.com/file.large',
242+
directory: './this/path'
243+
});
244+
243245
await downloader.download();
244246
} catch (error) {
245247
console.error(`Download failed: ${error.message}`);
@@ -250,6 +252,8 @@ try {
250252

251253
In some edge cases, the re-try mechanism may give the illusion that the download is stuck.
252254

255+
(You can see this in the progress object that "retrying" is true)
256+
253257
To debug this, disable the re-try mechanism:
254258

255259
```js
@@ -258,6 +262,9 @@ const downloader = await downloadFile({
258262
directory: './this/path',
259263
retry: {
260264
retries: 0
265+
},
266+
retryFetchDownloadInfo: {
267+
retries: 0
261268
}
262269
});
263270
```
@@ -286,6 +293,27 @@ downloader.on("progress", (progress) => {
286293
});
287294
```
288295

296+
### Remote Download Listing
297+
298+
If you want to show in the CLI the progress of a file downloading in remote.
299+
300+
```ts
301+
const originaldownloader = await downloadFile({
302+
url: 'https://example.com/file.large',
303+
directory: './this/path'
304+
});
305+
306+
const remoteDownloader = downloadFileRemote({
307+
cliProgress: true
308+
});
309+
310+
originaldownloader.on("progress", (progress) => {
311+
remoteDownloader.emitRemoteProgress(progress);
312+
});
313+
314+
await originaldownloader.download();
315+
```
316+
289317
### Download multiple files
290318

291319
If you want to download multiple files, you can use the `downloadSequence` function.

examples/browser-log.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import {downloadFileBrowser} from "ipull/dist/browser.js";
1+
import {downloadFileBrowser} from "ipull/browser";
22

33
const BIG_IMAGE = "https://upload.wikimedia.org/wikipedia/commons/9/9e/1_dubrovnik_pano_-_edit1.jpg"; // 40mb
44

55
const downloader = await downloadFileBrowser({
66
url: BIG_IMAGE,
7-
onWrite: (cursor: number, buffer: Uint8Array, options) => {
8-
console.log(`Writing ${buffer.length} bytes at cursor ${cursor}, with options: ${JSON.stringify(options)}`);
7+
onWrite: (cursor: number, buffers: Uint8Array[], options: DownloadEngineWriteStreamOptionsBrowser) => {
8+
const totalLength = buffers.reduce((acc, b) => acc + b.byteLength, 0);
9+
console.log(`Writing ${totalLength} bytes at cursor ${cursor}, with options: ${JSON.stringify(options)}`);
910
}
1011
});
1112

package-lock.json

Lines changed: 46 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
"sleep-promise": "^9.1.0",
148148
"slice-ansi": "^7.1.0",
149149
"stdout-update": "^4.0.1",
150-
"strip-ansi": "^7.1.0"
150+
"strip-ansi": "^7.1.0",
151+
"uid": "^2.0.2"
151152
}
152153
}

src/browser.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {downloadFileBrowser, DownloadFileBrowserOptions, downloadSequenceBrowser} from "./download/browser-download.js";
1+
import {downloadFileBrowser, DownloadFileBrowserOptions, downloadFileRemoteBrowser, downloadSequenceBrowser, DownloadSequenceBrowserOptions} from "./download/browser-download.js";
22
import DownloadEngineBrowser from "./download/download-engine/engine/download-engine-browser.js";
33
import EmptyResponseError from "./download/download-engine/streams/download-engine-fetch-stream/errors/empty-response-error.js";
44
import StatusCodeError from "./download/download-engine/streams/download-engine-fetch-stream/errors/status-code-error.js";
@@ -9,17 +9,21 @@ import FetchStreamError from "./download/download-engine/streams/download-engine
99
import IpullError from "./errors/ipull-error.js";
1010
import EngineError from "./download/download-engine/engine/error/engine-error.js";
1111
import {FormattedStatus} from "./download/transfer-visualize/format-transfer-status.js";
12-
import DownloadEngineMultiDownload from "./download/download-engine/engine/download-engine-multi-download.js";
12+
import DownloadEngineMultiDownload, {DownloadEngineMultiAllowedEngines} from "./download/download-engine/engine/download-engine-multi-download.js";
1313
import HttpError from "./download/download-engine/streams/download-engine-fetch-stream/errors/http-error.js";
1414
import BaseDownloadEngine from "./download/download-engine/engine/base-download-engine.js";
1515
import {InvalidOptionError} from "./download/download-engine/engine/error/InvalidOptionError.js";
1616
import {DownloadFlags, DownloadStatus} from "./download/download-engine/download-file/progress-status-file.js";
17-
import {NoDownloadEngineProvidedError} from "./download/download-engine/engine/error/no-download-engine-provided-error.js";
17+
import {DownloadEngineRemote} from "./download/download-engine/engine/DownloadEngineRemote.js";
18+
import {
19+
DownloadEngineWriteStreamOptionsBrowser
20+
} from "./download/download-engine/streams/download-engine-write-stream/download-engine-write-stream-browser.js";
1821

1922
export {
2023
DownloadFlags,
2124
DownloadStatus,
2225
downloadFileBrowser,
26+
downloadFileRemoteBrowser,
2327
downloadSequenceBrowser,
2428
EmptyResponseError,
2529
HttpError,
@@ -29,15 +33,18 @@ export {
2933
FetchStreamError,
3034
IpullError,
3135
EngineError,
32-
InvalidOptionError,
33-
NoDownloadEngineProvidedError
36+
InvalidOptionError
3437
};
3538

3639
export type {
40+
DownloadEngineRemote,
3741
BaseDownloadEngine,
3842
DownloadFileBrowserOptions,
3943
DownloadEngineBrowser,
4044
DownloadEngineMultiDownload,
45+
DownloadEngineMultiAllowedEngines,
4146
FormattedStatus,
42-
SaveProgressInfo
47+
SaveProgressInfo,
48+
DownloadSequenceBrowserOptions,
49+
DownloadEngineWriteStreamOptionsBrowser
4350
};

0 commit comments

Comments
 (0)