-
Notifications
You must be signed in to change notification settings - Fork 710
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from gzip to deflate for compression
Resolves #2796
- Loading branch information
Showing
3 changed files
with
9 additions
and
8 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
6 changes: 3 additions & 3 deletions
6
src/lib/output/themes/default/assets/typedoc/utils/decompress.ts
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,15 +1,15 @@ | ||
/** | ||
* Decompresses Base64-encoded Gzip data and parses it into a JSON object. | ||
* Decompresses Base64-encoded deflate compressed data and parses it into a JSON object. | ||
* | ||
* @param base64 - The Base64-encoded string representing the Gzip-compressed JSON string. | ||
* @param base64 - The Base64-encoded string representing the deflate-compressed JSON string. | ||
* @returns A promise that resolves to the parsed JSON object. | ||
*/ | ||
export async function decompressJson(base64: string) { | ||
const binaryData = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0)); | ||
const blob = new Blob([binaryData]); | ||
const decompressedStream = blob | ||
.stream() | ||
.pipeThrough(new DecompressionStream("gzip")); | ||
.pipeThrough(new DecompressionStream("deflate")); | ||
const decompressedText = await new Response(decompressedStream).text(); | ||
return JSON.parse(decompressedText); | ||
} |
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,15 +1,15 @@ | ||
import { gzip } from "zlib"; | ||
import { deflate } from "zlib"; | ||
import { promisify } from "util"; | ||
|
||
const gzipP = promisify(gzip); | ||
const deflateP = promisify(deflate); | ||
|
||
/** | ||
* Compresses a JSON-serializable object into a Base64-encoded Gzip string. | ||
* Compresses a JSON-serializable object into a Base64-encoded deflate string. | ||
* | ||
* @param data - The JSON-serializable object to compress. | ||
* @returns A promise that resolves to a Base64-encoded string of the Gzip-compressed data. | ||
* @returns A promise that resolves to a Base64-encoded string of the deflate-compressed data. | ||
*/ | ||
export async function compressJson(data: any) { | ||
const gz = await gzipP(Buffer.from(JSON.stringify(data))); | ||
const gz = await deflateP(Buffer.from(JSON.stringify(data))); | ||
return gz.toString("base64"); | ||
} |