From 0f4708b9544c1acaa8ae17cbbc9673d39ab2fbe5 Mon Sep 17 00:00:00 2001 From: Kenny Daniel Date: Tue, 27 Feb 2024 19:45:52 -0800 Subject: [PATCH] Change compressors to return Uint8Array --- package.json | 2 +- src/column.js | 3 +-- src/types.d.ts | 2 +- test/read.test.js | 4 ++-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 1155739..d0d0549 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/src/column.js b/src/column.js index d5e2456..143dc29 100644 --- a/src/column.js +++ b/src/column.js @@ -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) diff --git a/src/types.d.ts b/src/types.d.ts index 7fbedbb..8a97668 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -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 { diff --git a/test/read.test.js b/test/read.test.js index 869a36c..93bf14e 100644 --- a/test/read.test.js +++ b/test/read.test.js @@ -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) }, }