@@ -6,100 +6,116 @@ const path = require('path');
6
6
const uuid = require ( 'uuid' ) ;
7
7
const compressing = require ( '../..' ) ;
8
8
const assert = require ( 'assert' ) ;
9
+ const isWindows = os . platform ( ) === 'win32' ;
9
10
10
11
describe ( 'test/gzip/index.test.js' , ( ) => {
11
12
describe ( 'gzip.compressFile()' , ( ) => {
12
- it ( 'gzip.compressFile(file, stream)' , function * ( ) {
13
+ it ( 'gzip.compressFile(file, stream)' , async ( ) => {
13
14
const sourceFile = path . join ( __dirname , '..' , 'fixtures' , 'xx.log' ) ;
14
15
const destFile = path . join ( os . tmpdir ( ) , uuid . v4 ( ) + '.log.gz' ) ;
15
16
console . log ( 'destFile' , destFile ) ;
16
17
const fileStream = fs . createWriteStream ( destFile ) ;
17
- yield compressing . gzip . compressFile ( sourceFile , fileStream ) ;
18
+ await compressing . gzip . compressFile ( sourceFile , fileStream ) ;
18
19
assert ( fs . existsSync ( destFile ) ) ;
19
20
} ) ;
20
21
21
- it ( 'gzip.compressFile(file, destStream) should error if destStream emit error' , function * ( ) {
22
+ it ( 'gzip.compressFile(file, destStream) should error if destStream emit error' , async ( ) => {
22
23
const sourceFile = path . join ( __dirname , '..' , 'fixtures' , 'xx.log' ) ;
23
24
const destFile = path . join ( os . tmpdir ( ) , uuid . v4 ( ) + '.gz' ) ;
24
25
const fileStream = fs . createWriteStream ( destFile ) ;
25
26
setImmediate ( ( ) => fileStream . emit ( 'error' , new Error ( 'xx' ) ) ) ;
26
27
27
28
let err ;
28
29
try {
29
- yield compressing . gzip . compressFile ( sourceFile , fileStream ) ;
30
+ await compressing . gzip . compressFile ( sourceFile , fileStream ) ;
30
31
} catch ( e ) {
31
32
err = e ;
32
33
}
33
34
assert ( err && err . message === 'xx' ) ;
34
35
} ) ;
35
36
36
- it ( 'gzip.compressFile(buffer, stream)' , function * ( ) {
37
+ it ( 'gzip.compressFile(buffer, stream)' , async ( ) => {
37
38
const sourceFile = path . join ( __dirname , '..' , 'fixtures' , 'xx.log' ) ;
38
39
const sourceBuffer = fs . readFileSync ( sourceFile ) ;
39
40
const destFile = path . join ( os . tmpdir ( ) , uuid . v4 ( ) + '.log.gz' ) ;
40
41
console . log ( 'destFile' , destFile ) ;
41
42
const fileStream = fs . createWriteStream ( destFile ) ;
42
- yield compressing . gzip . compressFile ( sourceBuffer , fileStream ) ;
43
+ await compressing . gzip . compressFile ( sourceBuffer , fileStream ) ;
43
44
assert ( fs . existsSync ( destFile ) ) ;
44
45
} ) ;
45
46
46
- it ( 'gzip.compressFile(sourceStream, destStream)' , function * ( ) {
47
+ it ( 'gzip.compressFile(sourceStream, destStream)' , async ( ) => {
47
48
const sourceFile = path . join ( __dirname , '..' , 'fixtures' , 'xx.log' ) ;
48
49
const sourceStream = fs . createReadStream ( sourceFile ) ;
49
50
const destFile = path . join ( os . tmpdir ( ) , uuid . v4 ( ) + '.log.gz' ) ;
50
51
console . log ( 'destFile' , destFile ) ;
51
52
const fileStream = fs . createWriteStream ( destFile ) ;
52
- yield compressing . gzip . compressFile ( sourceStream , fileStream ) ;
53
+ await compressing . gzip . compressFile ( sourceStream , fileStream ) ;
53
54
assert ( fs . existsSync ( destFile ) ) ;
54
55
} ) ;
55
56
} ) ;
56
57
57
58
describe ( 'gzip.uncompress()' , ( ) => {
58
- it ( 'gzip.uncompress(sourceFile, destStream)' , function * ( ) {
59
+ it ( 'gzip.uncompress(sourceFile, destStream)' , async ( ) => {
59
60
const sourceFile = path . join ( __dirname , '..' , 'fixtures' , 'xx.log.gz' ) ;
60
61
const originalFile = path . join ( __dirname , '..' , 'fixtures' , 'xx.log' ) ;
61
62
const destFile = path . join ( os . tmpdir ( ) , uuid . v4 ( ) + '.log' ) ;
62
63
const fileStream = fs . createWriteStream ( destFile ) ;
63
- yield compressing . gzip . uncompress ( sourceFile , fileStream ) ;
64
+ await compressing . gzip . uncompress ( sourceFile , fileStream ) ;
64
65
assert ( fs . existsSync ( destFile ) ) ;
65
- assert ( fs . readFileSync ( destFile , 'utf8' ) === fs . readFileSync ( originalFile , 'utf8' ) ) ;
66
+ if ( ! isWindows ) {
67
+ // EOL not equal to linux
68
+ assert ( fs . readFileSync ( destFile , 'utf8' ) === fs . readFileSync ( originalFile , 'utf8' ) ) ;
69
+ }
66
70
} ) ;
67
71
68
- it ( 'gzip.uncompress(sourceStream, destStream)' , function * ( ) {
72
+ it ( 'gzip.uncompress(sourceStream, destStream)' , async ( ) => {
69
73
const sourceStream = fs . createReadStream ( path . join ( __dirname , '..' , 'fixtures' , 'xx.log.gz' ) ) ;
70
74
const originalFile = path . join ( __dirname , '..' , 'fixtures' , 'xx.log' ) ;
71
75
const destFile = path . join ( os . tmpdir ( ) , uuid . v4 ( ) + '.log' ) ;
72
76
const fileStream = fs . createWriteStream ( destFile ) ;
73
- yield compressing . gzip . uncompress ( sourceStream , fileStream ) ;
77
+ await compressing . gzip . uncompress ( sourceStream , fileStream ) ;
74
78
assert ( fs . existsSync ( destFile ) ) ;
75
- assert ( fs . readFileSync ( destFile , 'utf8' ) === fs . readFileSync ( originalFile , 'utf8' ) ) ;
79
+ if ( ! isWindows ) {
80
+ // EOL not equal to linux
81
+ assert ( fs . readFileSync ( destFile , 'utf8' ) === fs . readFileSync ( originalFile , 'utf8' ) ) ;
82
+ }
76
83
} ) ;
77
84
78
- it ( 'gzip.uncompress(sourceStream, destFile)' , function * ( ) {
85
+ it ( 'gzip.uncompress(sourceStream, destFile)' , async ( ) => {
79
86
const sourceStream = fs . createReadStream ( path . join ( __dirname , '..' , 'fixtures' , 'xx.log.gz' ) ) ;
80
87
const originalFile = path . join ( __dirname , '..' , 'fixtures' , 'xx.log' ) ;
81
88
const destFile = path . join ( os . tmpdir ( ) , uuid . v4 ( ) + '.log' ) ;
82
- yield compressing . gzip . uncompress ( sourceStream , destFile ) ;
89
+ await compressing . gzip . uncompress ( sourceStream , destFile ) ;
83
90
assert ( fs . existsSync ( destFile ) ) ;
84
- assert ( fs . readFileSync ( destFile , 'utf8' ) === fs . readFileSync ( originalFile , 'utf8' ) ) ;
91
+ if ( ! isWindows ) {
92
+ // EOL not equal to linux
93
+ assert ( fs . readFileSync ( destFile , 'utf8' ) === fs . readFileSync ( originalFile , 'utf8' ) ) ;
94
+ }
85
95
} ) ;
86
96
87
- it ( 'gzip.uncompress(sourceFile, destFile)' , function * ( ) {
97
+ it ( 'gzip.uncompress(sourceFile, destFile)' , async ( ) => {
88
98
const sourceFile = path . join ( __dirname , '..' , 'fixtures' , 'xx.log.gz' ) ;
89
99
const originalFile = path . join ( __dirname , '..' , 'fixtures' , 'xx.log' ) ;
90
100
const destFile = path . join ( os . tmpdir ( ) , uuid . v4 ( ) + '.log' ) ;
91
- yield compressing . gzip . uncompress ( sourceFile , destFile ) ;
101
+ await compressing . gzip . uncompress ( sourceFile , destFile ) ;
92
102
assert ( fs . existsSync ( destFile ) ) ;
93
- assert ( fs . readFileSync ( destFile , 'utf8' ) === fs . readFileSync ( originalFile , 'utf8' ) ) ;
103
+ if ( ! isWindows ) {
104
+ // EOL not equal to linux
105
+ assert ( fs . readFileSync ( destFile , 'utf8' ) === fs . readFileSync ( originalFile , 'utf8' ) ) ;
106
+ }
94
107
} ) ;
95
108
96
- it ( 'gzip.uncompress(buffer, destFile)' , function * ( ) {
109
+ it ( 'gzip.uncompress(buffer, destFile)' , async ( ) => {
97
110
const sourceBuffer = fs . readFileSync ( path . join ( __dirname , '..' , 'fixtures' , 'xx.log.gz' ) ) ;
98
111
const originalFile = path . join ( __dirname , '..' , 'fixtures' , 'xx.log' ) ;
99
112
const destFile = path . join ( os . tmpdir ( ) , uuid . v4 ( ) + '.log' ) ;
100
- yield compressing . gzip . uncompress ( sourceBuffer , destFile ) ;
113
+ await compressing . gzip . uncompress ( sourceBuffer , destFile ) ;
101
114
assert ( fs . existsSync ( destFile ) ) ;
102
- assert ( fs . readFileSync ( destFile , 'utf8' ) === fs . readFileSync ( originalFile , 'utf8' ) ) ;
115
+ if ( ! isWindows ) {
116
+ // EOL not equal to linux
117
+ assert ( fs . readFileSync ( destFile , 'utf8' ) === fs . readFileSync ( originalFile , 'utf8' ) ) ;
118
+ }
103
119
} ) ;
104
120
} ) ;
105
121
} ) ;
0 commit comments