libfw-client 0.1.0 → 0.1.1

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/index.js CHANGED
@@ -207,8 +207,8 @@ export class LibfwClient {
207
207
  onWriteChunk: (path, offset, data) => this._onWriteChunk(path, offset, data),
208
208
  onFileCompleted: (path) => this._emit({ type: 'fileCompleted', path }),
209
209
  onProgress: (done, total) => this._emit({ type: 'progress', done, total }),
210
- loadState: (path) => Idb.loadState(path),
211
- saveState: (path, state) => Idb.saveState(path, state),
210
+ loadState: (direction, path) => Idb.loadState(`${direction}:${path}`),
211
+ saveState: (direction, path, state) => Idb.saveState(`${direction}:${path}`, state),
212
212
  getFileList: () => this._getFileList(),
213
213
  readFile: (path, offset, length) => this._readFile(path, offset, length),
214
214
  log: (msg) => {
@@ -270,9 +270,16 @@ export class LibfwClient {
270
270
  if (!writable) {
271
271
  const handle = await this._ensureFileHandle(path);
272
272
  this._fileHandles.set(path, handle);
273
- // keepExistingData: true lets resumed downloads overwrite only the
274
- // tail without truncating the already-written prefix.
275
- writable = await handle.createWritable({ keepExistingData: true });
273
+ // Only a true resume (first chunk arrives at offset > 0) needs to
274
+ // keep the existing file's prefix. For a fresh download we open the
275
+ // writable WITHOUT keepExistingData, which truncates and lets us
276
+ // write sequentially. In real Chromium the keepExistingData +
277
+ // position-write path can leave empty target files behind a trail of
278
+ // orphaned `.crswap` swap files, so we avoid it unless required.
279
+ const isResume = offset > 0;
280
+ writable = await handle.createWritable(
281
+ isResume ? { keepExistingData: true } : undefined
282
+ );
276
283
  this._writables.set(path, writable);
277
284
  }
278
285
  await writable.write({ type: 'write', position: offset, data });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libfw-client",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "High-performance streaming file & folder transfer SDK for the browser (libfw WASM engine + File System Access API + IndexedDB resume).",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "type": "module",
Binary file
package/pkg/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "libfw-client",
3
3
  "type": "module",
4
4
  "description": "WASM engine + JS SDK for libfw browser clients",
5
- "version": "0.1.0",
5
+ "version": "0.1.1",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",