From: Ardis Lu Date: Wed, 20 Aug 2025 07:14:44 +0000 (-0700) Subject: Remove platform-specific data from test gzip file X-Git-Tag: v0.1.6~16 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=e378251a5b5b7e1a4ace358270cf012bc1822265;p=csvio 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. --- 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 f13bea0..e0f98af 100644 Binary files a/test/data/simple.csv.gz and b/test/data/simple.csv.gz differ 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(); +}