]> git.ardis.lu - csvio/commitdiff
Remove platform-specific data from test gzip file
authorArdis Lu <ardisglu@gmail.com>
Wed, 20 Aug 2025 07:14:44 +0000 (00:14 -0700)
committerArdis Lu <ardisglu@gmail.com>
Wed, 20 Aug 2025 07:14:44 +0000 (00:14 -0700)
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
test/data/simple.csv.gz
test/utils.js

index de0e3390b765efcded945112a5c678c4806b3d60..db893e78da14b6f614b8b8c7ce2814a5cd4f46f8 100644 (file)
@@ -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));
index f13bea0caa63b5ab37ed4177b4e2b17c95e4b5aa..e0f98afe634b6d309c3af7c6b5293417daf2f1c1 100644 (file)
Binary files a/test/data/simple.csv.gz and b/test/data/simple.csv.gz differ
index a7b5adbefd5d9a91fdb1c1db74815a7b583de58f..27459247dc5cc4e4f61b3cdefd37b6375e3e3e4a 100644 (file)
@@ -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();
+}
This page took 0.037175 seconds and 4 git commands to generate.