-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e43e918
commit ca3beaf
Showing
9 changed files
with
25 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
import * as zlib from 'node:zlib'; | ||
|
||
// 输入是一个对象,输出是一个 Buffer | ||
export async function compressedData(input) { | ||
const options = { | ||
params: { | ||
[zlib.constants.BROTLI_PARAM_QUALITY]: 11, // 设置压缩质量 | ||
}, | ||
}; | ||
|
||
const compressed = zlib.brotliCompressSync(input, options); | ||
return compressed; | ||
return zlib.brotliCompressSync(JSON.stringify(input), options); | ||
} | ||
|
||
// 输入是一个 Buffer,输出是一个对象 | ||
export async function decompressedData(compressedData) { | ||
if (compressedData.length === 0) { | ||
return '{}'; | ||
} | ||
const decompressed = zlib.brotliDecompressSync(compressedData); | ||
return decompressed; | ||
return JSON.parse(decompressed.toString()); | ||
} |
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,7 @@ | ||
import * as zlib from "node:zlib"; | ||
|
||
export async function compressedData(input) { | ||
const options = { | ||
params: { | ||
[zlib.constants.BROTLI_PARAM_QUALITY]: 11, // 设置压缩质量 | ||
}, | ||
}; | ||
|
||
const compressed = zlib.brotliCompressSync(input, options); | ||
return compressed; | ||
} | ||
|
||
// 输入是一个 Buffer,输出是一个对象 | ||
export async function decompressedData(compressedData) { | ||
const decompressed = zlib.brotliDecompressSync(compressedData); | ||
return decompressed; | ||
return JSON.parse(decompressed.toString()); | ||
} |