**`TransformStream` variants of `CSVReader` and `CSVWriter`**: You can now create `TransformStream` versions of both `CSVReader` and `CSVWriter` by passing nothing to the constructor. This behavior is useful for (1) if you have some intermediate transformations you'd like to perform on data before you parse or stringify CSV data (e.g., gzip compression or decompression via the Compression Streams API), or (2) if you want to bring your own underlying source or ultimate sink of CSV data (e.g., from over network).
```javascript
import { CSVReader, CSVWriter } from '@ardislu/csvio';
// Could be any source other than a local file, e.g. a fetch response body.
const underlyingSource = ReadableStream.from((function* () {
yield 'header1,header2,header3\r\n';
yield '1,2,3\r\n';
yield '4,5,6\r\n';
})());
// Could be any stream sink other than a local file, e.g. a fetch request body.
const ultimateSink = new WritableStream({
write(row) {
console.log(row);
}
});
underlyingSource
.pipeThrough(new CSVReader()) // Returns a TransformStream that does CSV parse
.pipeThrough(new CSVTransformer(r => r))
.pipeThrough(new CSVWriter()) // Returns a TransformStream that does CSV stringify
.pipeTo(ultimateSink)
// header1,header2,header3
// 1,2,3
// 4,5,6
```
**Performance improvements**: This release removes all instances of intermediate JSON serialization/deserialization (i.e., `JSON.parse()` and `JSON.stringify()` calls) that were previously used in between each stream. Now, raw objects (or copies of the objects) are directly passed between streams, improving performance.
**Other**: Added type improvements, documentation improvements, additional tests, and `CONTRIBUTING.md` checklist for quality assurance.
-----BEGIN SSH SIGNATURE-----
U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAg4OaSdijsW6raSPK3llrsZIEdtk
SQaGaXESF8DcruCNgAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5
AAAAQFHrGFwfhpTn475CXidJXW1LSe5Lht3Ey8QgcPY4pLnPSBeT9wDs4IDhVNQuxVGUmq
7O9gK7bKQPXEt1MUk6HAk=
-----END SSH SIGNATURE-----
This page took 0.042789 seconds and 3 git commands to generate.