Skip to content

Commit abd95a9

Browse files
committed
feat: ✨ blob 数据支持动态获取
1 parent 81ec13e commit abd95a9

4 files changed

Lines changed: 28 additions & 8 deletions

File tree

libs/zip-downloader/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @xiaohuohumax/xpath-selector
22

3+
## 2.1.0
4+
5+
### Minor Changes
6+
7+
- Blob 数据支持动态获取
8+
39
## 2.0.3
410

511
### Patch Changes

libs/zip-downloader/README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828

2929
**Resource 参数说明:**
3030

31-
| 参数名 | 类型 | 是否必填 | 默认值 | 说明 |
32-
| ------ | ------ | -------- | ------ | ------------- |
33-
| `name` | string || | 资源名称 |
34-
| `url` | string || | URL 类型资源 |
35-
| `blob` | Blob || | Blob 类型资源 |
31+
| 参数名 | 类型 | 是否必填 | 默认值 | 说明 |
32+
| ------ | ----------------------------- | -------- | ------ | ------------- |
33+
| `name` | string || | 资源名称 |
34+
| `url` | string || | URL 类型资源 |
35+
| `blob` | Blob 或者 () => Promise<Blob> || | Blob 类型资源 |
3636

3737
## 📦 使用示例
3838

@@ -47,6 +47,13 @@ await zipDownloader({
4747
name: 'hello.txt',
4848
blob: new Blob(['hello world'], { type: 'text/plain' }),
4949
},
50+
{
51+
name: 'world.txt',
52+
blob: async () => {
53+
const response = await fetch('https://example.com/world.txt')
54+
return response.blob()
55+
},
56+
},
5057
],
5158
concurrency: 10,
5259
async onProgress(index) {
@@ -65,6 +72,13 @@ const blob = await zipDownloader({
6572
name: 'hello.txt',
6673
blob: new Blob(['hello world'], { type: 'text/plain' }),
6774
},
75+
{
76+
name: 'world.txt',
77+
blob: async () => {
78+
const response = await fetch('https://example.com/world.txt')
79+
return response.blob()
80+
},
81+
},
6882
],
6983
concurrency: 10,
7084
async onProgress(index) {

libs/zip-downloader/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@xiaohuohumax/zip-downloader",
33
"type": "module",
4-
"version": "2.0.3",
4+
"version": "2.1.0",
55
"description": "Zip Downloader -- 资源下载器(下载资源、Zip 压缩、下载到本地)",
66
"author": {
77
"name": "xiaohuohumax",

libs/zip-downloader/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface UrlResource {
88

99
export interface BlobResource {
1010
name: string
11-
blob: Blob
11+
blob: Blob | (() => Promise<Blob>)
1212
}
1313

1414
function isBlobResource(resource: Resource): resource is BlobResource {
@@ -43,7 +43,7 @@ export default async function zipDownloader(options: Options): Promise<void | Bl
4343
await Promise.all(options.resources.map((resource, index) => limit(async () => {
4444
await options.onProgress?.(index)
4545
const reader = isBlobResource(resource)
46-
? new BlobReader(resource.blob)
46+
? new BlobReader(typeof resource.blob === 'function' ? await resource.blob() : resource.blob)
4747
: new HttpReader(resource.url)
4848
return writer.add(resource.name, reader)
4949
})))

0 commit comments

Comments
 (0)