@@ -5,6 +5,15 @@ const expect = require('chai').expect
5
5
const bl = require ( 'bl' )
6
6
const bs58 = require ( 'bs58' )
7
7
const Readable = require ( 'readable-stream' )
8
+ const isNode = require ( 'detect-node' )
9
+ const path = require ( 'path' )
10
+
11
+ let testfileBig
12
+
13
+ if ( isNode ) {
14
+ const fs = require ( 'fs' )
15
+ testfileBig = fs . readFileSync ( path . join ( __dirname , './test-data/15mb.random' ) , { bufferSize : 128 } )
16
+ }
8
17
9
18
module . exports = ( common ) => {
10
19
describe ( '.file' , ( ) => {
@@ -22,26 +31,6 @@ module.exports = (common) => {
22
31
common . teardown ( done )
23
32
} )
24
33
25
- // go-ipfs http and js-ipfs core have different responses
26
- describe ( '.add' , ( ) => {
27
- it ( 'add' , ( done ) => {
28
- const buffered = new Buffer ( 'some data' )
29
- const rs = new Readable ( )
30
- rs . push ( buffered )
31
- rs . push ( null )
32
- const arr = [ ]
33
- const filePair = { path : 'data.txt' , content : rs }
34
- arr . push ( filePair )
35
- ipfs . add ( arr , ( err , res ) => {
36
- expect ( err ) . to . not . exist
37
- expect ( res [ 0 ] . path ) . to . equal ( 'data.txt' )
38
- expect ( res [ 0 ] . size ) . to . equal ( 17 )
39
- expect ( bs58 . encode ( res [ 0 ] . multihash ) . toString ( ) ) . to . equal ( 'QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS' )
40
- done ( )
41
- } )
42
- } )
43
- } )
44
-
45
34
describe ( '.cat' , ( ) => {
46
35
it ( 'returns file stream' , ( done ) => {
47
36
const hash = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'
@@ -56,7 +45,7 @@ module.exports = (common) => {
56
45
} )
57
46
58
47
// This fails on js-ipfs-api
59
- it . skip ( 'takes a buffer input' , ( done ) => {
48
+ it ( 'takes a buffer input' , ( done ) => {
60
49
const mhBuf = new Buffer ( bs58 . decode ( 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB' ) )
61
50
ipfs . cat ( mhBuf , ( err , file ) => {
62
51
expect ( err ) . to . not . exist
@@ -69,12 +58,13 @@ module.exports = (common) => {
69
58
} )
70
59
71
60
// You can add a large file to your ipfs repo and change the hash to the file after installing js-ipfs
72
- it . skip ( 'returns a large file' , ( done ) => {
73
- const hash = ''
61
+ it ( 'returns a large file' , ( done ) => {
62
+ const hash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq '
74
63
ipfs . cat ( hash , ( err , file ) => {
75
64
expect ( err ) . to . not . exist
76
65
file . pipe ( bl ( ( err , bldata ) => {
77
66
expect ( err ) . to . not . exist
67
+ expect ( bldata ) . to . deep . equal ( testfileBig )
78
68
done ( )
79
69
} ) )
80
70
} )
@@ -127,6 +117,21 @@ module.exports = (common) => {
127
117
done ( )
128
118
} )
129
119
} )
120
+
121
+ it ( 'takes a buffer input' , ( done ) => {
122
+ const hash = new Buffer ( bs58 . decode ( 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB' ) )
123
+ ipfs . cat ( hash )
124
+ . then ( ( stream ) => {
125
+ stream . pipe ( bl ( ( err , bldata ) => {
126
+ expect ( err ) . to . not . exist
127
+ expect ( bldata . toString ( ) ) . to . contain ( 'Check out some of the other files in this directory:' )
128
+ done ( )
129
+ } ) )
130
+ } )
131
+ . catch ( ( err ) => {
132
+ expect ( err ) . to . not . exist
133
+ } )
134
+ } )
130
135
} )
131
136
} )
132
137
} )
0 commit comments