22MIT License http://www.opensource.org/licenses/mit-license.php 
33Author Tobias Koppers @sokra 
44*/ 
5+ import  crypto  from  'crypto' ; 
56import  url  from  'url' ; 
67import  async  from  'async' ; 
78import  RawSource  from  'webpack-sources/lib/RawSource' ; 
@@ -75,13 +76,13 @@ class CompressionPlugin {
7576        } 
7677
7778        const  asset  =  assets [ file ] ; 
78-         let  content  =  asset . source ( ) ; 
79+         let  input  =  asset . source ( ) ; 
7980
80-         if  ( ! Buffer . isBuffer ( content ) )  { 
81-           content  =  new   Buffer ( content ,   'utf8' ) ; 
81+         if  ( ! Buffer . isBuffer ( input ) )  { 
82+           input  =  Buffer . from ( input ) ; 
8283        } 
8384
84-         const  originalSize  =  content . length ; 
85+         const  originalSize  =  input . length ; 
8586
8687        if  ( originalSize  <  threshold )  { 
8788          return  cb ( ) ; 
@@ -96,8 +97,8 @@ class CompressionPlugin {
9697                node : process . version , 
9798                'compression-webpack-plugin' : pkg . version , 
9899                'compression-webpack-plugin-options' : this . options , 
99-                 file, 
100-                 content , 
100+                 path :  compiler . outputPath  ?  ` ${ compiler . outputPath } / ${ file } `  :  file , 
101+                 hash :  crypto . createHash ( 'md5' ) . update ( input ) . digest ( 'hex' ) , 
101102              } ) ; 
102103
103104              return  cacache 
@@ -106,15 +107,15 @@ class CompressionPlugin {
106107                  result  =>  result . data , 
107108                  ( )  =>  Promise 
108109                    . resolve ( ) 
109-                     . then ( ( )  =>  this . compress ( content ) ) 
110+                     . then ( ( )  =>  this . compress ( input ) ) 
110111                    . then ( 
111112                      data  =>  cacache . put ( cacheDir ,  cacheKey ,  data ) 
112113                        . then ( ( )  =>  data ) , 
113114                    ) , 
114115                ) ; 
115116            } 
116117
117-             return  this . compress ( content ) ; 
118+             return  this . compress ( input ) ; 
118119          } ) 
119120          . then ( ( result )  =>  { 
120121            if  ( result . length  /  originalSize  >  minRatio )  {  return  cb ( ) ;  } 
@@ -145,11 +146,11 @@ class CompressionPlugin {
145146    } ) ; 
146147  } 
147148
148-   compress ( content )  { 
149+   compress ( input )  { 
149150    return  new  Promise ( ( resolve ,  reject )  =>  { 
150151      const  {  algorithm,  compressionOptions }  =  this . options ; 
151152
152-       algorithm ( content ,  compressionOptions ,  ( error ,  result )  =>  { 
153+       algorithm ( input ,  compressionOptions ,  ( error ,  result )  =>  { 
153154        if  ( error )  { 
154155          return  reject ( error ) ; 
155156        } 
0 commit comments