2
2
'use strict'
3
3
4
4
const expect = require ( 'chai' ) . expect
5
- const DAGNode = require ( 'ipfs-merkle-dag' ) . DAGNode
6
5
const bs58 = require ( 'bs58' )
7
- const bl = require ( 'bl' )
8
6
const Readable = require ( 'readable-stream' )
9
7
const path = require ( 'path' )
10
8
const isNode = require ( 'detect-node' )
9
+ const fs = require ( 'fs' )
11
10
12
11
module . exports = ( common ) => {
13
12
describe ( '.files/add' , ( ) => {
14
- let testfile
15
- let testfileBig
13
+ let smallFile
14
+ let bigFile
16
15
let ipfs
17
16
18
17
before ( ( done ) => {
19
- // load test data
20
- if ( isNode ) {
21
- const fs = require ( 'fs' )
22
-
23
- const testfilePath = path . join ( __dirname , './data/testfile.txt' )
24
- testfile = fs . readFileSync ( testfilePath )
25
-
26
- const testfileBigPath = path . join ( __dirname , './data/15mb.random' )
27
- testfileBig = fs . createReadStream ( testfileBigPath , { bufferSize : 128 } )
28
- } else {
29
- testfile = require ( 'raw!./data/testfile.txt' )
30
- }
18
+ smallFile = fs . readFileSync ( path . join ( __dirname , './data/testfile.txt' )
19
+ )
20
+ bigFile = fs . readFileSync ( path . join ( __dirname , './data/15mb.random' )
21
+ )
31
22
32
23
common . setup ( ( err , _ipfs ) => {
33
24
expect ( err ) . to . not . exist
@@ -66,7 +57,7 @@ module.exports = (common) => {
66
57
67
58
const file = {
68
59
path : 'testfile.txt' ,
69
- content : new Buffer ( testfile )
60
+ content : smallFile
70
61
}
71
62
72
63
ipfs . files . add ( [ file ] , ( err , res ) => {
@@ -82,8 +73,7 @@ module.exports = (common) => {
82
73
} )
83
74
84
75
it ( 'buffer' , ( done ) => {
85
- let buf = new Buffer ( testfile )
86
- ipfs . files . add ( buf , ( err , res ) => {
76
+ ipfs . files . add ( smallFile , ( err , res ) => {
87
77
expect ( err ) . to . not . exist
88
78
89
79
expect ( res ) . to . have . length ( 1 )
@@ -96,11 +86,7 @@ module.exports = (common) => {
96
86
} )
97
87
98
88
it ( 'BIG buffer' , ( done ) => {
99
- if ( ! isNode ) {
100
- return done ( )
101
- }
102
-
103
- ipfs . files . add ( testfileBig , ( err , res ) => {
89
+ ipfs . files . add ( bigFile , ( err , res ) => {
104
90
expect ( err ) . to . not . exist
105
91
106
92
expect ( res ) . to . have . length ( 1 )
@@ -113,8 +99,9 @@ module.exports = (common) => {
113
99
} )
114
100
115
101
it ( 'add a nested dir as array' , ( done ) => {
116
- if ( ! isNode ) return done ( )
117
- const fs = require ( 'fs' )
102
+ if ( ! isNode ) {
103
+ return done ( )
104
+ }
118
105
const base = path . join ( __dirname , 'data/test-folder' )
119
106
const content = ( name ) => ( {
120
107
path : `test-folder/${ name } ` ,
@@ -149,8 +136,7 @@ module.exports = (common) => {
149
136
150
137
describe ( 'promise' , ( ) => {
151
138
it ( 'buffer' , ( ) => {
152
- let buf = new Buffer ( testfile )
153
- return ipfs . files . add ( buf )
139
+ return ipfs . files . add ( smallFile )
154
140
. then ( ( res ) => {
155
141
const added = res [ 0 ] != null ? res [ 0 ] : res
156
142
const mh = bs58 . encode ( added . node . multihash ( ) ) . toString ( )
0 commit comments