Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose blobStore.writerDriveId #219

Merged
merged 1 commit into from
Aug 24, 2023
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: 4 additions & 0 deletions src/blob-store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export class BlobStore {
throw new Error('Could not find a writer for the blobIndex namespace')
}

get writerDriveId() {
return this.#writer.key.toString('hex')
}

/**
* @param {string} driveId
*/
Expand Down
31 changes: 31 additions & 0 deletions tests/blob-store/blob-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,37 @@ test('blobStore.createWriteStream(blobId) and blobStore.createReadStream(blobId)
t.alike(bndlbuf, diskbuf, 'should be equal')
})

test('blobStore.writerDriveId', async (t) => {
{
const { blobStore } = await testenv()
const blobId = /** @type {const} */ ({
type: 'photo',
variant: 'original',
name: 'test-file',
})
const ws = blobStore.createWriteStream(blobId)
t.is(
ws.driveId,
blobStore.writerDriveId,
'writerDriveId is same as driveId used for createWriteStream'
)
}
{
const { blobStore } = await testenv()
const blobId = /** @type {const} */ ({
type: 'photo',
variant: 'original',
name: 'test-file',
})
const driveId = await blobStore.put(blobId, Buffer.from('hello'))
t.is(
driveId,
blobStore.writerDriveId,
'writerDriveId is same as driveId returned by put()'
)
}
})

// Tests:
// A) Downloads from peers connected when download() is first called
// B) Downloads from peers connected after download() is first called
Expand Down
Loading