1
1
'use strict'
2
2
3
3
const errCode = require ( 'err-code' )
4
- const CID = require ( 'cids ' )
4
+ const { CID } = require ( 'multiformats/cid ' )
5
5
const resolve = require ( './resolvers' )
6
6
const last = require ( 'it-last' )
7
7
8
8
/**
9
9
* @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
12
11
* @typedef {import('./types').ExporterOptions } ExporterOptions
13
12
* @typedef {import('./types').UnixFSFile } UnixFSFile
14
13
* @typedef {import('./types').UnixFSDirectory } UnixFSDirectory
@@ -32,14 +31,15 @@ const toPathComponents = (path = '') => {
32
31
const cidAndRest = ( path ) => {
33
32
if ( path instanceof Uint8Array ) {
34
33
return {
35
- cid : new CID ( path ) ,
34
+ cid : CID . decode ( path ) ,
36
35
toResolve : [ ]
37
36
}
38
37
}
39
38
40
- if ( CID . isCID ( path ) ) {
39
+ const cid = CID . asCID ( path )
40
+ if ( cid ) {
41
41
return {
42
- cid : path ,
42
+ cid,
43
43
toResolve : [ ]
44
44
}
45
45
}
@@ -52,7 +52,7 @@ const cidAndRest = (path) => {
52
52
const output = toPathComponents ( path )
53
53
54
54
return {
55
- cid : new CID ( output [ 0 ] ) ,
55
+ cid : CID . parse ( output [ 0 ] ) ,
56
56
toResolve : output . slice ( 1 )
57
57
}
58
58
}
@@ -62,10 +62,10 @@ const cidAndRest = (path) => {
62
62
63
63
/**
64
64
* @param {string | CID } path
65
- * @param {IPLD } ipld
65
+ * @param {Blockstore } blockstore
66
66
* @param {ExporterOptions } [options]
67
67
*/
68
- async function * walkPath ( path , ipld , options = { } ) {
68
+ async function * walkPath ( path , blockstore , options = { } ) {
69
69
let {
70
70
cid,
71
71
toResolve
@@ -75,7 +75,7 @@ async function * walkPath (path, ipld, options = {}) {
75
75
const startingDepth = toResolve . length
76
76
77
77
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 )
79
79
80
80
if ( ! result . entry && ! result . next ) {
81
81
throw errCode ( new Error ( `Could not resolve ${ path } ` ) , 'ERR_NOT_FOUND' )
@@ -99,11 +99,11 @@ async function * walkPath (path, ipld, options = {}) {
99
99
100
100
/**
101
101
* @param {string | CID } path
102
- * @param {IPLD } ipld
102
+ * @param {Blockstore } blockstore
103
103
* @param {ExporterOptions } [options]
104
104
*/
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 ) )
107
107
108
108
if ( ! result ) {
109
109
throw errCode ( new Error ( `Could not resolve ${ path } ` ) , 'ERR_NOT_FOUND' )
@@ -114,11 +114,11 @@ async function exporter (path, ipld, options = {}) {
114
114
115
115
/**
116
116
* @param {string | CID } path
117
- * @param {IPLD } ipld
117
+ * @param {Blockstore } blockstore
118
118
* @param {ExporterOptions } [options]
119
119
*/
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 )
122
122
123
123
if ( ! node ) {
124
124
return
0 commit comments