11'use strict'
22
33const errCode = require ( 'err-code' )
4- const CID = require ( 'cids ' )
4+ const { CID } = require ( 'multiformats/cid ' )
55const resolve = require ( './resolvers' )
66const last = require ( 'it-last' )
77
88/**
99 * @typedef {import('ipfs-unixfs').UnixFS } UnixFS
10- * @typedef {import('ipld-dag-pb').DAGNode } DAGNode
11- * @typedef {import('ipld') } IPLD
10+ * @typedef {import('interface-blockstore').Blockstore } Blockstore
1211 * @typedef {import('./types').ExporterOptions } ExporterOptions
1312 * @typedef {import('./types').UnixFSFile } UnixFSFile
1413 * @typedef {import('./types').UnixFSDirectory } UnixFSDirectory
@@ -32,14 +31,15 @@ const toPathComponents = (path = '') => {
3231const cidAndRest = ( path ) => {
3332 if ( path instanceof Uint8Array ) {
3433 return {
35- cid : new CID ( path ) ,
34+ cid : CID . decode ( path ) ,
3635 toResolve : [ ]
3736 }
3837 }
3938
40- if ( CID . isCID ( path ) ) {
39+ const cid = CID . asCID ( path )
40+ if ( cid ) {
4141 return {
42- cid : path ,
42+ cid,
4343 toResolve : [ ]
4444 }
4545 }
@@ -52,7 +52,7 @@ const cidAndRest = (path) => {
5252 const output = toPathComponents ( path )
5353
5454 return {
55- cid : new CID ( output [ 0 ] ) ,
55+ cid : CID . parse ( output [ 0 ] ) ,
5656 toResolve : output . slice ( 1 )
5757 }
5858 }
@@ -62,10 +62,10 @@ const cidAndRest = (path) => {
6262
6363/**
6464 * @param {string | CID } path
65- * @param {IPLD } ipld
65+ * @param {Blockstore } blockstore
6666 * @param {ExporterOptions } [options]
6767 */
68- async function * walkPath ( path , ipld , options = { } ) {
68+ async function * walkPath ( path , blockstore , options = { } ) {
6969 let {
7070 cid,
7171 toResolve
@@ -75,7 +75,7 @@ async function * walkPath (path, ipld, options = {}) {
7575 const startingDepth = toResolve . length
7676
7777 while ( true ) {
78- const result = await resolve ( cid , name , entryPath , toResolve , startingDepth , ipld , options )
78+ const result = await resolve ( cid , name , entryPath , toResolve , startingDepth , blockstore , options )
7979
8080 if ( ! result . entry && ! result . next ) {
8181 throw errCode ( new Error ( `Could not resolve ${ path } ` ) , 'ERR_NOT_FOUND' )
@@ -99,11 +99,11 @@ async function * walkPath (path, ipld, options = {}) {
9999
100100/**
101101 * @param {string | CID } path
102- * @param {IPLD } ipld
102+ * @param {Blockstore } blockstore
103103 * @param {ExporterOptions } [options]
104104 */
105- async function exporter ( path , ipld , options = { } ) {
106- const result = await last ( walkPath ( path , ipld , options ) )
105+ async function exporter ( path , blockstore , options = { } ) {
106+ const result = await last ( walkPath ( path , blockstore , options ) )
107107
108108 if ( ! result ) {
109109 throw errCode ( new Error ( `Could not resolve ${ path } ` ) , 'ERR_NOT_FOUND' )
@@ -114,11 +114,11 @@ async function exporter (path, ipld, options = {}) {
114114
115115/**
116116 * @param {string | CID } path
117- * @param {IPLD } ipld
117+ * @param {Blockstore } blockstore
118118 * @param {ExporterOptions } [options]
119119 */
120- async function * recursive ( path , ipld , options = { } ) {
121- const node = await exporter ( path , ipld , options )
120+ async function * recursive ( path , blockstore , options = { } ) {
121+ const node = await exporter ( path , blockstore , options )
122122
123123 if ( ! node ) {
124124 return
0 commit comments