@@ -7,6 +7,8 @@ const bs58 = require('bs58')
7
7
const series = require ( 'async/series' )
8
8
const hat = require ( 'hat' )
9
9
const { getDescribe, getIt, expect } = require ( '../utils/mocha' )
10
+ const UnixFs = require ( 'ipfs-unixfs' )
11
+ const crypto = require ( 'crypto' )
10
12
11
13
module . exports = ( createCommon , options ) => {
12
14
const describe = getDescribe ( options )
@@ -285,5 +287,39 @@ module.exports = (createCommon, options) => {
285
287
}
286
288
] , done )
287
289
} )
290
+
291
+ it ( 'supplies unadulterated data' , ( ) => {
292
+ // has to be big enough to span several DAGNodes
293
+ let required = 1024 * 3000
294
+
295
+ // can't just request `required` random bytes in the browser yet
296
+ // as it's more than 65536:
297
+ // https://github.com/crypto-browserify/randombytes/pull/15
298
+ let data = Buffer . alloc ( 0 )
299
+ const maxBytes = 65536
300
+ let next = maxBytes
301
+
302
+ while ( data . length !== required ) {
303
+ data = Buffer . concat ( [ data , crypto . randomBytes ( next ) ] )
304
+ next = maxBytes
305
+
306
+ if ( data . length + maxBytes > required ) {
307
+ next = required - data . length
308
+ }
309
+ }
310
+
311
+ return ipfs . files . add ( {
312
+ path : '' ,
313
+ content : data
314
+ } )
315
+ . then ( ( result ) => {
316
+ return ipfs . object . get ( result [ 0 ] . hash )
317
+ } )
318
+ . then ( ( node ) => {
319
+ const meta = UnixFs . unmarshal ( node . data )
320
+
321
+ expect ( meta . fileSize ( ) ) . to . equal ( data . length )
322
+ } )
323
+ } )
288
324
} )
289
325
}
0 commit comments