5
5
const expect = require ( 'chai' ) . expect
6
6
const isNode = require ( 'detect-node' )
7
7
const fs = require ( 'fs' )
8
+ const bl = require ( 'bl' )
8
9
9
10
const path = require ( 'path' )
10
11
const streamEqual = require ( 'stream-equal' )
@@ -24,59 +25,40 @@ describe('.get', () => {
24
25
apiClients . a
25
26
. get ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' , ( err , res ) => {
26
27
expect ( err ) . to . not . exist
27
-
28
- let buf = ''
29
- res
30
- . on ( 'error' , ( err ) => {
31
- expect ( err ) . to . not . exist
32
- } )
33
- . on ( 'data' , ( data ) => {
34
- buf += data
35
- } )
36
- . on ( 'end' , ( ) => {
37
- expect ( buf ) . to . contain ( testfile . toString ( ) )
38
- done ( )
39
- } )
28
+ res . pipe ( bl ( ( err , bldata ) => {
29
+ expect ( err ) . to . not . exist
30
+ expect ( bldata . toString ( ) ) . to . contain ( testfile . toString ( ) )
31
+ done ( )
32
+ } ) )
40
33
} )
41
34
} )
42
35
43
36
it ( 'get with archive true' , ( done ) => {
44
37
apiClients . a
45
- . get ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' , true , ( err , res ) => {
38
+ . get ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' , { archive : true } , ( err , res ) => {
46
39
expect ( err ) . to . not . exist
40
+ res . pipe ( bl ( ( err , bldata ) => {
41
+ expect ( err ) . to . not . exist
42
+ expect ( bldata . toString ( ) ) . to . contain ( testfile . toString ( ) )
43
+ done ( )
44
+ } ) )
45
+ } )
46
+ } )
47
47
48
- let buf = ''
49
- res
50
- . on ( 'error' , ( err ) => {
51
- expect ( err ) . to . not . exist
52
- } )
53
- . on ( 'data' , ( data ) => {
54
- buf += data
55
- } )
56
- . on ( 'end' , ( ) => {
57
- expect ( buf ) . to . contain ( testfile . toString ( ) )
58
- done ( )
59
- } )
48
+ it ( 'get err with out of range compression level' , ( done ) => {
49
+ apiClients . a
50
+ . get ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' , { compress : true , 'compression-level' : 10 } , ( err , res ) => {
51
+ expect ( err ) . to . exist
52
+ expect ( err . toString ( ) ) . to . equal ( 'Error: Compression level must be between 1 and 9' )
53
+ done ( )
60
54
} )
61
55
} )
62
56
63
57
it ( 'get with compression level' , ( done ) => {
64
58
apiClients . a
65
- . get ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' , true , 1 , ( err , res ) => {
59
+ . get ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' , { compress : true , 'compression-level' : 1 } , ( err , res ) => {
66
60
expect ( err ) . to . not . exist
67
-
68
- let buf = ''
69
- res
70
- . on ( 'error' , ( err ) => {
71
- expect ( err ) . to . not . exist
72
- } )
73
- . on ( 'data' , ( data ) => {
74
- buf += data
75
- } )
76
- . on ( 'end' , ( ) => {
77
- expect ( buf ) . to . contain ( testfile . toString ( ) )
78
- done ( )
79
- } )
61
+ done ( )
80
62
} )
81
63
} )
82
64
0 commit comments