import { suite, test } from 'node:test';
import { ok, deepStrictEqual, throws, rejects } from 'node:assert/strict';
+import { createWriteStream } from 'node:fs';
import { unlink, readFile } from 'node:fs/promises';
import { normalize, basename, resolve } from 'node:path';
import { setTimeout } from 'node:timers/promises';
import { pathToFileURL } from 'node:url';
+import { Writable } from 'node:stream';
import { ReadableStream, DecompressionStream, CompressionStream, TextDecoderStream } from 'node:stream/web';
-import { csvStreamEqualWritable, createCSVMockStream, createTempFile, createWritableFileStream, setGzipOSByteToUnknown } from './utils.js';
+import { csvStreamEqualWritable, createCSVMockStream, createTempFile, setGzipOSByteToUnknown } from './utils.js';
import { parsePathLike, createFileStream, CSVReader, CSVTransformer, CSVWriter } from '../src/core.js';
suite('CSVWriter.arrayToCSVString', { concurrency: true }, () => {
await new CSVReader(input)
.pipeThrough(new CSVWriter())
.pipeThrough(new CompressionStream('gzip'))
- .pipeTo(createWritableFileStream(temp));
+ .pipeTo(Writable.toWeb(createWriteStream(temp)));
await setGzipOSByteToUnknown(temp); // Allows this test to work across platforms
const expected = await readFile(output);
const actual = await readFile(temp);
return ReadableStream.from(chunks);
}
-/**
- * Creates a writable file stream for a local file.
- *
- * @see {@link https://streams.spec.whatwg.org/#example-ws-backpressure}
- * @param {PathLike} path A `string`, `Buffer`, or `URL` representing a path to a local file.
- * @returns {WritableStream<Uint8Array<ArrayBuffer>>}
- */
-export function createWritableFileStream(path) {
- /** @type {FileHandle} */
- let handle;
-
- return new WritableStream({
- async start() {
- handle = await open(path, 'w');
- },
- async write(chunk) {
- await handle.write(chunk, 0, chunk.length);
- },
- async close() {
- await handle.close();
- },
- async abort() {
- await handle.close();
- }
- });
-}
-
/**
* 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.