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 }, () => {
.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));
}
});
}
+
+/**
+ * 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();
+}