@@ -3,28 +3,28 @@ import { resolve, basename, parse } from 'path';
3
3
import { createBrotliDecompress , createBrotliCompress } from 'zlib' ;
4
4
5
5
export const brotli = async ( option , path , newPath ) => {
6
- const EXT = 'br' ;
6
+ const EXT = 'br' ;
7
7
try {
8
8
const needCompress = option === 'compress' ;
9
9
10
- const fileToConvertPath = resolve ( process . cwd ( ) , path ) ;
10
+ const filePath = resolve ( process . cwd ( ) , path ) ;
11
11
12
- const baseName = basename ( fileToConvertPath ) ;
12
+ const baseName = basename ( filePath ) ;
13
13
const fileName = parse ( baseName ) . name ;
14
14
15
- const fileNameToWrite = needCompress ? `${ baseName } .${ EXT } ` : fileName ;
16
- const dirToWritePath = resolve ( process . cwd ( ) , newPath ) ;
17
- const fileToWritePath = resolve ( dirToWritePath , fileNameToWrite ) ;
15
+ const newFileName = needCompress ? `${ baseName } .${ EXT } ` : fileName ;
16
+ const dirPath = resolve ( process . cwd ( ) , newPath ) ;
17
+ const brotliPath = resolve ( dirPath , newFileName ) ;
18
18
19
19
await new Promise ( ( res , rej ) => {
20
- const fileToConvert = createReadStream ( fileToConvertPath ) ;
21
- const fileToWrite = createWriteStream ( fileToWritePath , { flags : 'wx' , } ) ;
20
+ const file = createReadStream ( filePath ) ;
21
+ const brotliFile = createWriteStream ( brotliPath , { flags : 'wx' , } ) ;
22
22
23
23
const brotliHandler = needCompress ? createBrotliCompress ( ) : createBrotliDecompress ( ) ;
24
24
25
- fileToConvert . pipe ( brotliHandler ) . pipe ( fileToWrite ) ;
26
- fileToConvert . on ( 'error' , rej ) ;
27
- fileToConvert . on ( 'end' , res ) ;
25
+ file . pipe ( brotliHandler ) . pipe ( brotliFile ) ;
26
+ file . on ( 'error' , rej ) ;
27
+ file . on ( 'end' , res ) ;
28
28
} ) ;
29
29
} catch ( err ) {
30
30
throw err ;
0 commit comments