3
3
4
4
const expect = require ( 'chai' ) . expect
5
5
const BlockService = require ( 'ipfs-block-service' )
6
- const DAGService = require ( 'ipld-resolver' )
6
+ const IPLDResolver = require ( 'ipld-resolver' )
7
7
const UnixFS = require ( 'ipfs-unixfs' )
8
8
const fs = require ( 'fs' )
9
9
const path = require ( 'path' )
10
10
const bs58 = require ( 'bs58' )
11
11
const pull = require ( 'pull-stream' )
12
12
const zip = require ( 'pull-zip' )
13
+ const CID = require ( 'cids' )
13
14
14
15
const unixFSEngine = require ( './../src' )
15
16
const exporter = unixFSEngine . exporter
16
17
17
18
module . exports = ( repo ) => {
18
19
describe ( 'exporter' , ( ) => {
19
- let ds
20
+ let ipldResolver
20
21
21
22
const bigFile = fs . readFileSync ( path . join ( __dirname , '/test-data/1.2MiB.txt' ) )
22
23
before ( ( ) => {
23
24
const bs = new BlockService ( repo )
24
- ds = new DAGService ( bs )
25
+ ipldResolver = new IPLDResolver ( bs )
25
26
} )
26
27
27
28
it ( 'import and export' , ( done ) => {
28
29
pull (
29
30
pull . values ( [ {
30
31
path : '1.2MiB.txt' ,
31
- content : pull . values ( [ bigFile , Buffer ( 'hello world' ) ] )
32
+ content : pull . values ( [
33
+ bigFile ,
34
+ Buffer ( 'hello world' )
35
+ ] )
32
36
} ] ) ,
33
- unixFSEngine . importer ( ds ) ,
37
+ unixFSEngine . importer ( ipldResolver ) ,
34
38
pull . map ( ( file ) => {
35
39
expect ( file . path ) . to . be . eql ( '1.2MiB.txt' )
36
40
37
- return exporter ( file . multihash , ds )
41
+ return exporter ( file . multihash , ipldResolver )
38
42
} ) ,
39
43
pull . flatten ( ) ,
40
44
pull . collect ( ( err , files ) => {
@@ -50,15 +54,15 @@ module.exports = (repo) => {
50
54
const mhBuf = new Buffer ( bs58 . decode ( hash ) )
51
55
52
56
pull (
53
- ds . getStream ( hash ) ,
57
+ ipldResolver . getStream ( new CID ( hash ) ) ,
54
58
pull . map ( ( node ) => UnixFS . unmarshal ( node . data ) ) ,
55
59
pull . collect ( ( err , nodes ) => {
56
60
expect ( err ) . to . not . exist
57
61
58
62
const unmarsh = nodes [ 0 ]
59
63
60
64
pull (
61
- exporter ( mhBuf , ds ) ,
65
+ exporter ( mhBuf , ipldResolver ) ,
62
66
pull . collect ( onFiles )
63
67
)
64
68
@@ -79,10 +83,10 @@ module.exports = (repo) => {
79
83
pull (
80
84
zip (
81
85
pull (
82
- ds . getStream ( hash ) ,
86
+ ipldResolver . getStream ( new CID ( hash ) ) ,
83
87
pull . map ( ( node ) => UnixFS . unmarshal ( node . data ) )
84
88
) ,
85
- exporter ( hash , ds )
89
+ exporter ( hash , ipldResolver )
86
90
) ,
87
91
pull . collect ( ( err , values ) => {
88
92
expect ( err ) . to . not . exist
@@ -97,7 +101,7 @@ module.exports = (repo) => {
97
101
it ( 'export a small file with links' , ( done ) => {
98
102
const hash = 'QmW7BDxEbGqxxSYVtn3peNPQgdDXbWkoQ6J1EFYAEuQV3Q'
99
103
pull (
100
- exporter ( hash , ds ) ,
104
+ exporter ( hash , ipldResolver ) ,
101
105
pull . collect ( ( err , files ) => {
102
106
expect ( err ) . to . not . exist
103
107
@@ -109,7 +113,7 @@ module.exports = (repo) => {
109
113
it ( 'export a large file > 5mb' , ( done ) => {
110
114
const hash = 'QmRQgufjp9vLE8XK2LGKZSsPCFCF6e4iynCQtNB5X2HBKE'
111
115
pull (
112
- exporter ( hash , ds ) ,
116
+ exporter ( hash , ipldResolver ) ,
113
117
pull . collect ( ( err , files ) => {
114
118
expect ( err ) . to . not . exist
115
119
@@ -123,7 +127,7 @@ module.exports = (repo) => {
123
127
const hash = 'QmWChcSFMNcFkfeJtNd8Yru1rE6PhtCRfewi1tMwjkwKjN'
124
128
125
129
pull (
126
- exporter ( hash , ds ) ,
130
+ exporter ( hash , ipldResolver ) ,
127
131
pull . collect ( ( err , files ) => {
128
132
expect ( err ) . to . not . exist
129
133
@@ -162,7 +166,7 @@ module.exports = (repo) => {
162
166
const hash = 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn'
163
167
164
168
pull (
165
- exporter ( hash , ds ) ,
169
+ exporter ( hash , ipldResolver ) ,
166
170
pull . collect ( ( err , files ) => {
167
171
expect ( err ) . to . not . exist
168
172
expect ( files [ 0 ] . content ) . to . not . exist
@@ -176,7 +180,7 @@ module.exports = (repo) => {
176
180
const hash = 'QmWChcSFMNcFkfeJtNd8Yru1rE6PhtCRfewi1tMwjkwKj3'
177
181
178
182
pull (
179
- exporter ( hash , ds ) ,
183
+ exporter ( hash , ipldResolver ) ,
180
184
pull . collect ( ( err , files ) => {
181
185
expect ( err ) . to . exist
182
186
done ( )
@@ -190,7 +194,9 @@ function fileEql (f1, f2, done) {
190
194
pull (
191
195
f1 . content ,
192
196
pull . collect ( ( err , data ) => {
193
- if ( err ) return done ( err )
197
+ if ( err ) {
198
+ return done ( err )
199
+ }
194
200
195
201
try {
196
202
if ( f2 ) {
0 commit comments