Change compressors to return Uint8Array

This commit is contained in:
Kenny Daniel 2024-02-27 19:45:52 -08:00
parent b378bd85fd
commit 0f4708b954
No known key found for this signature in database
GPG Key ID: 90AB653A8CAD7E45
4 changed files with 5 additions and 6 deletions

@ -34,7 +34,7 @@
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jsdoc": "48.2.0",
"http-server": "14.1.1",
"hysnappy": "0.2.0",
"hysnappy": "0.3.0",
"typescript": "5.3.3",
"vitest": "1.3.1"
}

@ -182,8 +182,7 @@ export function decompressPage(compressedBytes, uncompressed_page_size, codec, c
if (codec === 'UNCOMPRESSED') {
page = compressedBytes
} else if (customDecompressor) {
page = new Uint8Array(uncompressed_page_size)
customDecompressor(compressedBytes, page)
page = customDecompressor(compressedBytes, uncompressed_page_size)
} else if (codec === 'SNAPPY') {
page = new Uint8Array(uncompressed_page_size)
snappyUncompress(compressedBytes, page)

2
src/types.d.ts vendored

@ -134,7 +134,7 @@ export type CompressionCodec =
'LZ4_RAW'
export type Compressors = {
[K in CompressionCodec]?: (input: Uint8Array, output: Uint8Array) => void
[K in CompressionCodec]?: (input: Uint8Array, outputLength: number) => Uint8Array
}
interface KeyValue {

@ -10,9 +10,9 @@ import { fileToAsyncBuffer, fileToJson } from './helpers.js'
* @type {Compressors}
*/
const compressors = {
GZIP: (/** @type {Uint8Array} */ input, /** @type {Uint8Array} */ output) => {
GZIP: (/** @type {Uint8Array} */ input, /** @type {number} */ outputLength) => {
const result = gunzipSync(input)
output.set(result)
return new Uint8Array(result.buffer, result.byteOffset, outputLength)
},
}