libfw-client 0.4.4 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +296 -161
- package/index.js +9 -3
- package/package.json +2 -2
- package/pkg/libfw_client.d.ts +5 -5
- package/pkg/libfw_client.js +19 -19
- package/pkg/libfw_client_bg.wasm +0 -0
- package/pkg/libfw_client_bg.wasm.d.ts +5 -5
- package/pkg/package.json +1 -1
- package/zip.js +8 -3
package/README.md
CHANGED
|
@@ -1,187 +1,322 @@
|
|
|
1
|
-
# libfw-client SDK
|
|
1
|
+
# libfw-client (browser SDK)
|
|
2
2
|
|
|
3
|
-
The browser
|
|
4
|
-
|
|
3
|
+
The official browser client for [libfw](../README.md). It wraps the WASM
|
|
4
|
+
engine, the File System Access API and IndexedDB behind one small ESM class:
|
|
5
|
+
you call `upload` / `downloadFolder` / `downloadFile` with a bearer token.
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
> `tokio` + `reqwest`), with a runnable CLI in
|
|
9
|
-
> [`examples/rust-client`](../examples/rust-client/README.md).
|
|
7
|
+
The same protocol engine is available natively for non-browser programs —
|
|
8
|
+
see [docs/native-client.md](../docs/native-client.md).
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
- [Install](#install)
|
|
11
|
+
- [Quick start](#quick-start)
|
|
12
|
+
- [Options](#options)
|
|
13
|
+
- [API](#api)
|
|
14
|
+
- [Events](#events)
|
|
15
|
+
- [Errors](#errors)
|
|
16
|
+
- [How transfers work](#how-transfers-work)
|
|
17
|
+
- [Resume and page refresh](#resume-and-page-refresh)
|
|
18
|
+
- [Download modes and ZIP fallback](#download-modes-and-zip-fallback)
|
|
19
|
+
- [Adaptive tuning](#adaptive-tuning)
|
|
20
|
+
- [Building the package](#building-the-package)
|
|
21
|
+
- [Browser support and security](#browser-support-and-security)
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install libfw-client
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or use it from source in this repository:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
wasm-pack build crates/libfw-client --target web --out-dir ../../sdk/pkg --release
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The package ships the ESM entry (`index.js`), TypeScript types
|
|
36
|
+
(`index.d.ts`), the dependency-free ZIP writer (`zip.js`) and the
|
|
37
|
+
`wasm-pack` output under `pkg/`. It does not bundle or fetch anything else.
|
|
38
|
+
|
|
39
|
+
## Quick start
|
|
12
40
|
|
|
13
41
|
```js
|
|
14
42
|
import { LibfwClient } from 'libfw-client';
|
|
15
43
|
|
|
16
44
|
const client = new LibfwClient({
|
|
17
|
-
baseUrl: '/',
|
|
18
|
-
concurrency: 4,
|
|
19
|
-
uploadWindow: 8,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
compress: true, // zrip per-block compression
|
|
24
|
-
compressLevel: 'auto',// zrip level policy: 'auto' benchmarks uploads
|
|
25
|
-
// (needs autoTune) / 'fast' / 'balanced' / 'max' / N
|
|
26
|
-
autoTune: true, // adaptive tuning: probes /capabilities and ramps
|
|
27
|
-
tuneTtlMs: 3600000, // how long a settled result stays cached (browser,
|
|
28
|
-
// localStorage); 0 = never cache, re-ramp each time
|
|
29
|
-
// concurrency/windows/chunk size from real stats
|
|
45
|
+
baseUrl: '/', // where libfw-server is mounted (same origin by default)
|
|
46
|
+
concurrency: 4, // parallel files
|
|
47
|
+
uploadWindow: 8, // in-flight chunks per file upload
|
|
48
|
+
downloadWindow: 4, // parallel range GETs per file download
|
|
49
|
+
compress: true,
|
|
50
|
+
autoTune: true,
|
|
30
51
|
onEvent: (e) => {
|
|
31
|
-
if (e.type === 'progress')
|
|
32
|
-
|
|
33
|
-
// other types: fileStart, fileCompleted, ...
|
|
52
|
+
if (e.type === 'progress') bar.value = e.done / e.total;
|
|
53
|
+
if (e.type === 'tuning') console.log(e.phase, e.params, e.stats);
|
|
34
54
|
},
|
|
35
55
|
});
|
|
36
56
|
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
// traditional browser download — no feature detection needed by the caller.
|
|
40
|
-
await client.downloadFolder('your_token_here');
|
|
57
|
+
// upload <input type="file" multiple>
|
|
58
|
+
await client.upload(token, document.querySelector('input[type=file]').files);
|
|
41
59
|
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
await client.upload('your_token_here', input.files);
|
|
60
|
+
// upload a whole folder (showDirectoryPicker)
|
|
61
|
+
await client.upload(token);
|
|
45
62
|
|
|
46
|
-
//
|
|
47
|
-
await client.
|
|
63
|
+
// download a whole folder into a picked local directory
|
|
64
|
+
await client.downloadFolder(token);
|
|
48
65
|
|
|
49
|
-
//
|
|
50
|
-
client.
|
|
51
|
-
client.resume();
|
|
52
|
-
client.cancel();
|
|
66
|
+
// download a single file
|
|
67
|
+
await client.downloadFile(token, 'docs/plan.pdf');
|
|
53
68
|
```
|
|
54
69
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
- **HTTP transport, not WebSocket** — the engine drives all control commands
|
|
58
|
-
(directory listing, metadata) and data over plain HTTP. This is what keeps
|
|
59
|
-
transfers robust on lossy/unstable links: each transfer uses **independent
|
|
60
|
-
parallel HTTP streams**, so a lost packet stalls only that one stream
|
|
61
|
-
(which retries just its own bytes) instead of blocking a whole multiplexed
|
|
62
|
-
WebSocket connection.
|
|
63
|
-
- **Downloads** — `downloadFolder(token, dirPath?)` / `downloadFile(token,
|
|
64
|
-
filePath)` list the tree (for folders) and fetch each large file as
|
|
65
|
-
`downloadWindow` concurrent `Range` GETs (tus-style parallel transfer, one
|
|
66
|
-
independent connection per range). Each chunk is retried independently
|
|
67
|
-
(only the lost part is re-fetched); the engine reorders the chunks in
|
|
68
|
-
memory and pushes `Uint8Array`s to the SDK **strictly in order**.
|
|
69
|
-
`Range`/`If-Range`/`416` give natural resume against the server ETag (the
|
|
70
|
-
server is the source of truth). With the File System Access API the SDK
|
|
71
|
-
streams chunks to disk via `fileHandle.createWritable()`; without it (or
|
|
72
|
-
with `downloadMode: 'browser'`) it buffers the chunks and saves the result
|
|
73
|
-
through a traditional browser download — a single file as-is, a folder
|
|
74
|
-
packed into a `.zip`.
|
|
75
|
-
- **Uploads** — `upload(token, files?)` slices each file into chunks, reads
|
|
76
|
-
them via `readFile`, compresses each into one zstd frame and POSTs the
|
|
77
|
-
missing chunks concurrently (out of order) with `x-libfw-offset` into a
|
|
78
|
-
shared per-session temp on the server (positional writes). A final
|
|
79
|
-
`x-libfw-final` commit validates the size and atomically renames the temp
|
|
80
|
-
into place. Only the chunks the server still misses are re-sent
|
|
81
|
-
(`x-libfw-session-status` probe seeds resume), so interrupted uploads
|
|
82
|
-
resume BitTorrent-style (only the broken/lost parts are re-transmitted).
|
|
83
|
-
A dropped connection (page refresh, crashed tab) keeps that partial on the
|
|
84
|
-
server, so a reloaded page resumes exactly where it stopped.
|
|
85
|
-
- Resume state (`etag`, `offset`, `size`) is persisted per path in
|
|
86
|
-
IndexedDB and re-validated on every retry. `createWritable()` only
|
|
87
|
-
publishes a file on `close()`, so a download **checkpoints** its prefix to
|
|
88
|
-
disk every time the engine reports a durable offset (~4 MiB) — a hard page
|
|
89
|
-
refresh mid-download therefore resumes from the last checkpoint instead of
|
|
90
|
-
restarting from byte 0.
|
|
91
|
-
- Pause/resume/cancel drive the WASM state machine
|
|
92
|
-
(`idle → downloading/uploading → paused → resumed → completed/failed`).
|
|
93
|
-
|
|
94
|
-
## Build
|
|
70
|
+
`downloadFolder` / `downloadFile` / the argument-less `upload` call a
|
|
71
|
+
directory picker, so they must run from a user gesture (a click handler).
|
|
95
72
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
73
|
+
## Options
|
|
74
|
+
|
|
75
|
+
| Option | Default | Meaning |
|
|
76
|
+
| --- | --- | --- |
|
|
77
|
+
| `baseUrl` | `''` | origin/prefix where libfw is mounted; `''` = same origin |
|
|
78
|
+
| `concurrency` | `4` | max files transferred in parallel |
|
|
79
|
+
| `uploadWindow` | `8` | in-flight chunks per single-file upload |
|
|
80
|
+
| `downloadWindow` | `4` | in-flight `Range` GETs per single-file download (`1` = sequential) |
|
|
81
|
+
| `compress` | `true` | request/send zrip (zstd) compression |
|
|
82
|
+
| `compressLevel` | `'balanced'` | `'auto'` \| `'fast'` \| `'balanced'` \| `'max'` \| number; `'auto'` benchmarks uploads |
|
|
83
|
+
| `chunkSize` | `2097152` (2 MiB) | shared chunk size for uploads and download ranges |
|
|
84
|
+
| `maxRetries` | `3` | retries per chunk/file |
|
|
85
|
+
| `baseRetryDelayMs` | `500` | initial exponential backoff |
|
|
86
|
+
| `maxRetryDelayMs` | `30000` | backoff ceiling |
|
|
87
|
+
| `timeoutMs` | `60000` | per-request stall timeout |
|
|
88
|
+
| `autoTune` | `false` | enable the adaptive ramp |
|
|
89
|
+
| `tuneTtlMs` | `3600000` (1 h) | how long a cached settle stays usable; `0` disables caching |
|
|
90
|
+
| `wasmUrl` | auto | explicit URL of `libfw_client_bg.wasm` |
|
|
91
|
+
| `downloadMode` | `'auto'` | `'auto'` \| `'fs'` \| `'browser'` |
|
|
92
|
+
| `maxFallbackBytes` | `536870912` (512 MiB) | memory cap for the `'browser'` fallback; `0` disables |
|
|
93
|
+
| `onEvent` | — | progress/lifecycle/tuning listener |
|
|
94
|
+
| `directoryHandle` | — | pre-selected handle (or resolver) instead of `showDirectoryPicker` |
|
|
95
|
+
| `resolveDisplayName` | — | map a server path to the on-disk / archive name |
|
|
96
|
+
| `resolveUploadPath` | — | map an upload entry to its virtual server path |
|
|
97
|
+
|
|
98
|
+
Notes:
|
|
99
|
+
|
|
100
|
+
- `concurrency` is the cross-file fan-out. The engine sizes its shared
|
|
101
|
+
in-flight request budget as `concurrency × max(uploadWindow,
|
|
102
|
+
downloadWindow)`, so raising a window actually increases parallelism (it
|
|
103
|
+
used to be capped by `concurrency` alone).
|
|
104
|
+
- `chunkSize` is used by both directions. The download path buffers in-flight
|
|
105
|
+
chunks for reordering, so peak memory is roughly
|
|
106
|
+
`downloadWindow × chunkSize`.
|
|
107
|
+
- `compressLevel` is a client *policy*, resolved against the server's
|
|
108
|
+
advertised range. `'auto'` additionally micro-benchmarks the range on a
|
|
109
|
+
real sample of the first uploaded file; downloads request the resolved
|
|
110
|
+
level from the server.
|
|
111
|
+
- `tuneTtlMs` only matters with `autoTune`. It is ignored by the native
|
|
112
|
+
client.
|
|
113
|
+
|
|
114
|
+
Example with a per-file virtual path:
|
|
99
115
|
|
|
100
|
-
|
|
101
|
-
|
|
116
|
+
```js
|
|
117
|
+
await client.upload(token, [
|
|
118
|
+
{ file, relPath: 'reports/2026/plan.pdf' },
|
|
119
|
+
]);
|
|
102
120
|
```
|
|
103
121
|
|
|
104
|
-
|
|
122
|
+
## API
|
|
123
|
+
|
|
124
|
+
### Transfers
|
|
125
|
+
|
|
126
|
+
| Method | Returns | Description |
|
|
127
|
+
| --- | --- | --- |
|
|
128
|
+
| `downloadFolder(token, dirPath?)` | bytes written | download a remote folder into a picked local folder (`''` = root) |
|
|
129
|
+
| `downloadFile(token, filePath, opts?)` | bytes written | download one file; `opts.fileName` overrides the leaf name |
|
|
130
|
+
| `upload(token, files?)` | bytes sent | `FileList`, `File[]`, `UploadFileEntry[]`, `UploadEntry[]`, or no argument = pick a folder |
|
|
131
|
+
|
|
132
|
+
### Controls and state
|
|
133
|
+
|
|
134
|
+
| Method | Description |
|
|
135
|
+
| --- | --- |
|
|
136
|
+
| `pause()` | pause the active transfer |
|
|
137
|
+
| `resume()` | resume it (state is revalidated first) |
|
|
138
|
+
| `cancel()` | cancel it → state `failed` |
|
|
139
|
+
| `state()` | `idle` \| `downloading` \| `uploading` \| `paused` \| `completed` \| `failed` |
|
|
140
|
+
| `progress()` | `0..1` |
|
|
141
|
+
| `doneBytes()` | bytes transferred so far |
|
|
142
|
+
| `totalBytes()` | total bytes to transfer |
|
|
143
|
+
| `tuneStatus()` | `{ phase, params, stats, capsHash }` or `null` |
|
|
144
|
+
| `clearResumeStore(direction?)` | remove persisted resume records (`'upload'` / `'download'`), returns the count |
|
|
145
|
+
|
|
146
|
+
`tuneStatus()` shape:
|
|
105
147
|
|
|
148
|
+
```js
|
|
149
|
+
{
|
|
150
|
+
phase: 'settled', // uninitialized | ramping | settled | degraded
|
|
151
|
+
params: {
|
|
152
|
+
concurrency: 4,
|
|
153
|
+
uploadWindow: 8,
|
|
154
|
+
downloadWindow: 4,
|
|
155
|
+
chunkSize: 4194304,
|
|
156
|
+
compressLevel: 1, // resolved policy (what downloads request)
|
|
157
|
+
},
|
|
158
|
+
stats: { rttMs: 12.4, mbps: 87.3 },
|
|
159
|
+
capsHash: 'sha256-…',
|
|
160
|
+
}
|
|
106
161
|
```
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
162
|
+
|
|
163
|
+
## Events
|
|
164
|
+
|
|
165
|
+
`onEvent` receives one of:
|
|
166
|
+
|
|
167
|
+
| Event | Fields | When |
|
|
168
|
+
| --- | --- | --- |
|
|
169
|
+
| `fileStart` | `path`, `done: 0`, `total: size` | a file starts |
|
|
170
|
+
| `fileCompleted` | `path` | a file finishes |
|
|
171
|
+
| `progress` | `done`, `total` | byte progress (frequent — keep the handler cheap) |
|
|
172
|
+
| `tuning` | `phase`, `params`, `stats` | tuning phase/window changes (only with `autoTune`) |
|
|
173
|
+
|
|
174
|
+
`progress` is emitted per received body slice, not per chunk, so a large range
|
|
175
|
+
GET still animates. Downloads also emit monotonically increasing totals
|
|
176
|
+
across files.
|
|
177
|
+
|
|
178
|
+
## Errors
|
|
179
|
+
|
|
180
|
+
Every rejection is a `LibfwError` with a stable `code`:
|
|
181
|
+
|
|
182
|
+
| Code | Meaning |
|
|
183
|
+
| --- | --- |
|
|
184
|
+
| `unknown` | unclassified |
|
|
185
|
+
| `wasm` | engine initialization/panic surfaced |
|
|
186
|
+
| `abort` | `AbortController` fired |
|
|
187
|
+
| `unsupported` | a required browser API is missing |
|
|
188
|
+
| `path` | invalid/unsafe path |
|
|
189
|
+
| `storage` | local file write / seek failure |
|
|
190
|
+
| `idb` | IndexedDB failure |
|
|
191
|
+
| `http` | non-success HTTP status (`http 404 for \`/file/x\``) |
|
|
192
|
+
| `network` | transport failure |
|
|
193
|
+
| `decompress` | bad compressed stream |
|
|
194
|
+
| `compress` | compression failure |
|
|
195
|
+
| `protocol` | malformed server payload |
|
|
196
|
+
| `cancelled` | user cancelled |
|
|
197
|
+
| `too-large` | would exceed `maxFallbackBytes` |
|
|
198
|
+
|
|
199
|
+
```js
|
|
200
|
+
try {
|
|
201
|
+
await client.downloadFolder(token);
|
|
202
|
+
} catch (err) {
|
|
203
|
+
console.error(err.code, err.message);
|
|
204
|
+
}
|
|
112
205
|
```
|
|
113
206
|
|
|
114
|
-
##
|
|
207
|
+
## How transfers work
|
|
208
|
+
|
|
209
|
+
- **Plain HTTP, no WebSocket.** Control commands (listing, metadata) and data
|
|
210
|
+
share the same transport, so proxies and CDNs behave predictably.
|
|
211
|
+
- **Downloads** — `HEAD` for the authoritative size/ETag, then parallel
|
|
212
|
+
`Range` GETs (`downloadWindow`), reordered in the engine and streamed to
|
|
213
|
+
disk in order. Each range retries independently; `Range`/`If-Range`/`416`
|
|
214
|
+
give resume against the server ETag. Files at or below 512 KiB stay on the
|
|
215
|
+
sequential path.
|
|
216
|
+
- **Uploads** — slice each file, compress each chunk into zrip frames, probe
|
|
217
|
+
the server's received ranges (`x-libfw-session-status`), POST only the
|
|
218
|
+
missing chunks with their absolute offset (out of order), then commit with
|
|
219
|
+
`x-libfw-final: 1`. A commit that fails re-probes and refills rather than
|
|
220
|
+
failing the task.
|
|
221
|
+
- **State machine** — `idle → downloading/uploading → paused → resumed →
|
|
222
|
+
completed/failed`. `pause()` stops scheduling new work; in-flight requests
|
|
223
|
+
are allowed to finish.
|
|
224
|
+
|
|
225
|
+
## Resume and page refresh
|
|
226
|
+
|
|
227
|
+
- Resume records (`etag`, `offset`, `size`) live in IndexedDB, keyed per
|
|
228
|
+
path and direction, and are revalidated on every retry. `clearResumeStore`
|
|
229
|
+
wipes them.
|
|
230
|
+
- **Download resume requires a real partial file**: `downloadMode: 'fs'`
|
|
231
|
+
(or an injected `directoryHandle`). A hard refresh runs no cleanup code,
|
|
232
|
+
so `createWritable()` would otherwise discard the `.crswap` and the target
|
|
233
|
+
would be 0 bytes. The SDK therefore **checkpoints**: whenever the engine
|
|
234
|
+
reports a durable offset (about every 4 MiB) it closes the writable and
|
|
235
|
+
reopens it with `keepExistingData` + `seek`, so a reload resumes from the
|
|
236
|
+
last checkpoint. Worst-case loss on a hard kill is one checkpoint
|
|
237
|
+
interval. The in-memory `'browser'` fallback always restarts from 0.
|
|
238
|
+
- **Upload resume** works because the session temp lives on the server and
|
|
239
|
+
the session id is the file's ETag (size + mtime): a reloaded page probes
|
|
240
|
+
the same session and sends only the missing chunks. A request whose
|
|
241
|
+
connection dies mid-body keeps the blocks already received.
|
|
242
|
+
|
|
243
|
+
## Download modes and ZIP fallback
|
|
244
|
+
|
|
245
|
+
| `downloadMode` | Behavior |
|
|
246
|
+
| --- | --- |
|
|
247
|
+
| `'fs'` | stream to disk via `showDirectoryPicker` / `createWritable`; folders are recreated; resumable |
|
|
248
|
+
| `'browser'` | buffer in memory, then trigger a normal browser download; folders become a `.zip`; not resumable |
|
|
249
|
+
| `'auto'` (default) | `'fs'` when the API exists, otherwise `'browser'` |
|
|
250
|
+
|
|
251
|
+
In `'browser'` mode each file is pre-checked against `maxFallbackBytes`
|
|
252
|
+
(512 MiB by default) and rejected with `too-large` rather than risking an
|
|
253
|
+
OOM.
|
|
254
|
+
|
|
255
|
+
The ZIP writer is dependency-free and emits UTF-8 entry names with the
|
|
256
|
+
general-purpose bit 11 (EFS) set, so CJK and other non-ASCII folder names
|
|
257
|
+
extract correctly on Windows, macOS and Linux. Illegal filesystem characters
|
|
258
|
+
are sanitized; `..` and drive-like segments are rejected.
|
|
259
|
+
|
|
260
|
+
## Adaptive tuning
|
|
261
|
+
|
|
262
|
+
With `autoTune: true` the engine fetches `/capabilities`, starts at the
|
|
263
|
+
advertised minimums and ramps the per-file window, then cross-file
|
|
264
|
+
concurrency, from 1-second EWMA measurements. The chunk size follows the
|
|
265
|
+
measured throughput (~100 ms of data, clamped into the advertised range); the
|
|
266
|
+
zrip level is a policy, never ramped. Errors halve the parameters and require
|
|
267
|
+
two stable windows before settling.
|
|
268
|
+
|
|
269
|
+
A settle is reused by later transfers in the same client **and** cached in
|
|
270
|
+
`localStorage`:
|
|
271
|
+
|
|
272
|
+
- Key: `libfw.tune.v1.<upload|download>.<origin>`.
|
|
273
|
+
- Tagged with the `/capabilities` hash; a changed advertisement invalidates it.
|
|
274
|
+
- Expires `tuneTtlMs` after the ramp settled (not after the last reuse), so a
|
|
275
|
+
link measured long ago is re-measured even if it is used constantly.
|
|
276
|
+
- Discarded on transfer failure.
|
|
277
|
+
- Storage failures (private mode, quota) are swallowed: caching is an
|
|
278
|
+
optimization and never fails a transfer.
|
|
279
|
+
|
|
280
|
+
`tuneTtlMs: 0` disables the cache entirely, so every transfer re-ramps.
|
|
281
|
+
|
|
282
|
+
A server without `/capabilities` (for example the actix example, which omits
|
|
283
|
+
the route) disables tuning and the configured static values are used as-is.
|
|
284
|
+
|
|
285
|
+
## Building the package
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
# from the repo root
|
|
289
|
+
wasm-pack build crates/libfw-client --target web --out-dir ../../sdk/pkg --release
|
|
290
|
+
|
|
291
|
+
# optional UMD bundle (rollup)
|
|
292
|
+
npm --prefix sdk run build:umd
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Layout produced:
|
|
296
|
+
|
|
297
|
+
```text
|
|
298
|
+
sdk/
|
|
299
|
+
index.js ESM SDK
|
|
300
|
+
index.d.ts TypeScript types
|
|
301
|
+
zip.js dependency-free ZIP writer
|
|
302
|
+
pkg/ wasm-pack output (wasm + wasm-bindgen glue)
|
|
303
|
+
dist/ UMD bundle (after build:umd)
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
The demo server serves this directory at `/sdk/*`, so the page can import
|
|
307
|
+
`/sdk/index.js` directly during development.
|
|
308
|
+
|
|
309
|
+
## Browser support and security
|
|
115
310
|
|
|
116
|
-
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
advertised minimum (least CPU, worst ratio), `'balanced'` the advertised
|
|
129
|
-
default, `'max'` the advertised maximum (best ratio); a number is clamped
|
|
130
|
-
into the advertised range. `'auto'` additionally micro-benchmarks the
|
|
131
|
-
advertised range against a real sample of the first uploaded file (while
|
|
132
|
-
`autoTune` is enabled) and picks the best bytes-saved-vs-CPU-time
|
|
133
|
-
trade-off for the measured link speed; downloads request the resolved
|
|
134
|
-
level from the server.
|
|
135
|
-
- `downloadMode: 'auto' | 'fs' | 'browser'` (default `'auto'`) — `'fs'`
|
|
136
|
-
streams downloads through the File System Access API; `'browser'` buffers
|
|
137
|
-
and triggers a traditional browser download (folders become `.zip`);
|
|
138
|
-
`'auto'` uses `'fs'` when the API exists and falls back to `'browser'`.
|
|
139
|
-
**Download resume requires `'fs'`** (or an injected `directoryHandle`):
|
|
140
|
-
an interrupted fs-mode download is continued from the bytes already on
|
|
141
|
-
disk, while the memory-backed `'browser'` fallback always restarts from
|
|
142
|
-
byte 0 — there is no partial file to continue from.
|
|
143
|
-
- `maxFallbackBytes: number` (default `536870912`, 512 MiB) — memory cap
|
|
144
|
-
for the in-memory `'browser'` fallback. File sizes are pre-checked
|
|
145
|
-
against it before buffering; a download that would exceed it rejects
|
|
146
|
-
with a `too-large` `LibfwError` instead of risking an OOM. `0` disables.
|
|
147
|
-
- `autoTune: boolean` (default `false`) — enable the adaptive tuning
|
|
148
|
-
engine. The engine probes the server's `/capabilities` limits and
|
|
149
|
-
TCP-style ramps the per-file window and cross-file concurrency from the
|
|
150
|
-
advertised minimums using real transfer stats; the chunk size follows the
|
|
151
|
-
measured throughput (~100 ms of it, clamped into the advertised range) and
|
|
152
|
-
the zrip level is a client policy from `compressLevel`, never ramped. When
|
|
153
|
-
disabled, the configured static values are used as-is. Tuning state is
|
|
154
|
-
**in memory** for the lifetime of the client (a settle is reused by later
|
|
155
|
-
transfers and dropped on failure) **and** is cached in `localStorage` per
|
|
156
|
-
origin + direction, so a page refresh does not re-ramp — see `tuneTtlMs`.
|
|
157
|
-
- `tuneTtlMs: number` (default `3600000`, 1 hour) — how long a cached
|
|
158
|
-
tuning result stays usable. The cache is keyed by origin **and**
|
|
159
|
-
direction (an upload settle says nothing about a download), is tagged with
|
|
160
|
-
the `/capabilities` it was measured against, and expires `tuneTtlMs`
|
|
161
|
-
*after the ramp settled* — not after the last reuse — so a link measured
|
|
162
|
-
long ago is re-measured even if it is used constantly. An entry is also
|
|
163
|
-
discarded early when the capabilities change or a transfer fails. `0`
|
|
164
|
-
disables the cache entirely (every transfer re-ramps). Ignored unless
|
|
165
|
-
`autoTune` is enabled. Storage failures (private mode, quota, disabled
|
|
166
|
-
storage) are swallowed: caching is an optimisation and never fails a
|
|
167
|
-
transfer.
|
|
168
|
-
- `downloadFolder(token, dirPath?) → Promise<number>`
|
|
169
|
-
- `downloadFile(token, filePath) → Promise<number>`
|
|
170
|
-
- `upload(token, files?) → Promise<number>`
|
|
171
|
-
- `clearResumeStore(direction?) → Promise<number>`
|
|
172
|
-
- `pause()`, `resume()`, `cancel()`
|
|
173
|
-
- `state()`, `progress()`, `doneBytes()`, `totalBytes()`
|
|
174
|
-
- `tuneStatus() → { phase, params, stats, capsHash } | null` — live
|
|
175
|
-
adaptive-tuning status. `phase` is `uninitialized | ramping | settled |
|
|
176
|
-
degraded`; `params` is `{ concurrency, uploadWindow, downloadWindow,
|
|
177
|
-
chunkSize, compressLevel }` (the zrip level is the resolved *policy*, i.e.
|
|
178
|
-
what downloads request — uploads may use an `'auto'`-benchmarked level for
|
|
179
|
-
the session); `stats` is
|
|
180
|
-
`{ rttMs, mbps }` (EWMA request RTT, last-window throughput). `null`
|
|
181
|
-
until the WASM engine is initialised.
|
|
182
|
-
- Events: with `autoTune` enabled, `onEvent` additionally receives
|
|
183
|
-
`{ type: 'tuning', phase, params, stats }` on every phase transition /
|
|
184
|
-
window evaluation.
|
|
185
|
-
- Errors: every rejection is a `LibfwError` with a stable `code`.
|
|
186
|
-
|
|
187
|
-
See `index.d.ts` for the full type surface.
|
|
311
|
+
- **Chromium-based browsers** for anything that needs
|
|
312
|
+
`showDirectoryPicker` / `createWritable` (folder download/upload,
|
|
313
|
+
resumable downloads). `downloadMode: 'auto'` falls back to a plain browser
|
|
314
|
+
download elsewhere; explicit `'fs'` calls reject with `unsupported`.
|
|
315
|
+
- **Tokens** are passed per call, not stored by the SDK. Do not embed
|
|
316
|
+
long-lived tokens in public pages — issue short-lived ones from your
|
|
317
|
+
backend and let the page fetch them. libfw never issues tokens; see
|
|
318
|
+
[docs/authorization.md](../docs/authorization.md).
|
|
319
|
+
- **`/capabilities` is public** and must not contain sensitive data.
|
|
320
|
+
- The SDK writes to IndexedDB (resume records) and `localStorage` (tuning
|
|
321
|
+
cache); both are per-origin. `clearResumeStore()` removes resume records,
|
|
322
|
+
and `tuneTtlMs: 0` disables the tuning cache.
|
package/index.js
CHANGED
|
@@ -347,7 +347,7 @@ export class LibfwClient {
|
|
|
347
347
|
// ESM-only `import.meta.url` fallback is never exercised — that
|
|
348
348
|
// fallback throws when the SDK is bundled for a classic <script>/UMD
|
|
349
349
|
// context. See _wasmUrl() for how the URL is resolved. The
|
|
350
|
-
// `{ module_or_path }` object form is the glue's
|
|
350
|
+
// `{ module_or_path }` object form is the glue's supported API.
|
|
351
351
|
this._initPromise = init({ module_or_path: this._wasmUrl() }).catch((err) => {
|
|
352
352
|
this._initPromise = null;
|
|
353
353
|
throw toLibfwError(err);
|
|
@@ -746,7 +746,13 @@ export class LibfwClient {
|
|
|
746
746
|
*/
|
|
747
747
|
async _archiveName(path) {
|
|
748
748
|
const base = (await this._cleanPath(path)).split('/').pop() || 'download';
|
|
749
|
-
|
|
749
|
+
// Strip only genuinely illegal filesystem characters. `\w` must NOT be
|
|
750
|
+
// used as a whitelist here: it is ASCII-only, so every non-ASCII name
|
|
751
|
+
// (中文, кириллица, accents, …) collapsed to `_` and the archive came out
|
|
752
|
+
// as `_.zip`. Path traversal is already rejected by `_safeEntryName`.
|
|
753
|
+
// eslint-disable-next-line no-control-regex
|
|
754
|
+
const safe = base.replace(/[\u0000-\u001f<>:"/\\|?*]+/g, '_').trim();
|
|
755
|
+
return `${safe || 'download'}.zip`;
|
|
750
756
|
}
|
|
751
757
|
|
|
752
758
|
/**
|
|
@@ -1055,7 +1061,7 @@ export class LibfwClient {
|
|
|
1055
1061
|
if (!this._dirHandle) return null;
|
|
1056
1062
|
try {
|
|
1057
1063
|
// Same display-name mapping as `_ensureFileHandle` so a resume finds
|
|
1058
|
-
// the file
|
|
1064
|
+
// the file already written under its resolved (display) name.
|
|
1059
1065
|
const segments = splitPath(await this._safeEntryName(path));
|
|
1060
1066
|
if (segments.length === 0) return null;
|
|
1061
1067
|
let dir = this._dirHandle;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libfw-client",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.4.6",
|
|
4
|
+
"description": "libfw client for browsers, providing high performance file transfer capabilities using WebAssembly.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "index.js",
|
package/pkg/libfw_client.d.ts
CHANGED
|
@@ -103,11 +103,11 @@ export interface InitOutput {
|
|
|
103
103
|
readonly libfwclient_tune_state: (a: number) => any;
|
|
104
104
|
readonly libfwclient_upload: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
105
105
|
readonly start: () => void;
|
|
106
|
-
readonly
|
|
107
|
-
readonly
|
|
108
|
-
readonly
|
|
109
|
-
readonly
|
|
110
|
-
readonly
|
|
106
|
+
readonly wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___wasm_bindgen_fcaa1ccc421e504f___JsValue__core_37ee0ce0c4cd57d5___result__Result_____wasm_bindgen_fcaa1ccc421e504f___JsError___true_: (a: number, b: number, c: any) => [number, number];
|
|
107
|
+
readonly wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___js_sys_acd39e4161e779fb___Function_fn_wasm_bindgen_fcaa1ccc421e504f___JsValue_____wasm_bindgen_fcaa1ccc421e504f___sys__Undefined___js_sys_acd39e4161e779fb___Function_fn_wasm_bindgen_fcaa1ccc421e504f___JsValue_____wasm_bindgen_fcaa1ccc421e504f___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
|
|
108
|
+
readonly wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___wasm_bindgen_fcaa1ccc421e504f___JsValue______true_: (a: number, b: number, c: any) => void;
|
|
109
|
+
readonly wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___wasm_bindgen_fcaa1ccc421e504f___JsValue______true__2: (a: number, b: number, c: any) => void;
|
|
110
|
+
readonly wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke_______true_: (a: number, b: number) => void;
|
|
111
111
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
112
112
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
113
113
|
readonly __wbindgen_exn_store: (a: number) => void;
|
package/pkg/libfw_client.js
CHANGED
|
@@ -403,7 +403,7 @@ function __wbg_get_imports() {
|
|
|
403
403
|
const a = state0.a;
|
|
404
404
|
state0.a = 0;
|
|
405
405
|
try {
|
|
406
|
-
return
|
|
406
|
+
return wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___js_sys_acd39e4161e779fb___Function_fn_wasm_bindgen_fcaa1ccc421e504f___JsValue_____wasm_bindgen_fcaa1ccc421e504f___sys__Undefined___js_sys_acd39e4161e779fb___Function_fn_wasm_bindgen_fcaa1ccc421e504f___JsValue_____wasm_bindgen_fcaa1ccc421e504f___sys__Undefined_______true_(a, state0.b, arg0, arg1);
|
|
407
407
|
} finally {
|
|
408
408
|
state0.a = a;
|
|
409
409
|
}
|
|
@@ -437,7 +437,7 @@ function __wbg_get_imports() {
|
|
|
437
437
|
const a = state0.a;
|
|
438
438
|
state0.a = 0;
|
|
439
439
|
try {
|
|
440
|
-
return
|
|
440
|
+
return wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___js_sys_acd39e4161e779fb___Function_fn_wasm_bindgen_fcaa1ccc421e504f___JsValue_____wasm_bindgen_fcaa1ccc421e504f___sys__Undefined___js_sys_acd39e4161e779fb___Function_fn_wasm_bindgen_fcaa1ccc421e504f___JsValue_____wasm_bindgen_fcaa1ccc421e504f___sys__Undefined_______true_(a, state0.b, arg0, arg1);
|
|
441
441
|
} finally {
|
|
442
442
|
state0.a = a;
|
|
443
443
|
}
|
|
@@ -593,22 +593,22 @@ function __wbg_get_imports() {
|
|
|
593
593
|
}, arguments); },
|
|
594
594
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
595
595
|
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 206, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
596
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
596
|
+
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___wasm_bindgen_fcaa1ccc421e504f___JsValue__core_37ee0ce0c4cd57d5___result__Result_____wasm_bindgen_fcaa1ccc421e504f___JsError___true_);
|
|
597
597
|
return ret;
|
|
598
598
|
},
|
|
599
599
|
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
600
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
601
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
600
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 4, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
601
|
+
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___wasm_bindgen_fcaa1ccc421e504f___JsValue______true_);
|
|
602
602
|
return ret;
|
|
603
603
|
},
|
|
604
604
|
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
|
|
605
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("ProgressEvent")], shim_idx:
|
|
606
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
605
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("ProgressEvent")], shim_idx: 4, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
606
|
+
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___wasm_bindgen_fcaa1ccc421e504f___JsValue______true__2);
|
|
607
607
|
return ret;
|
|
608
608
|
},
|
|
609
609
|
__wbindgen_cast_0000000000000004: function(arg0, arg1) {
|
|
610
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx:
|
|
611
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
610
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 7, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
611
|
+
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke_______true_);
|
|
612
612
|
return ret;
|
|
613
613
|
},
|
|
614
614
|
__wbindgen_cast_0000000000000005: function(arg0) {
|
|
@@ -637,27 +637,27 @@ function __wbg_get_imports() {
|
|
|
637
637
|
};
|
|
638
638
|
}
|
|
639
639
|
|
|
640
|
-
function
|
|
641
|
-
wasm.
|
|
640
|
+
function wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke_______true_(arg0, arg1) {
|
|
641
|
+
wasm.wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke_______true_(arg0, arg1);
|
|
642
642
|
}
|
|
643
643
|
|
|
644
|
-
function
|
|
645
|
-
wasm.
|
|
644
|
+
function wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___wasm_bindgen_fcaa1ccc421e504f___JsValue______true_(arg0, arg1, arg2) {
|
|
645
|
+
wasm.wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___wasm_bindgen_fcaa1ccc421e504f___JsValue______true_(arg0, arg1, arg2);
|
|
646
646
|
}
|
|
647
647
|
|
|
648
|
-
function
|
|
649
|
-
wasm.
|
|
648
|
+
function wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___wasm_bindgen_fcaa1ccc421e504f___JsValue______true__2(arg0, arg1, arg2) {
|
|
649
|
+
wasm.wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___wasm_bindgen_fcaa1ccc421e504f___JsValue______true__2(arg0, arg1, arg2);
|
|
650
650
|
}
|
|
651
651
|
|
|
652
|
-
function
|
|
653
|
-
const ret = wasm.
|
|
652
|
+
function wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___wasm_bindgen_fcaa1ccc421e504f___JsValue__core_37ee0ce0c4cd57d5___result__Result_____wasm_bindgen_fcaa1ccc421e504f___JsError___true_(arg0, arg1, arg2) {
|
|
653
|
+
const ret = wasm.wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___wasm_bindgen_fcaa1ccc421e504f___JsValue__core_37ee0ce0c4cd57d5___result__Result_____wasm_bindgen_fcaa1ccc421e504f___JsError___true_(arg0, arg1, arg2);
|
|
654
654
|
if (ret[1]) {
|
|
655
655
|
throw takeFromExternrefTable0(ret[0]);
|
|
656
656
|
}
|
|
657
657
|
}
|
|
658
658
|
|
|
659
|
-
function
|
|
660
|
-
wasm.
|
|
659
|
+
function wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___js_sys_acd39e4161e779fb___Function_fn_wasm_bindgen_fcaa1ccc421e504f___JsValue_____wasm_bindgen_fcaa1ccc421e504f___sys__Undefined___js_sys_acd39e4161e779fb___Function_fn_wasm_bindgen_fcaa1ccc421e504f___JsValue_____wasm_bindgen_fcaa1ccc421e504f___sys__Undefined_______true_(arg0, arg1, arg2, arg3) {
|
|
660
|
+
wasm.wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___js_sys_acd39e4161e779fb___Function_fn_wasm_bindgen_fcaa1ccc421e504f___JsValue_____wasm_bindgen_fcaa1ccc421e504f___sys__Undefined___js_sys_acd39e4161e779fb___Function_fn_wasm_bindgen_fcaa1ccc421e504f___JsValue_____wasm_bindgen_fcaa1ccc421e504f___sys__Undefined_______true_(arg0, arg1, arg2, arg3);
|
|
661
661
|
}
|
|
662
662
|
|
|
663
663
|
const LibfwClientFinalization = (typeof FinalizationRegistry === 'undefined')
|
package/pkg/libfw_client_bg.wasm
CHANGED
|
Binary file
|
|
@@ -19,11 +19,11 @@ export const libfwclient_total_bytes: (a: number) => number;
|
|
|
19
19
|
export const libfwclient_tune_state: (a: number) => any;
|
|
20
20
|
export const libfwclient_upload: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
21
21
|
export const start: () => void;
|
|
22
|
-
export const
|
|
23
|
-
export const
|
|
24
|
-
export const
|
|
25
|
-
export const
|
|
26
|
-
export const
|
|
22
|
+
export const wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___wasm_bindgen_fcaa1ccc421e504f___JsValue__core_37ee0ce0c4cd57d5___result__Result_____wasm_bindgen_fcaa1ccc421e504f___JsError___true_: (a: number, b: number, c: any) => [number, number];
|
|
23
|
+
export const wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___js_sys_acd39e4161e779fb___Function_fn_wasm_bindgen_fcaa1ccc421e504f___JsValue_____wasm_bindgen_fcaa1ccc421e504f___sys__Undefined___js_sys_acd39e4161e779fb___Function_fn_wasm_bindgen_fcaa1ccc421e504f___JsValue_____wasm_bindgen_fcaa1ccc421e504f___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
|
|
24
|
+
export const wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___wasm_bindgen_fcaa1ccc421e504f___JsValue______true_: (a: number, b: number, c: any) => void;
|
|
25
|
+
export const wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke___wasm_bindgen_fcaa1ccc421e504f___JsValue______true__2: (a: number, b: number, c: any) => void;
|
|
26
|
+
export const wasm_bindgen_fcaa1ccc421e504f___convert__closures_____invoke_______true_: (a: number, b: number) => void;
|
|
27
27
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
28
28
|
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
29
29
|
export const __wbindgen_exn_store: (a: number) => void;
|
package/pkg/package.json
CHANGED
package/zip.js
CHANGED
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
* {@link createZip}. The archive uses the STORE method (no compression) —
|
|
7
7
|
* the SDK stays dependency-free (no deflate implementation) and CPU cost is
|
|
8
8
|
* negligible. Entries carry the full virtual path (with `/` separators), so
|
|
9
|
-
* extractors recreate the folder structure automatically.
|
|
9
|
+
* extractors recreate the folder structure automatically. Entry names are
|
|
10
|
+
* UTF-8 encoded and the EFS general purpose flag (bit 11) is set in both the
|
|
11
|
+
* local and central headers, so non-ASCII names survive extraction on any
|
|
12
|
+
* platform instead of being decoded with the local OEM code page.
|
|
10
13
|
*
|
|
11
14
|
* @module libfw/zip
|
|
12
15
|
*/
|
|
@@ -74,7 +77,9 @@ export function createZip(entries) {
|
|
|
74
77
|
const dv = new DataView(local.buffer);
|
|
75
78
|
dv.setUint32(0, 0x04034b50, true); // "PK\x03\x04"
|
|
76
79
|
dv.setUint16(4, 20, true); // version needed to extract
|
|
77
|
-
|
|
80
|
+
// Bit 11 (0x0800) = EFS: the name/comment are UTF-8. Entry names are
|
|
81
|
+
// always encoded with TextEncoder above, so the flag is unconditional.
|
|
82
|
+
dv.setUint16(6, 0x0800, true); // general purpose flags
|
|
78
83
|
dv.setUint16(8, 0, true); // compression method: STORE
|
|
79
84
|
dv.setUint16(10, 0, true); // last mod time
|
|
80
85
|
dv.setUint16(12, 0x0021, true); // last mod date (1980-01-01)
|
|
@@ -102,7 +107,7 @@ export function createZip(entries) {
|
|
|
102
107
|
dv.setUint32(0, 0x02014b50, true); // "PK\x01\x02"
|
|
103
108
|
dv.setUint16(4, 20, true); // version made by
|
|
104
109
|
dv.setUint16(6, 20, true); // version needed to extract
|
|
105
|
-
dv.setUint16(8,
|
|
110
|
+
dv.setUint16(8, 0x0800, true); // flags (bit 11 = EFS, UTF-8 names)
|
|
106
111
|
dv.setUint16(10, 0, true); // method: STORE
|
|
107
112
|
dv.setUint16(12, 0, true); // mod time
|
|
108
113
|
dv.setUint16(14, 0x0021, true); // mod date
|