-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose progress events from importer, blockstore and bitswap (#13)
Expose progress event types that are passed to `onProgress` callback passed to all operations.
- Loading branch information
1 parent
4c8d124
commit de78f4d
Showing
6 changed files
with
127 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* eslint-env mocha */ | ||
|
||
import { expect } from 'aegir/chai' | ||
import { createHeliaNode } from './fixtures/create-helia.js' | ||
import { createKuboNode } from './fixtures/create-kubo.js' | ||
import type { Helia } from '@helia/interface' | ||
import type { Controller } from 'ipfsd-ctl' | ||
import { UnixFS, unixfs } from '@helia/unixfs' | ||
import type { FileCandidate } from 'ipfs-unixfs-importer' | ||
import toBuffer from 'it-to-buffer' | ||
|
||
describe('unixfs bitswap interop', () => { | ||
let helia: Helia | ||
let unixFs: UnixFS | ||
let kubo: Controller | ||
|
||
beforeEach(async () => { | ||
helia = await createHeliaNode() | ||
unixFs = unixfs(helia) | ||
kubo = await createKuboNode() | ||
|
||
// connect helia to kubo | ||
await helia.libp2p.peerStore.addressBook.add(kubo.peer.id, kubo.peer.addresses) | ||
await helia.libp2p.dial(kubo.peer.id) | ||
}) | ||
|
||
afterEach(async () => { | ||
if (helia != null) { | ||
await helia.stop() | ||
} | ||
|
||
if (kubo != null) { | ||
await kubo.stop() | ||
} | ||
}) | ||
|
||
it('should add a large file to helia and fetch it from kubo', async () => { | ||
const chunkSize = 1024 * 1024 | ||
const size = chunkSize * 10 | ||
const input: Uint8Array[] = [] | ||
|
||
const candidate: FileCandidate = { | ||
content: (async function * () { | ||
for (let i = 0; i < size; i += chunkSize) { | ||
const buf = new Uint8Array(chunkSize) | ||
input.push(buf) | ||
|
||
yield buf | ||
} | ||
}()) | ||
} | ||
|
||
const cid = await unixFs.addFile(candidate) | ||
|
||
const bytes = await toBuffer(kubo.api.cat(cid)) | ||
|
||
expect(bytes).to.equalBytes(await toBuffer(input)) | ||
}) | ||
|
||
it('should add a large file to kubo and fetch it from helia', async () => { | ||
const chunkSize = 1024 * 1024 | ||
const size = chunkSize * 10 | ||
const input: Uint8Array[] = [] | ||
|
||
const candidate: FileCandidate = { | ||
content: (async function * () { | ||
for (let i = 0; i < size; i += chunkSize) { | ||
const buf = new Uint8Array(chunkSize) | ||
input.push(buf) | ||
|
||
yield buf | ||
} | ||
}()) | ||
} | ||
|
||
const { cid } = await kubo.api.add(candidate.content) | ||
|
||
const bytes = await toBuffer(unixFs.cat(cid)) | ||
|
||
expect(bytes).to.equalBytes(await toBuffer(input)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters