@@ -7,6 +7,8 @@ const bs58 = require('bs58')
77const series = require ( 'async/series' )
88const hat = require ( 'hat' )
99const { getDescribe, getIt, expect } = require ( '../utils/mocha' )
10+ const UnixFs = require ( 'ipfs-unixfs' )
11+ const crypto = require ( 'crypto' )
1012
1113module . exports = ( createCommon , options ) => {
1214 const describe = getDescribe ( options )
@@ -285,5 +287,39 @@ module.exports = (createCommon, options) => {
285287 }
286288 ] , done )
287289 } )
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+ } )
288324 } )
289325}
0 commit comments