Skip to content

Commit

Permalink
[add] Abort Signal support & polyfill (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery authored May 18, 2024
1 parent 0efd48f commit 39d4277
Show file tree
Hide file tree
Showing 10 changed files with 3,735 additions and 3,121 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

- uses: pnpm/action-setup@v2
with:
version: 8
version: 9
- uses: actions/setup-node@v3
with:
node-version: 18
Expand Down
16 changes: 10 additions & 6 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ npm install koajax
<script src="https://polyfill.web-cell.dev/feature/Regenerator.js"></script>
<script src="https://polyfill.web-cell.dev/feature/ECMAScript.js"></script>
<script src="https://polyfill.web-cell.dev/feature/TextEncoder.js"></script>
<script src="https://polyfill.web-cell.dev/feature/AbortController.js"></script>
</head>
```

Expand Down Expand Up @@ -139,19 +140,22 @@ const bufferClient = new HTTPClient({ responseType: 'arraybuffer' });

document.querySelector('#download').onclick = async () => {
const fileURL = 'https://your.server/with/Range/header/supported/file.zip';
const suggestedName = fileURL.split('/').at(-1);
const suggestedName = new URL(fileURL).pathname.split('/').pop();

const fileHandle = await showSaveFilePicker({ suggestedName });
const writer = await fileHandle.createWritable(),
stream = bufferClient.download(fileURL);

for await (const { total, loaded, percent, buffer } of stream) {
writer.write(buffer);
try {
for await (const { total, loaded, percent, buffer } of stream) {
await writer.write(buffer);

console.table({ total, loaded, percent });
console.table({ total, loaded, percent });
}
window.alert(`File ${fileHandle.name} downloaded successfully!`);
} finally {
await writer.close();
}
writer.close();
window.alert(`File ${fileHandle.name} downloaded successfully!`);
};
```

Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "koajax",
"version": "1.0.0",
"version": "1.1.0",
"license": "LGPL-3.0",
"author": "[email protected]",
"description": "HTTP Client based on Koa-like middlewares",
Expand All @@ -25,10 +25,10 @@
"main": "dist/index.js",
"module": "dist/index.esm.js",
"dependencies": {
"@swc/helpers": "^0.5.8",
"@swc/helpers": "^0.5.11",
"iterable-observer": "^1.0.1",
"regenerator-runtime": "^0.14.1",
"web-utility": "^4.3.0"
"web-utility": "^4.4.0"
},
"peerDependencies": {
"jsdom": ">=21"
Expand All @@ -39,8 +39,8 @@
"@types/core-js": "^2.5.8",
"@types/jest": "^29.5.12",
"@types/jsdom": "^21.1.6",
"@types/node": "^18.19.28",
"core-js": "^3.36.1",
"@types/node": "^18.19.33",
"core-js": "^3.37.1",
"cross-env": "^7.0.3",
"husky": "^9.0.11",
"jest": "^29.7.0",
Expand All @@ -51,9 +51,9 @@
"parcel": "~2.12.0",
"prettier": "^3.2.5",
"ts-jest": "^29.1.2",
"typedoc": "^0.25.12",
"typedoc-plugin-mdn-links": "^3.1.18",
"typescript": "~5.4.3"
"typedoc": "^0.25.13",
"typedoc-plugin-mdn-links": "^3.1.25",
"typescript": "~5.5.0-beta"
},
"prettier": {
"singleQuote": true,
Expand All @@ -77,7 +77,7 @@
},
"scripts": {
"prepare": "husky",
"test": "lint-staged && jest",
"test": "lint-staged && cross-env NODE_OPTIONS=--unhandled-rejections=warn jest",
"pack-dist": "rm -rf dist/ && tsc --emitDeclarationOnly && parcel build",
"pack-docs": "rm -rf docs/ && typedoc source/",
"build": "npm run pack-dist && npm run pack-docs",
Expand Down
Loading

0 comments on commit 39d4277

Please sign in to comment.