From 191a4ec16a3d95566a0d546bd7dd463d90dbc87b Mon Sep 17 00:00:00 2001 From: jeromew Date: Tue, 23 Aug 2016 11:32:10 +0200 Subject: [PATCH] Fix documentation of copy-from completion --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 853dae7..5d14872 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,15 @@ pg.connect(function(err, client, done) { var stream = client.query(copyFrom('COPY my_table FROM STDIN')); var fileStream = fs.createReadStream('some_file.tsv') fileStream.on('error', done); - fileStream.pipe(stream).on('finish', done).on('error', done); + stream.on('error', done); + stream.on('end', done); + fileStream.pipe(stream); }); ``` +*Important*: Even if `pg-copy-streams.from` is used as a Writable (via `pipe`), you should not listen for the 'finish' event and expect that the COPY command has already been correctly acknowledged by the database. Internally, a duplex stream is used to pipe the data into the database connection and the COPY command should be considered complete only when the 'end' event is triggered. + + ## install ```sh