@@ -4,12 +4,11 @@ const extend = require('deep-extend')
4
4
const UnixFS = require ( 'ipfs-unixfs' )
5
5
const pull = require ( 'pull-stream/pull' )
6
6
const values = require ( 'pull-stream/sources/values' )
7
- const asyncMap = require ( 'pull-stream/throughs/async-map' )
8
- const map = require ( 'pull-stream/throughs/map' )
9
7
const collect = require ( 'pull-stream/sinks/collect' )
10
8
const through = require ( 'pull-through' )
11
9
const parallel = require ( 'async/parallel' )
12
10
const waterfall = require ( 'async/waterfall' )
11
+ const paraMap = require ( 'pull-paramap' )
13
12
const persist = require ( '../utils/persist' )
14
13
const reduce = require ( './reduce' )
15
14
const {
@@ -106,50 +105,53 @@ module.exports = function builder (createChunker, ipld, createReducer, _options)
106
105
pull (
107
106
file . content ,
108
107
chunker ,
109
- map ( chunk => {
108
+ through ( chunk => {
110
109
if ( options . progress && typeof options . progress === 'function' ) {
111
110
options . progress ( chunk . byteLength )
112
111
}
113
- return chunk
114
112
} ) ,
115
- asyncMap ( ( buffer , callback ) => {
116
- if ( options . rawLeaves ) {
117
- return callback ( null , {
118
- size : buffer . length ,
119
- leafSize : buffer . length ,
120
- data : buffer
121
- } )
122
- }
123
-
124
- const file = new UnixFS ( options . leafType , buffer )
113
+ paraMap ( ( buffer , callback ) => {
114
+ waterfall ( [
115
+ ( cb ) => {
116
+ if ( options . rawLeaves ) {
117
+ return cb ( null , {
118
+ size : buffer . length ,
119
+ leafSize : buffer . length ,
120
+ data : buffer
121
+ } )
122
+ }
125
123
126
- DAGNode . create ( file . marshal ( ) , [ ] , ( err , node ) => {
127
- if ( err ) {
128
- return callback ( err )
124
+ const file = new UnixFS ( options . leafType , buffer )
125
+
126
+ DAGNode . create ( file . marshal ( ) , [ ] , ( err , node ) => {
127
+ if ( err ) {
128
+ return cb ( err )
129
+ }
130
+
131
+ cb ( null , {
132
+ size : node . size ,
133
+ leafSize : file . fileSize ( ) ,
134
+ data : node
135
+ } )
136
+ } )
137
+ } ,
138
+ ( leaf , cb ) => {
139
+ persist ( leaf . data , ipld , options , ( error , results ) => {
140
+ if ( error ) {
141
+ return cb ( error )
142
+ }
143
+
144
+ cb ( null , {
145
+ size : leaf . size ,
146
+ leafSize : leaf . leafSize ,
147
+ data : results . node ,
148
+ multihash : results . cid . buffer ,
149
+ path : leaf . path ,
150
+ name : ''
151
+ } )
152
+ } )
129
153
}
130
-
131
- callback ( null , {
132
- size : node . size ,
133
- leafSize : file . fileSize ( ) ,
134
- data : node
135
- } )
136
- } )
137
- } ) ,
138
- asyncMap ( ( leaf , callback ) => {
139
- persist ( leaf . data , ipld , options , ( error , results ) => {
140
- if ( error ) {
141
- return callback ( error )
142
- }
143
-
144
- callback ( null , {
145
- size : leaf . size ,
146
- leafSize : leaf . leafSize ,
147
- data : results . node ,
148
- multihash : results . cid . buffer ,
149
- path : leaf . path ,
150
- name : ''
151
- } )
152
- } )
154
+ ] , callback )
153
155
} ) ,
154
156
through ( // mark as single node if only one single node
155
157
function onData ( data ) {
0 commit comments