From e378251a5b5b7e1a4ace358270cf012bc1822265 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Wed, 20 Aug 2025 00:14:44 -0700 Subject: [PATCH] Remove platform-specific data from test gzip file This step is not required for real-world usage, but for testing purposes it is useful to share the same tests and test data across platforms. --- test/core.test.js | 3 ++- test/data/simple.csv.gz | Bin 75 -> 75 bytes test/utils.js | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/test/core.test.js b/test/core.test.js index de0e339..db893e7 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -6,7 +6,7 @@ import { setTimeout } from 'node:timers/promises'; import { pathToFileURL } from 'node:url'; import { ReadableStream, DecompressionStream, CompressionStream, TextDecoderStream } from 'node:stream/web'; -import { csvStreamEqualWritable, createCSVMockStream, createTempFile, createWritableFileStream } from './utils.js'; +import { csvStreamEqualWritable, createCSVMockStream, createTempFile, createWritableFileStream, setGzipOSByteToUnknown } from './utils.js'; import { parsePathLike, createFileStream, CSVReader, CSVTransformer, CSVWriter } from '../src/core.js'; suite('CSVWriter.arrayToCSVString', { concurrency: true }, () => { @@ -742,6 +742,7 @@ suite('CSVWriter', { concurrency: true }, () => { .pipeThrough(new CSVWriter()) .pipeThrough(new CompressionStream('gzip')) .pipeTo(createWritableFileStream(temp)); + await setGzipOSByteToUnknown(temp); // Allows this test to work across platforms const expected = await readFile(output); const actual = await readFile(temp); ok(actual.equals(expected)); diff --git a/test/data/simple.csv.gz b/test/data/simple.csv.gz index f13bea0caa63b5ab37ed4177b4e2b17c95e4b5aa..e0f98afe634b6d309c3af7c6b5293417daf2f1c1 100644 GIT binary patch delta 16 TcmebF=92H`U;u;v6S*7#7$gHO delta 16 TcmebF=92H`U;qQIiCm5V6i@;= diff --git a/test/utils.js b/test/utils.js index a7b5adb..2745924 100644 --- a/test/utils.js +++ b/test/utils.js @@ -238,3 +238,18 @@ export function createWritableFileStream(path) { } }); } + +/** + * Sets the "OS" (filesystem) header byte of a given gzip file to `255` ("Unknown"). This function + * is useful to strip a gzip file of platform-specific metadata. + * + * @param {PathLike} path A `string`, `Buffer`, or `URL` representing a path to a local file. + */ +export async function setGzipOSByteToUnknown(path) { + // https://en.wikipedia.org/wiki/Gzip#File_structure + const offset = 9; + const byte = new Uint8Array([255]); + const file = await open(path, 'r+'); + await file.write(byte, 0, 1, offset); + await file.close(); +} -- 2.47.3