@@ -6,22 +6,22 @@ const { UnixFS } = require('ipfs-unixfs')
66const errCode = require ( 'err-code' )
77const dagPb = require ( '@ipld/dag-pb' )
88const dagCbor = require ( '@ipld/dag-cbor' )
9- const mc = require ( 'multicodec ' )
9+ const raw = require ( 'multiformats/codecs/raw ' )
1010
1111/**
1212 * @typedef {import('../../../types').ExporterOptions } ExporterOptions
13- * @typedef {import('ipfs-unixfs-importer/src/types ').BlockAPI } BlockService
13+ * @typedef {import('interface-blockstore ').Blockstore } Blockstore
1414 * @typedef {import('@ipld/dag-pb').PBNode } PBNode
1515 *
16- * @param {BlockService } blockService
16+ * @param {Blockstore } blockstore
1717 * @param {PBNode } node
1818 * @param {number } start
1919 * @param {number } end
2020 * @param {number } streamPosition
2121 * @param {ExporterOptions } options
2222 * @returns {AsyncIterable<Uint8Array> }
2323 */
24- async function * emitBytes ( blockService , node , start , end , streamPosition = 0 , options ) {
24+ async function * emitBytes ( blockstore , node , start , end , streamPosition = 0 , options ) {
2525 // a `raw` node
2626 if ( node instanceof Uint8Array ) {
2727 const buf = extractDataFromBlock ( node , streamPosition , start , end )
@@ -68,26 +68,25 @@ async function * emitBytes (blockService, node, start, end, streamPosition = 0,
6868 if ( ( start >= childStart && start < childEnd ) || // child has offset byte
6969 ( end > childStart && end <= childEnd ) || // child has end byte
7070 ( start < childStart && end > childEnd ) ) { // child is between offset and end bytes
71- const block = await blockService . get ( childLink . Hash , {
71+ const block = await blockstore . get ( childLink . Hash , {
7272 signal : options . signal
7373 } )
7474 let child
7575 switch ( childLink . Hash . code ) {
76- case mc . DAG_PB :
77- child = await dagPb . decode ( block . bytes )
76+ case dagPb . code :
77+ child = await dagPb . decode ( block )
7878 break
79- case mc . RAW :
80- child = block . bytes
79+ case raw . code :
80+ child = block
8181 break
82- case mc . DAG_CBOR :
83- child = await dagCbor . decode ( block . bytes )
82+ case dagCbor . code :
83+ child = await dagCbor . decode ( block )
8484 break
8585 default :
86- // @ts -ignore - A `CodecCode` is expected, but a number is just fine
87- throw Error ( `Unsupported codec: ${ mc . getName ( childLink . Hash . code ) } ` )
86+ throw Error ( `Unsupported codec: ${ childLink . Hash . code } ` )
8887 }
8988
90- for await ( const buf of emitBytes ( blockService , child , start , end , streamPosition , options ) ) {
89+ for await ( const buf of emitBytes ( blockstore , child , start , end , streamPosition , options ) ) {
9190 streamPosition += buf . length
9291
9392 yield buf
@@ -102,7 +101,7 @@ async function * emitBytes (blockService, node, start, end, streamPosition = 0,
102101/**
103102 * @type {import('../').UnixfsV1Resolver }
104103 */
105- const fileContent = ( cid , node , unixfs , path , resolve , depth , blockService ) => {
104+ const fileContent = ( cid , node , unixfs , path , resolve , depth , blockstore ) => {
106105 /**
107106 * @param {ExporterOptions } options
108107 */
@@ -121,7 +120,7 @@ const fileContent = (cid, node, unixfs, path, resolve, depth, blockService) => {
121120 const start = offset
122121 const end = offset + length
123122
124- return emitBytes ( blockService , node , start , end , 0 , options )
123+ return emitBytes ( blockstore , node , start , end , 0 , options )
125124 }
126125
127126 return yieldFileContent
0 commit comments