.to returns a writable stream
kilianc opened this issue · comments
Kilian Ciuffolo commented
const copyTo = require('pg-copy-streams').to
const csvStream = pg.query(exports.copyTo(dedent`
COPY (
SELECT *
FROM some_table
) TO STDOUT
WITH CSV DELIMITER ','
HEADER;
`))
console.log(csvStream.writable, csvStream.readable) // true, true
Most of the libraries out there rely on those flags, I have to manually set it to
csvStream.writable = false
to make it work!
jeromew commented
Hello @killianC thanks for the report.
Indeed under the hood the copyTo object is currently a Transform stream. It is writable because the pg connection is piped into it.
What do you mean by "Most of the libraries out there rely on those flags" ?
Reading the node.js doc on https://nodejs.org/api/stream.html#stream_writable_writable I would not think that forcing csvStream.writable = false
is a safe thing to do.
jeromew commented
feel free to reopen if needed