mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-27 07:50:47 +00:00
b348ddcbb9
Add buffer compression helpers, an envelope codec, and a legacy package-cache decoder. Hoist package cache reads into the base backend so file, Redis, and SQLite share format detection, legacy fallback, and corrupt-entry handling while preserving existing write formats.
32 lines
932 B
TypeScript
32 lines
932 B
TypeScript
import { promisify } from 'node:util';
|
|
import zlib, { constants } from 'node:zlib';
|
|
|
|
const brotliCompress = promisify(zlib.brotliCompress);
|
|
const brotliDecompress = promisify(zlib.brotliDecompress);
|
|
|
|
export async function compressToBuffer(
|
|
input: string,
|
|
quality = 8,
|
|
): Promise<Buffer> {
|
|
return await brotliCompress(input, {
|
|
params: {
|
|
[constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_TEXT,
|
|
[constants.BROTLI_PARAM_QUALITY]: quality,
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function decompressFromBuffer(input: Buffer): Promise<string> {
|
|
const str = await brotliDecompress(input);
|
|
return str.toString('utf8');
|
|
}
|
|
|
|
export async function compressToBase64(input: string): Promise<string> {
|
|
const buf = await compressToBuffer(input);
|
|
return buf.toString('base64');
|
|
}
|
|
|
|
export async function decompressFromBase64(input: string): Promise<string> {
|
|
return await decompressFromBuffer(Buffer.from(input, 'base64'));
|
|
}
|