1- var spawn = require ( 'child_process' ) . spawn
2- , createCompressStream = require ( '../' ) . createCompressStream
3- , test = require ( 'tap' ) . test
4- , largerInput = require ( 'fs' ) . readFileSync ( __filename )
5- , largerInputString = largerInput . toString ( )
1+ const spawn = require ( 'child_process' ) . spawn ,
2+ createCompressStream = require ( '../' ) . createCompressStream ,
3+ test = require ( 'tap' ) . test ,
4+ largerInput = require ( 'fs' ) . readFileSync ( __filename )
65
76const UNCOMPRESSED_CHUNK_SIZE = 65536
87let superLargeInput = largerInput ;
98for ( let i = largerInput . length ; i <= UNCOMPRESSED_CHUNK_SIZE ; i += largerInput . length ) {
109 superLargeInput = Buffer . concat ( [ superLargeInput , largerInput ] ) ;
1110}
12- const superLargeInputString = superLargeInput . toString ( ) ;
1311
14- test ( 'compress small string' , function ( t ) {
15- var child = spawn ( 'python' , [ '-m' , 'snappy' , '-d' ] )
16- , compressStream = createCompressStream ( )
17- , data = ''
18-
19- child . stdout . on ( 'data' , function ( chunk ) {
20- data = data + chunk . toString ( )
21- } )
22-
23- child . stdout . on ( 'end' , function ( ) {
24- t . equal ( data , 'beep boop' )
25- t . end ( )
26- } )
27-
28- child . stderr . pipe ( process . stderr )
29-
30- compressStream . pipe ( child . stdin )
31-
32- compressStream . write ( 'beep boop' )
33- compressStream . end ( )
34- } )
35-
36- test ( 'compress large string' , function ( t ) {
37- var child = spawn ( 'python' , [ '-m' , 'snappy' , '-d' ] )
38- , compressStream = createCompressStream ( )
39- , data = ''
40-
41- child . stdout . on ( 'data' , function ( chunk ) {
42- data = data + chunk . toString ( )
43- } )
44-
45- child . stdout . on ( 'end' , function ( ) {
46- t . equal ( data , largerInputString )
47- t . end ( )
12+ [ {
13+ testName : "small" ,
14+ testString : "beep boop" ,
15+ asyncCompress : true
16+ } , {
17+ testName : "small" ,
18+ testString : "beep boop" ,
19+ asyncCompress : false
20+ } , {
21+ testName : "large" ,
22+ testString : largerInput ,
23+ asyncCompress : true
24+ } , {
25+ testName : "large" ,
26+ testString : largerInput ,
27+ asyncCompress : false
28+ } , {
29+ testName : "super large" ,
30+ testString : superLargeInput ,
31+ asyncCompress : true
32+ } , {
33+ testName : "super large" ,
34+ testString : superLargeInput ,
35+ asyncCompress : false
36+ } ] . forEach ( ( {
37+ testName,
38+ testString,
39+ asyncCompress
40+ } ) => {
41+
42+ test ( `compress ${ testName } input - asyncCompress=${ asyncCompress } ` , function ( t ) {
43+ const child = spawn ( 'python' , [ '-m' , 'snappy' , '-d' ] ) ,
44+ compressStream = createCompressStream ( {
45+ asyncCompress
46+ } )
47+ let data = ''
48+
49+ child . stdout . on ( 'data' , function ( chunk ) {
50+ data = data + chunk . toString ( )
51+ } )
52+
53+ child . stdout . on ( 'end' , function ( ) {
54+ t . equal ( data , testString . toString ( ) )
55+ t . end ( )
56+ } )
57+
58+ child . stderr . pipe ( process . stderr )
59+
60+ compressStream . pipe ( child . stdin )
61+
62+ compressStream . write ( testString )
63+ compressStream . end ( )
4864 } )
4965
50- child . stderr . pipe ( process . stderr )
51-
52- compressStream . pipe ( child . stdin )
53-
54- compressStream . write ( largerInputString )
55- compressStream . end ( )
56- } )
57-
58-
59- test ( 'compress very very large string' , function ( t ) {
60- var child = spawn ( 'python' , [ '-m' , 'snappy' , '-d' ] )
61- , compressStream = createCompressStream ( )
62- , data = ''
63-
64- child . stdout . on ( 'data' , function ( chunk ) {
65- data = data + chunk . toString ( )
66- } )
67-
68- child . stdout . on ( 'end' , function ( ) {
69- t . equal ( data , superLargeInputString )
70- t . end ( )
71- } )
72-
73- child . stderr . pipe ( process . stderr )
74-
75- compressStream . pipe ( child . stdin )
76-
77- compressStream . write ( superLargeInputString )
78- compressStream . end ( )
79- } )
66+ } )
0 commit comments