@@ -4,7 +4,6 @@ const unixfsEngine = require('ipfs-unixfs-engine')
4
4
const importer = unixfsEngine . importer
5
5
const exporter = unixfsEngine . exporter
6
6
const promisify = require ( 'promisify-es6' )
7
- const multihashes = require ( 'multihashes' )
8
7
const pull = require ( 'pull-stream' )
9
8
const sort = require ( 'pull-sort' )
10
9
const pushable = require ( 'pull-pushable' )
@@ -13,6 +12,7 @@ const toPull = require('stream-to-pull-stream')
13
12
const waterfall = require ( 'async/waterfall' )
14
13
const isStream = require ( 'is-stream' )
15
14
const Duplex = require ( 'stream' ) . Duplex
15
+ const CID = require ( 'cids' )
16
16
17
17
module . exports = function files ( self ) {
18
18
const createAddPullStream = ( options ) => {
@@ -24,7 +24,7 @@ module.exports = function files (self) {
24
24
pull . map ( normalizeContent ) ,
25
25
pull . flatten ( ) ,
26
26
importer ( self . _ipldResolver , opts ) ,
27
- pull . asyncMap ( prepareFile . bind ( null , self ) )
27
+ pull . asyncMap ( prepareFile . bind ( null , self , opts ) )
28
28
)
29
29
}
30
30
@@ -68,7 +68,7 @@ module.exports = function files (self) {
68
68
pull (
69
69
pull . values ( normalizeContent ( data ) ) ,
70
70
importer ( self . _ipldResolver , options ) ,
71
- pull . asyncMap ( prepareFile . bind ( null , self ) ) ,
71
+ pull . asyncMap ( prepareFile . bind ( null , self , options ) ) ,
72
72
sort ( ( a , b ) => {
73
73
if ( a . path < b . path ) return 1
74
74
if ( a . path > b . path ) return - 1
@@ -114,15 +114,23 @@ module.exports = function files (self) {
114
114
}
115
115
}
116
116
117
- function prepareFile ( self , file , callback ) {
118
- const bs58mh = multihashes . toB58String ( file . multihash )
117
+ function prepareFile ( self , opts , file , callback ) {
118
+ opts = opts || { }
119
119
120
120
waterfall ( [
121
121
( cb ) => self . object . get ( file . multihash , cb ) ,
122
122
( node , cb ) => {
123
+ let cid = new CID ( node . multihash )
124
+
125
+ if ( opts [ 'cid-version' ] === 1 ) {
126
+ cid = cid . toV1 ( )
127
+ }
128
+
129
+ const b58Hash = cid . toBaseEncodedString ( )
130
+
123
131
cb ( null , {
124
- path : file . path || bs58mh ,
125
- hash : bs58mh ,
132
+ path : file . path || b58Hash ,
133
+ hash : b58Hash ,
126
134
size : node . size
127
135
} )
128
136
}
0 commit comments