From c92546fbc16f3778c232f5f7bc57dc63c69e57a3 Mon Sep 17 00:00:00 2001 From: user Date: Tue, 23 Jun 2026 14:42:05 +0200 Subject: [PATCH 1/9] fix download of dedup entries --- lib/download.js | 48 ++++++++++++++++++++++++++++++------- test.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 9 deletions(-) diff --git a/lib/download.js b/lib/download.js index c7f54cd9..c0b9005a 100644 --- a/lib/download.js +++ b/lib/download.js @@ -14,6 +14,8 @@ module.exports = class Download extends ReadyResource { async _open() { const drive = this.drive + const blobs = await drive.getBlobs() + const entry = !this.folder || this.folder.endsWith('/') ? null @@ -22,11 +24,7 @@ module.exports = class Download extends ReadyResource { if (entry) { const b = entry.value.blob if (!b) return - const blobs = await drive.getBlobs() - const download = blobs.core.download({ - start: b.blockOffset, - length: b.blockLength - }) + const download = await this._downloadEntry(blobs, b) this.downloads.push(download) return } @@ -38,16 +36,48 @@ module.exports = class Download extends ReadyResource { // ignore } + const maps = [] + const entries = [] for await (const entry of drive.list(this.folder, this.options)) { - const b = entry.value.blob - if (!b) continue + const blob = entry.value.blob + if (!blob) continue + if (blob.blockMap && blob.blockLength) { + maps.push(blobs.core.download({ start: blob.blockOffset, length: blob.blockLength })) + } + entries.push(entry) // cache entries + } + + await Promise.all(maps.map((m) => m.done())) - const blobs = await drive.getBlobs() - this.downloads.push(blobs.core.download({ start: b.blockOffset, length: b.blockLength })) + for (const entry of entries) { + const blob = entry.value.blob + const download = await this._downloadEntry(blobs, blob) + this.downloads.push(download) } } } + async _downloadEntry(blobs, blob) { + if (blob.blockMap) { + const map = await blobs.getBlockMap(blob) + if (!map) return null + + const blocks = [] + for (const block of map.blocks) blocks.push(block.index) + + const download = blobs.core.download({ blocks }) + await download.ready() + return download + } else { + const download = blobs.core.download({ + start: blob.blockOffset, + length: blob.blockLength + }) + await download.ready() + return download + } + } + _close() { for (const d of this.downloads) { d.destroy() diff --git a/test.js b/test.js index 43b02292..9fe3177b 100644 --- a/test.js +++ b/test.js @@ -816,6 +816,70 @@ test('drive.downloadDiff(version, folder, [options])', async (t) => { t.is(blobscount, blobstelem.count) }) +test('drive.download dedup entry', async (t) => { + t.plan(2) + const { corestore, drive, swarm, mirror } = await testenv(t) + swarm.on('connection', (conn) => corestore.replicate(conn)) + swarm.join(drive.discoveryKey, { server: true, client: false }) + await swarm.flush() + + mirror.swarm.on('connection', (conn) => mirror.corestore.replicate(conn)) + mirror.swarm.join(drive.discoveryKey, { server: false, client: true }) + await mirror.swarm.flush() + + const ws = await drive.createWriteStream('/entry', { dedup: true }) + ws.write(Buffer.alloc(1024)) + ws.end() + + await ensureDbLength(mirror.drive, drive.version) + + const download = await mirror.drive.download('/entry') + await download.done() + + const mirrorBlobs = await mirror.drive.getBlobs() + const driveBlobs = await drive.getBlobs() + + const mirrorBlobsHash = await mirrorBlobs.core.treeHash() + const driveBlobsHash = await driveBlobs.core.treeHash() + + t.is(mirrorBlobs.core.contiguousLength, driveBlobs.core.contiguousLength) + t.is(mirrorBlobsHash.toString('hex'), driveBlobsHash.toString('hex')) +}) + +test('drive.download folder mixed dedup: true and dedup: false', async (t) => { + t.plan(2) + const { corestore, drive, swarm, mirror } = await testenv(t) + swarm.on('connection', (conn) => corestore.replicate(conn)) + swarm.join(drive.discoveryKey, { server: true, client: false }) + await swarm.flush() + + mirror.swarm.on('connection', (conn) => mirror.corestore.replicate(conn)) + mirror.swarm.join(drive.discoveryKey, { server: false, client: true }) + await mirror.swarm.flush() + + { + const ws = await drive.createWriteStream('/folder/entry', { dedup: true }) + ws.write(Buffer.alloc(1024)) + ws.end() + } + + await drive.put('/folder/entry-b', Buffer.from('hello world')) + + await ensureDbLength(mirror.drive, drive.version) + + const download = await mirror.drive.download('/folder') + await download.done() + + const mirrorBlobs = await mirror.drive.getBlobs() + const driveBlobs = await drive.getBlobs() + + const mirrorBlobsHash = await mirrorBlobs.core.treeHash() + const driveBlobsHash = await driveBlobs.core.treeHash() + + t.is(mirrorBlobs.core.contiguousLength, driveBlobs.core.contiguousLength) + t.is(mirrorBlobsHash.toString('hex'), driveBlobsHash.toString('hex')) +}) + test('drive.has(path)', async (t) => { t.plan(8) const { corestore, drive, swarm, mirror } = await testenv(t) From 39d3018b479d7338eed94b7a40771b1eeffb97cc Mon Sep 17 00:00:00 2001 From: user Date: Tue, 23 Jun 2026 14:45:34 +0200 Subject: [PATCH 2/9] tweak --- lib/download.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/download.js b/lib/download.js index c0b9005a..3211cf3c 100644 --- a/lib/download.js +++ b/lib/download.js @@ -22,9 +22,9 @@ module.exports = class Download extends ReadyResource { : await drive.entry(this.folder, this.options) if (entry) { - const b = entry.value.blob - if (!b) return - const download = await this._downloadEntry(blobs, b) + const blob = entry.value.blob + if (!blob) return + const download = await this._downloadEntry(blobs, blob) this.downloads.push(download) return } From 1116e01e61068f6849dafb44919e30579e1b2725 Mon Sep 17 00:00:00 2001 From: user Date: Tue, 23 Jun 2026 16:02:18 +0200 Subject: [PATCH 3/9] fixed has method --- index.js | 25 +++++++++++++++++++------ test.js | 26 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 94af115d..1d643054 100644 --- a/index.js +++ b/index.js @@ -484,16 +484,16 @@ module.exports = class Hyperdrive extends ReadyResource { const blobs = await this.getBlobs() const entry = !path || path.endsWith('/') ? null : await this.entry(path) if (entry) { - const b = entry.value.blob - if (!b) return false - return await blobs.core.has(b.blockOffset, b.blockOffset + b.blockLength) + const blob = entry.value.blob + if (!blob) return false + return await this._hasEntry(blobs, blob) } let isDir = false for await (const entry of this.list(path)) { isDir = true - const b = entry.value.blob - if (!b) continue - const has = await blobs.core.has(b.blockOffset, b.blockOffset + b.blockLength) + const blob = entry.value.blob + if (!blob) continue + const has = await this._hasEntry(blobs, blob) if (!has) return false } return isDir @@ -659,6 +659,19 @@ module.exports = class Hyperdrive extends ReadyResource { } } + async _hasEntry(blobs, blob) { + if (blob.blockMap) { + const map = await blobs.getBlockMap(blob) + for (const block of map.blocks) { + const has = await blobs.core.has(block.index) + if (!has) return false + } + return true + } else { + return await blobs.core.has(blob.blockOffset, blob.blockOffset + blob.blockLength) + } + } + static normalizePath(name) { return std(name, false) } diff --git a/test.js b/test.js index 9fe3177b..3da9effa 100644 --- a/test.js +++ b/test.js @@ -919,6 +919,32 @@ test('drive.has(path)', async (t) => { t.ok(await mirror.drive.has('/parent/sibling/grandchild1')) }) +test('drive.has dedup entry is false after getting the blockMap', async (t) => { + t.plan(1) + const { corestore, drive, swarm, mirror } = await testenv(t) + swarm.on('connection', (conn) => corestore.replicate(conn)) + swarm.join(drive.discoveryKey, { server: true, client: false }) + await swarm.flush() + + mirror.swarm.on('connection', (conn) => mirror.corestore.replicate(conn)) + mirror.swarm.join(drive.discoveryKey, { server: false, client: true }) + await mirror.swarm.flush() + + const ws = await drive.createWriteStream('/entry', { dedup: true }) + ws.write(Buffer.alloc(1024)) + ws.write(Buffer.alloc(1024)) + ws.write(Buffer.alloc(1024)) + ws.end() + + await ensureDbLength(mirror.drive, drive.version) + await mirror.drive.entry('/entry') + + await mirror.drive.getBlobs() + await mirror.drive.blobs.core.get(1) // get map block + + t.is(await mirror.drive.has('/entry'), false) +}) + test('drive.batch() & drive.flush()', async (t) => { const { drive } = await testenv(t) From d35803993effd0d75657de1f0031e624421af8fe Mon Sep 17 00:00:00 2001 From: rafapaezbas <15270736+rafapaezbas@users.noreply.github.com> Date: Wed, 24 Jun 2026 00:20:13 +0200 Subject: [PATCH 4/9] Apply suggestions from code review Co-authored-by: Sean Zellmer --- index.js | 4 ++-- test.js | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 1d643054..ab23465a 100644 --- a/index.js +++ b/index.js @@ -486,7 +486,7 @@ module.exports = class Hyperdrive extends ReadyResource { if (entry) { const blob = entry.value.blob if (!blob) return false - return await this._hasEntry(blobs, blob) + return this._hasEntry(blobs, blob) } let isDir = false for await (const entry of this.list(path)) { @@ -668,7 +668,7 @@ module.exports = class Hyperdrive extends ReadyResource { } return true } else { - return await blobs.core.has(blob.blockOffset, blob.blockOffset + blob.blockLength) + return blobs.core.has(blob.blockOffset, blob.blockOffset + blob.blockLength) } } diff --git a/test.js b/test.js index 3da9effa..9eedea0a 100644 --- a/test.js +++ b/test.js @@ -827,13 +827,13 @@ test('drive.download dedup entry', async (t) => { mirror.swarm.join(drive.discoveryKey, { server: false, client: true }) await mirror.swarm.flush() - const ws = await drive.createWriteStream('/entry', { dedup: true }) + const ws = drive.createWriteStream('/entry', { dedup: true }) ws.write(Buffer.alloc(1024)) ws.end() await ensureDbLength(mirror.drive, drive.version) - const download = await mirror.drive.download('/entry') + const download = mirror.drive.download('/entry') await download.done() const mirrorBlobs = await mirror.drive.getBlobs() @@ -843,7 +843,7 @@ test('drive.download dedup entry', async (t) => { const driveBlobsHash = await driveBlobs.core.treeHash() t.is(mirrorBlobs.core.contiguousLength, driveBlobs.core.contiguousLength) - t.is(mirrorBlobsHash.toString('hex'), driveBlobsHash.toString('hex')) + t.alike(mirrorBlobsHash, driveBlobsHash, 'blob hashes match') }) test('drive.download folder mixed dedup: true and dedup: false', async (t) => { @@ -858,7 +858,7 @@ test('drive.download folder mixed dedup: true and dedup: false', async (t) => { await mirror.swarm.flush() { - const ws = await drive.createWriteStream('/folder/entry', { dedup: true }) + const ws = drive.createWriteStream('/folder/entry', { dedup: true }) ws.write(Buffer.alloc(1024)) ws.end() } @@ -867,7 +867,7 @@ test('drive.download folder mixed dedup: true and dedup: false', async (t) => { await ensureDbLength(mirror.drive, drive.version) - const download = await mirror.drive.download('/folder') + const download = mirror.drive.download('/folder') await download.done() const mirrorBlobs = await mirror.drive.getBlobs() @@ -877,7 +877,7 @@ test('drive.download folder mixed dedup: true and dedup: false', async (t) => { const driveBlobsHash = await driveBlobs.core.treeHash() t.is(mirrorBlobs.core.contiguousLength, driveBlobs.core.contiguousLength) - t.is(mirrorBlobsHash.toString('hex'), driveBlobsHash.toString('hex')) + t.alike(mirrorBlobsHash, driveBlobsHash, 'blob hashes match') }) test('drive.has(path)', async (t) => { @@ -930,7 +930,7 @@ test('drive.has dedup entry is false after getting the blockMap', async (t) => { mirror.swarm.join(drive.discoveryKey, { server: false, client: true }) await mirror.swarm.flush() - const ws = await drive.createWriteStream('/entry', { dedup: true }) + const ws = drive.createWriteStream('/entry', { dedup: true }) ws.write(Buffer.alloc(1024)) ws.write(Buffer.alloc(1024)) ws.write(Buffer.alloc(1024)) @@ -942,7 +942,7 @@ test('drive.has dedup entry is false after getting the blockMap', async (t) => { await mirror.drive.getBlobs() await mirror.drive.blobs.core.get(1) // get map block - t.is(await mirror.drive.has('/entry'), false) + t.absent(await mirror.drive.has('/entry'), 'has() is false w/ map, but w/o blocks') }) test('drive.batch() & drive.flush()', async (t) => { From 3a64e2e2c74f62572c3d17448e5f934a6167695e Mon Sep 17 00:00:00 2001 From: rafapaezbas Date: Fri, 26 Jun 2026 12:42:05 +0200 Subject: [PATCH 5/9] correct has method to do only local check --- index.js | 3 +++ test.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/index.js b/index.js index ab23465a..f2d26e7d 100644 --- a/index.js +++ b/index.js @@ -661,6 +661,9 @@ module.exports = class Hyperdrive extends ReadyResource { async _hasEntry(blobs, blob) { if (blob.blockMap) { + const hasMap = await blobs.core.has(blob.blockOffset, blob.blockOffset + blob.blockLength) + if (!hasMap) return false + const map = await blobs.getBlockMap(blob) for (const block of map.blocks) { const has = await blobs.core.has(block.index) diff --git a/test.js b/test.js index 9eedea0a..fdd5e845 100644 --- a/test.js +++ b/test.js @@ -945,6 +945,54 @@ test('drive.has dedup entry is false after getting the blockMap', async (t) => { t.absent(await mirror.drive.has('/entry'), 'has() is false w/ map, but w/o blocks') }) +test('drive.has dedup entry does not download block map', async (t) => { + t.plan(3) + + const { corestore, drive, mirror } = await testenv(t) + + const s1 = corestore.replicate(true) + const s2 = mirror.corestore.replicate(false) + s1.pipe(s2).pipe(s1) + + t.teardown(() => { + s1.destroy() + s2.destroy() + }) + + const ws = drive.createWriteStream('/entry', { dedup: true }) + const done = new Promise((resolve, reject) => { + ws.once('error', reject) + ws.once('finish', resolve) + }) + + ws.write(Buffer.alloc(1024)) + ws.write(Buffer.alloc(1024)) + ws.end() + await done + + await ensureDbLength(mirror.drive, drive.version) + + const entry = await mirror.drive.entry('/entry') + const blob = entry.value.blob + const blobs = await mirror.drive.getBlobs() + + t.absent( + await blobs.core.has(blob.blockOffset, blob.blockOffset + blob.blockLength), + 'sanity: block map is not local before has()' + ) + + let downloads = 0 + blobs.core.on('download', ondownload) + t.teardown(() => blobs.core.off('download', ondownload)) + + t.absent(await mirror.drive.has('/entry'), 'entry data is not local') + t.is(downloads, 0, 'has() should not download while checking local state') + + function ondownload() { + downloads++ + } +}) + test('drive.batch() & drive.flush()', async (t) => { const { drive } = await testenv(t) From 921cc775ef76e2f94af2ca886f6e8e8d5146078a Mon Sep 17 00:00:00 2001 From: rafapaezbas Date: Fri, 26 Jun 2026 13:26:56 +0200 Subject: [PATCH 6/9] adapted donwloadDiff to dedup blobs --- index.js | 6 +++--- lib/download.js | 6 +++--- test.js | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index f2d26e7d..ca0a60e5 100644 --- a/index.js +++ b/index.js @@ -441,10 +441,10 @@ module.exports = class Hyperdrive extends ReadyResource { for await (const entry of this.diff(length, folder, opts)) { if (!entry.left) continue - const b = entry.left.value.blob - if (!b) continue + const blob = entry.left.value.blob + if (!blob) continue const blobs = await this.getBlobs() - dls.push(blobs.core.download({ start: b.blockOffset, length: b.blockLength })) + dls.push(await Download.downloadEntry(blobs, blob)) } return new Download(this, null, { downloads: dls }) diff --git a/lib/download.js b/lib/download.js index 3211cf3c..72bc2e32 100644 --- a/lib/download.js +++ b/lib/download.js @@ -24,7 +24,7 @@ module.exports = class Download extends ReadyResource { if (entry) { const blob = entry.value.blob if (!blob) return - const download = await this._downloadEntry(blobs, blob) + const download = await this.constructor.downloadEntry(blobs, blob) this.downloads.push(download) return } @@ -51,13 +51,13 @@ module.exports = class Download extends ReadyResource { for (const entry of entries) { const blob = entry.value.blob - const download = await this._downloadEntry(blobs, blob) + const download = await this.constructor.downloadEntry(blobs, blob) this.downloads.push(download) } } } - async _downloadEntry(blobs, blob) { + static async downloadEntry(blobs, blob) { if (blob.blockMap) { const map = await blobs.getBlockMap(blob) if (!map) return null diff --git a/test.js b/test.js index fdd5e845..d8ed4586 100644 --- a/test.js +++ b/test.js @@ -117,7 +117,7 @@ test('drive.createWriteStream(path) and drive.createReadStream(path)', async (t) drive.createReadStream(__filename), new Writable({ write(data, cb) { - if (bndlbuf) bndlbuf = b4a.concat(bndlbuf, data) + if (bndlbuf) bndlbuf = b4a.concat([bndlbuf, data]) else bndlbuf = data return cb(null) } @@ -816,6 +816,39 @@ test('drive.downloadDiff(version, folder, [options])', async (t) => { t.is(blobscount, blobstelem.count) }) +test('drive.downloadDiff dedup entry', async (t) => { + t.plan(2) + const { corestore, drive, swarm, mirror } = await testenv(t) + swarm.on('connection', (conn) => corestore.replicate(conn)) + swarm.join(drive.discoveryKey, { server: true, client: false }) + await swarm.flush() + mirror.swarm.on('connection', (conn) => mirror.corestore.replicate(conn)) + mirror.swarm.join(drive.discoveryKey, { server: false, client: true }) + await mirror.swarm.flush() + + const version = drive.version + + const ws = drive.createWriteStream('/folder/entry', { dedup: true }) + ws.write(Buffer.alloc(1024)) + ws.write(Buffer.alloc(1024)) + ws.write(Buffer.alloc(1024)) + ws.end() + + await new Promise((resolve) => ws.once('finish', resolve)) + await ensureDbLength(mirror.drive, drive.version) + + const download = await mirror.drive.downloadDiff(version, '/folder') + await download.done() + + const mirrorBlobs = await mirror.drive.getBlobs() + const driveBlobs = await drive.getBlobs() + const mirrorBlobsHash = await mirrorBlobs.core.treeHash() + const driveBlobsHash = await driveBlobs.core.treeHash() + + t.is(mirrorBlobs.core.contiguousLength, driveBlobs.core.contiguousLength) + t.alike(mirrorBlobsHash, driveBlobsHash, 'blob hashes match') +}) + test('drive.download dedup entry', async (t) => { t.plan(2) const { corestore, drive, swarm, mirror } = await testenv(t) From a2b682c621228a00c21a60b85078ba415a236582 Mon Sep 17 00:00:00 2001 From: rafapaezbas Date: Mon, 29 Jun 2026 15:13:19 +0200 Subject: [PATCH 7/9] improved download life-cycle --- lib/download.js | 32 +++++++++++++++++++++++++++----- test.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/lib/download.js b/lib/download.js index 72bc2e32..239daa77 100644 --- a/lib/download.js +++ b/lib/download.js @@ -8,7 +8,9 @@ module.exports = class Download extends ReadyResource { this.folder = folder this.options = options || {} this.downloads = this.options.downloads || [] - this.destroyed = false + this._cancelled = new Promise((resolve) => { + this._cancel = resolve + }) this.ready().catch(noop) } @@ -24,6 +26,12 @@ module.exports = class Download extends ReadyResource { if (entry) { const blob = entry.value.blob if (!blob) return + + const mapDownload = await this._cancellableDownload( + this.constructor.downloadEntryMap(blobs, blob) + ) + if (!mapDownload) return + const download = await this.constructor.downloadEntry(blobs, blob) this.downloads.push(download) return @@ -47,7 +55,8 @@ module.exports = class Download extends ReadyResource { entries.push(entry) // cache entries } - await Promise.all(maps.map((m) => m.done())) + const results = await Promise.all(maps.map((m) => this._cancellableDownload(m))) + if (results.includes(false)) return // if true, it means the Download got cancelled for (const entry of entries) { const blob = entry.value.blob @@ -57,11 +66,13 @@ module.exports = class Download extends ReadyResource { } } + static downloadEntryMap(blobs, blob) { + return blobs.core.download({ start: blob.blockOffset, length: blob.blockLength }) + } + static async downloadEntry(blobs, blob) { if (blob.blockMap) { - const map = await blobs.getBlockMap(blob) - if (!map) return null - + const map = await blobs.getBlockMap(blob) // always called after downloadEntryMap, so its non-blocking const blocks = [] for (const block of map.blocks) blocks.push(block.index) @@ -78,6 +89,16 @@ module.exports = class Download extends ReadyResource { } } + async _cancellableDownload(download) { + return Promise.race([ + download.done().then(() => true), + this._cancelled.then(() => { + download.destroy() + return false + }) + ]) + } + _close() { for (const d of this.downloads) { d.destroy() @@ -86,6 +107,7 @@ module.exports = class Download extends ReadyResource { destroy() { this.destroyed = true + this._cancel() this._safeBackgroundDestroy() } diff --git a/test.js b/test.js index d8ed4586..1c867b3c 100644 --- a/test.js +++ b/test.js @@ -816,6 +816,38 @@ test('drive.downloadDiff(version, folder, [options])', async (t) => { t.is(blobscount, blobstelem.count) }) +test('dedup download can be destroyed while block map is unavailable', async (t) => { + t.plan(1) + + const { corestore, drive, mirror } = await testenv(t) + + const s1 = corestore.replicate(true) + const s2 = mirror.corestore.replicate(false) + s1.pipe(s2).pipe(s1) + + const ws = drive.createWriteStream('/entry', { dedup: true }) + ws.write(Buffer.alloc(1024)) + ws.write(Buffer.alloc(1024)) + ws.end() + + await new Promise((resolve, reject) => { + ws.once('error', reject) + ws.once('finish', resolve) + }) + + await ensureDbLength(mirror.drive, drive.version) + await mirror.drive.entry('/entry') + + s1.destroy() + s2.destroy() + + const download = mirror.drive.download('/entry') + download.destroy() + + await download.close() + t.pass('download closed') +}) + test('drive.downloadDiff dedup entry', async (t) => { t.plan(2) const { corestore, drive, swarm, mirror } = await testenv(t) From 9056fa9850d86b4e7ef15894a60b7299f9a79d30 Mon Sep 17 00:00:00 2001 From: rafapaezbas Date: Mon, 29 Jun 2026 16:37:18 +0200 Subject: [PATCH 8/9] added test for folder download destroy --- test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test.js b/test.js index 1c867b3c..fb1bc61e 100644 --- a/test.js +++ b/test.js @@ -848,6 +848,30 @@ test('dedup download can be destroyed while block map is unavailable', async (t) t.pass('download closed') }) +test('download can be destroyed before _open completes (folder)', async (t) => { + t.plan(1) + const { corestore, drive, mirror } = await testenv(t) + + const s1 = corestore.replicate(true) + const s2 = mirror.corestore.replicate(false) + s1.pipe(s2).pipe(s1) + + await drive.put('/folder/a', Buffer.alloc(1024)) + await drive.put('/folder/b', Buffer.alloc(1024)) + + await ensureDbLength(mirror.drive, drive.version) + await mirror.drive.entry('/folder/a') + + s1.destroy() + s2.destroy() + + const download = mirror.drive.download('/folder') + download.destroy() + await download.close() + + t.pass('folder download closed cleanly') +}) + test('drive.downloadDiff dedup entry', async (t) => { t.plan(2) const { corestore, drive, swarm, mirror } = await testenv(t) From ca7e09d1e4443ba8a8b3e9263e6f5fe07557db26 Mon Sep 17 00:00:00 2001 From: rafapaezbas Date: Mon, 29 Jun 2026 19:03:41 +0200 Subject: [PATCH 9/9] removed comments --- lib/download.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/download.js b/lib/download.js index 239daa77..353dac11 100644 --- a/lib/download.js +++ b/lib/download.js @@ -56,7 +56,7 @@ module.exports = class Download extends ReadyResource { } const results = await Promise.all(maps.map((m) => this._cancellableDownload(m))) - if (results.includes(false)) return // if true, it means the Download got cancelled + if (results.includes(false)) return for (const entry of entries) { const blob = entry.value.blob @@ -72,7 +72,7 @@ module.exports = class Download extends ReadyResource { static async downloadEntry(blobs, blob) { if (blob.blockMap) { - const map = await blobs.getBlockMap(blob) // always called after downloadEntryMap, so its non-blocking + const map = await blobs.getBlockMap(blob) const blocks = [] for (const block of map.blocks) blocks.push(block.index)