Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ module.exports = class Hyperdrive extends ReadyResource {
dls.push(blobs.core.download({ start: b.blockOffset, length: b.blockLength }))
}

return new Download(dls)
return new Download(this, undefined, { downloads: dls })
}

async downloadRange(dbRanges, blobRanges) {
Expand All @@ -448,7 +448,7 @@ module.exports = class Hyperdrive extends ReadyResource {
dls.push(blobs.core.download(range))
}

return new Download(dls)
return new Download(this, undefined, { downloads: dls })
}

entries(range, opts) {
Expand Down
2 changes: 1 addition & 1 deletion lib/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = class Download extends ReadyResource {
this.drive = drive
this.folder = folder
this.options = options || {}
this.downloads = []
this.downloads = this.options.downloads || []
this.destroyed = false
this.ready().catch(noop)
}
Expand Down
58 changes: 25 additions & 33 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,8 @@ test('drive.download(filename, [options])', async (t) => {
}
})

test.skip('drive.downloadRange(dbRanges, blobRanges)', async (t) => {
const { drive, swarm, mirror, corestore } = await testenv(t)
test('drive.downloadRange(dbRanges, blobRanges)', async (t) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous test was testing something else entirely it seems. Your test makes more sense to me, but needs a good look from @mafintosh too because we're changing both the tests and the main logic, which is always dangerous.

Likewise for the other test

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()
Expand All @@ -755,31 +755,29 @@ test.skip('drive.downloadRange(dbRanges, blobRanges)', async (t) => {
mirror.swarm.join(drive.discoveryKey, { server: false, client: true })
await mirror.swarm.flush()

const blobs = await drive.getBlobs()
const nil = b4a.from('nil')
await drive.put('/file-a', Buffer.alloc(1024))
await drive.put('/file-b', Buffer.alloc(1024))
await drive.put('/file-c', Buffer.alloc(1024))

const fileBlocks = []
const blobBlocks = []
await drive.put('/0', nil)
fileBlocks.push(drive.core.length)
blobBlocks.push(blobs.core.length)
await drive.put('/1', nil)
await drive.put('/2', nil)
fileBlocks.push(drive.core.length)
blobBlocks.push(blobs.core.length)
await eventFlush()

const fileTelem = downloadShark(mirror.drive.core)
const blobTelem = downloadShark((await mirror.drive.getBlobs()).core)

const fileCount = fileTelem.count
const blobCount = blobTelem.count
const download = await mirror.drive.downloadRange(
[
{ start: 1, end: 2 },
{ start: 2, end: 3 }
],
[{ start: 0, end: 3 }]
)
await download.done()

await mirror.drive.get('/0')
t.is(blobCount, blobTelem.count)
t.is(fileCount, fileTelem.count)
t.is(fileTelem.count, 3)
t.is(blobTelem.count, 3)
})

test.skip('drive.downloadDiff(version, folder, [options])', async (t) => {
test('drive.downloadDiff(version, folder, [options])', async (t) => {
const { drive, swarm, mirror, corestore } = await testenv(t)
swarm.on('connection', (conn) => corestore.replicate(conn))
swarm.join(drive.discoveryKey, { server: true, client: false })
Expand All @@ -792,18 +790,18 @@ test.skip('drive.downloadDiff(version, folder, [options])', async (t) => {
const nil = b4a.from('nil')

await drive.put('/parent/child/0', nil)
await drive.put('/parent/sibling/0')
await drive.put('/parent/sibling/0', nil)
await drive.put('/parent/child/1', nil)
const version = drive.version
let version = drive.version

const filestelem = downloadShark(mirror.drive.core)
const blobstelem = downloadShark((await mirror.drive.getBlobs()).core)

const downloadDiff = await mirror.drive.downloadDiff(version, '/parent/child')
let downloadDiff = await mirror.drive.downloadDiff(version, '/parent/child')
await downloadDiff.done()

let filescount = filestelem.count
let blobscount = blobstelem.count
const filescount = filestelem.count
const blobscount = blobstelem.count

await mirror.drive.get('/parent/child/1')

Expand All @@ -812,16 +810,10 @@ test.skip('drive.downloadDiff(version, folder, [options])', async (t) => {

await drive.put('/parent/child/2', nil)

await mirror.drive.downloadDiff(version, '/parent/child')

t.is(blobscount + 1, blobstelem.count)

filescount = filestelem.count
blobscount = blobstelem.count

await mirror.drive.get('/parent/sibling/0')
version = drive.version
downloadDiff = await mirror.drive.downloadDiff(version, '/parent/child')
await downloadDiff.done()

t.is(filescount + 1, filestelem.count)
t.is(blobscount + 1, blobstelem.count)
})

Expand Down