11/* eslint-env mocha */
22
3- import { type AddOptions , type UnixFS , unixfs } from '@helia/unixfs'
3+ import { unixfs } from '@helia/unixfs'
44import { expect } from 'aegir/chai'
55import { fixedSize } from 'ipfs-unixfs-importer/chunker'
66import { balanced } from 'ipfs-unixfs-importer/layout'
77import { CID } from 'multiformats/cid'
88import { createHeliaNode } from './fixtures/create-helia.js'
99import { createKuboNode } from './fixtures/create-kubo.js'
10+ import type { AddOptions , UnixFS } from '@helia/unixfs'
1011import type { HeliaLibp2p } from 'helia'
11- import type { FileCandidate } from 'ipfs-unixfs-importer'
12+ import type { ByteStream } from 'ipfs-unixfs-importer'
1213import type { KuboNode } from 'ipfsd-ctl'
1314import type { AddOptions as KuboAddOptions } from 'kubo-rpc-client'
1415
@@ -17,19 +18,19 @@ describe('@helia/unixfs - files', () => {
1718 let unixFs : UnixFS
1819 let kubo : KuboNode
1920
20- async function importToHelia ( data : FileCandidate , opts ?: Partial < AddOptions > ) : Promise < CID > {
21- const cid = await unixFs . addFile ( data , opts )
21+ async function importToHelia ( data : ByteStream , opts ?: Partial < AddOptions > ) : Promise < CID > {
22+ const cid = await unixFs . addByteStream ( data , opts )
2223
2324 return cid
2425 }
2526
26- async function importToKubo ( data : FileCandidate , opts ?: KuboAddOptions ) : Promise < CID > {
27- const result = await kubo . api . add ( data . content , opts )
27+ async function importToKubo ( data : ByteStream , opts ?: KuboAddOptions ) : Promise < CID > {
28+ const result = await kubo . api . add ( data , opts )
2829
2930 return CID . parse ( result . cid . toString ( ) )
3031 }
3132
32- async function expectSameCid ( data : ( ) => FileCandidate , heliaOpts : Partial < AddOptions > = { } , kuboOpts : KuboAddOptions = { } ) : Promise < void > {
33+ async function expectSameCid ( data : ( ) => ByteStream , heliaOpts : Partial < AddOptions > = { } , kuboOpts : KuboAddOptions = { } ) : Promise < void > {
3334 const heliaCid = await importToHelia ( data ( ) , {
3435 // these are the default kubo options
3536 cidVersion : 0 ,
@@ -65,9 +66,9 @@ describe('@helia/unixfs - files', () => {
6566 } )
6667
6768 it ( 'should create the same CID for a small file' , async ( ) => {
68- const candidate = ( ) : FileCandidate => ( {
69- content : Uint8Array . from ( [ 0 , 1 , 2 , 3 , 4 ] )
70- } )
69+ const candidate = ( ) : ByteStream => ( async function * ( ) {
70+ yield Uint8Array . from ( [ 0 , 1 , 2 , 3 , 4 ] )
71+ } ( ) )
7172
7273 await expectSameCid ( candidate )
7374 } )
@@ -76,13 +77,11 @@ describe('@helia/unixfs - files', () => {
7677 const chunkSize = 1024 * 1024
7778 const size = chunkSize * 10
7879
79- const candidate = ( ) : FileCandidate => ( {
80- content : ( async function * ( ) {
81- for ( let i = 0 ; i < size ; i += chunkSize ) {
82- yield new Uint8Array ( chunkSize )
83- }
84- } ( ) )
85- } )
80+ const candidate = ( ) : ByteStream => ( async function * ( ) {
81+ for ( let i = 0 ; i < size ; i += chunkSize ) {
82+ yield new Uint8Array ( chunkSize )
83+ }
84+ } ( ) )
8685
8786 await expectSameCid ( candidate )
8887 } )
0 commit comments