@@ -94,6 +94,20 @@ const compareErrors = (...ops) => {
9494 } )
9595}
9696
97+ // TODO: remove after https://github.com/crypto-browserify/randombytes/pull/16 released
98+ const MAX_BYTES = 65536
99+ function randomBytes ( num ) {
100+ if ( num < 1 ) return Buffer . alloc ( 0 )
101+ if ( num <= MAX_BYTES ) return crypto . randomBytes ( num )
102+
103+ const chunks = Array ( Math . floor ( num / MAX_BYTES ) )
104+ . fill ( MAX_BYTES )
105+ . concat ( num % MAX_BYTES )
106+ . map ( n => crypto . randomBytes ( n ) )
107+
108+ return Buffer . concat ( chunks )
109+ }
110+
97111describe ( 'files' , function ( ) {
98112 this . timeout ( 50 * 1000 )
99113
@@ -141,7 +155,7 @@ describe('files', function () {
141155 } )
142156
143157 it ( 'uses raw nodes for leaf data' , ( ) => {
144- const data = crypto . randomBytes ( 1024 * 300 )
158+ const data = randomBytes ( 1024 * 300 )
145159 const testLeavesAreRaw = ( daemon ) => {
146160 return addFile ( daemon , data )
147161 . then ( file => checkNodeTypes ( daemon , file ) )
@@ -166,8 +180,8 @@ describe('files', function () {
166180 const path = `/test-dir-${ Math . random ( ) } `
167181
168182 return compare (
169- go . api . files . mkdir ( path ) . then ( ( ) => go . api . files . mkdir ( path , { p : true } ) ) ,
170- js . api . files . mkdir ( path ) . then ( ( ) => js . api . files . mkdir ( path , { p : true } ) )
183+ go . api . files . mkdir ( path ) . then ( ( ) => go . api . files . mkdir ( path , { p : true } ) ) ,
184+ js . api . files . mkdir ( path ) . then ( ( ) => js . api . files . mkdir ( path , { p : true } ) )
171185 )
172186 } )
173187
@@ -229,7 +243,7 @@ describe('files', function () {
229243 } )
230244
231245 it ( 'big files' , ( ) => {
232- const data = crypto . randomBytes ( 1024 * 3000 )
246+ const data = randomBytes ( 1024 * 3000 )
233247
234248 return compare (
235249 testHashesAreEqual ( go , data ) ,
@@ -238,8 +252,8 @@ describe('files', function () {
238252 } )
239253
240254 it ( 'files that have had data appended' , ( ) => {
241- const initialData = crypto . randomBytes ( 1024 * 300 )
242- const appendedData = crypto . randomBytes ( 1024 * 300 )
255+ const initialData = randomBytes ( 1024 * 300 )
256+ const appendedData = randomBytes ( 1024 * 300 )
243257
244258 return compare (
245259 appendData ( go , initialData , appendedData ) ,
@@ -249,8 +263,8 @@ describe('files', function () {
249263
250264 it ( 'files that have had data overwritten' , ( ) => {
251265 const bytes = 1024 * 300
252- const initialData = crypto . randomBytes ( bytes )
253- const newData = crypto . randomBytes ( bytes )
266+ const initialData = randomBytes ( bytes )
267+ const newData = randomBytes ( bytes )
254268
255269 return compare (
256270 overwriteData ( go , initialData , newData ) ,
@@ -271,7 +285,7 @@ describe('files', function () {
271285 } )
272286
273287 it ( 'big files with CIDv1' , ( ) => {
274- const data = crypto . randomBytes ( 1024 * 3000 )
288+ const data = randomBytes ( 1024 * 3000 )
275289 const options = {
276290 cidVersion : 1
277291 }
0 commit comments