File tree Expand file tree Collapse file tree 4 files changed +11
-15
lines changed Expand file tree Collapse file tree 4 files changed +11
-15
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @alicloud/gateway-sls" ,
3- "version" : " 0.3.0 " ,
3+ "version" : " 0.3.1 " ,
44 "description" : " " ,
55 "main" : " dist/client.js" ,
66 "scripts" : {
2929 "@alicloud/darabonba-array" : " ^0.1.0" ,
3030 "@alicloud/darabonba-encode-util" : " ^0.0.2" ,
3131 "@alicloud/darabonba-signature-util" : " ^0.0.4" ,
32- "@alicloud/gateway-sls-util" : " ^0.3.0 "
32+ "@alicloud/gateway-sls-util" : " ^0.3.1 "
3333 },
3434 "files" : [
3535 " dist" ,
Original file line number Diff line number Diff line change 11{
22 "name" : " @alicloud/gateway-sls-util" ,
3- "version" : " 0.3.0 " ,
3+ "version" : " 0.3.1 " ,
44 "description" : " " ,
55 "main" : " dist/client.js" ,
66 "scripts" : {
1212 "author" : " " ,
1313 "license" : " ISC" ,
1414 "devDependencies" : {
15- "@types/lz4" : " ^0.6.4" ,
1615 "@types/node" : " ^12.12.26" ,
1716 "nyc" : " ^15.0.0" ,
1817 "source-map-support" : " ^0.5.16" ,
1918 "ts-node" : " ^8.6.2" ,
2019 "typescript" : " ^3.7.5"
2120 },
2221 "dependencies" : {
23- "lz4" : " ^0.6.5 "
22+ "lz4-napi " : " ^2.9.0 "
2423 },
2524 "files" : [
2625 " dist" ,
Original file line number Diff line number Diff line change 1- import lz4 from 'lz4' ;
1+ import { compress as napiLz4Compress } from 'lz4-napi ' ;
22import zlib from 'zlib' ;
33
44const supportedCompressor = [ 'lz4' , 'gzip' , 'deflate' ]
55
66export async function lz4Compress ( data : Buffer ) : Promise < Buffer > {
7- const output = Buffer . alloc ( lz4 . encodeBound ( data . length ) ) ;
8- const n = lz4 . encodeBlock ( data , output ) ;
9- return Buffer . from ( output . slice ( 0 , n ) ) ;
7+ return await napiLz4Compress ( data ) ;
108}
119
1210export async function gzipCompress ( data : Buffer ) : Promise < Buffer > {
Original file line number Diff line number Diff line change 11import { Readable } from 'stream' ;
22import { readableStreamToBuffer } from './common' ;
3- import lz4 from 'lz4' ;
3+ import { uncompress as napiLz4Uncompress } from 'lz4-napi ' ;
44import zlib from 'zlib' ;
55
66const supportedDecompressor = [ 'lz4' , 'gzip' , 'deflate' ]
@@ -10,12 +10,11 @@ export async function isDecompressorAvailable(compressType: string): Promise<boo
1010}
1111
1212export async function lz4Decompress ( input : Readable , bodyRawSize : number ) : Promise < Buffer > {
13- const output = Buffer . alloc ( bodyRawSize ) ;
14- const n = lz4 . decodeBlock ( await readableStreamToBuffer ( input ) , output ) ;
15- if ( n !== bodyRawSize ) {
16- return Buffer . from ( output . slice ( 0 , n ) ) ;
13+ const napiOutput = await napiLz4Uncompress ( await readableStreamToBuffer ( input ) ) ;
14+ if ( napiOutput . length !== bodyRawSize ) {
15+ return Buffer . from ( napiOutput . slice ( 0 , bodyRawSize ) ) ;
1716 }
18- return output ;
17+ return napiOutput ;
1918}
2019
2120export async function gzipDecompress ( input : Readable , bodyRawSize : number ) : Promise < Buffer > {
You can’t perform that action at this time.
0 commit comments