From 22d18a99804606715c8c987c8043a942f5924caa Mon Sep 17 00:00:00 2001 From: rafapaezbas Date: Fri, 26 Dec 2025 14:27:07 +0100 Subject: [PATCH 1/2] avoid unrequested eager downloads on downloadDiff and downloadRange --- lib/download.js | 12 +++++++----- test.js | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/download.js b/lib/download.js index 9202601..0a31c23 100644 --- a/lib/download.js +++ b/lib/download.js @@ -37,12 +37,14 @@ module.exports = class Download extends ReadyResource { // ignore } - for await (const entry of drive.list(this.folder, this.options)) { - const b = entry.value.blob - if (!b) continue + if (this.folder) { + for await (const entry of drive.list(this.folder, this.options)) { + const b = entry.value.blob + if (!b) continue - const blobs = await drive.getBlobs() - this.downloads.push(blobs.core.download({ start: b.blockOffset, length: b.blockLength })) + const blobs = await drive.getBlobs() + this.downloads.push(blobs.core.download({ start: b.blockOffset, length: b.blockLength })) + } } } diff --git a/test.js b/test.js index 6ddaeea..083945d 100644 --- a/test.js +++ b/test.js @@ -806,7 +806,7 @@ test('drive.downloadDiff(version, folder, [options])', async (t) => { await mirror.drive.get('/parent/child/1') t.is(filescount, filestelem.count) - t.is(blobscount, blobstelem.count) + t.is(blobscount + 1, blobstelem.count) await drive.put('/parent/child/2', nil) From 4e91bba96ab3cc69cc3a7d7be3504575ee38f8f9 Mon Sep 17 00:00:00 2001 From: rafapaezbas Date: Wed, 31 Dec 2025 13:17:23 +0100 Subject: [PATCH 2/2] explicit check of null in download folder --- index.js | 6 +++--- lib/download.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 3b96470..d181e27 100644 --- a/index.js +++ b/index.js @@ -430,7 +430,7 @@ module.exports = class Hyperdrive extends ReadyResource { dls.push(blobs.core.download({ start: b.blockOffset, length: b.blockLength })) } - return new Download(this, undefined, { downloads: dls }) + return new Download(this, null, { downloads: dls }) } async downloadRange(dbRanges, blobRanges) { @@ -448,7 +448,7 @@ module.exports = class Hyperdrive extends ReadyResource { dls.push(blobs.core.download(range)) } - return new Download(this, undefined, { downloads: dls }) + return new Download(this, null, { downloads: dls }) } entries(range, opts) { @@ -482,7 +482,7 @@ module.exports = class Hyperdrive extends ReadyResource { // atm always recursive, but we should add some depth thing to it list(folder, opts = {}) { - if (typeof folder === 'object') return this.list(undefined, folder) + if (typeof folder === 'object' && folder !== null) return this.list(undefined, folder) folder = std(folder || '/', true) diff --git a/lib/download.js b/lib/download.js index 0a31c23..6febf28 100644 --- a/lib/download.js +++ b/lib/download.js @@ -37,7 +37,7 @@ module.exports = class Download extends ReadyResource { // ignore } - if (this.folder) { + if (this.folder !== null) { for await (const entry of drive.list(this.folder, this.options)) { const b = entry.value.blob if (!b) continue