Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pg-copy-streams

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pg-copy-streams - npm Package Compare versions

Comparing version 4.0.0 to 5.0.0

51

copy-to.js

@@ -7,3 +7,3 @@ 'use strict'

const { Transform } = require('stream')
const { Readable } = require('stream')
const assert = require('assert')

@@ -18,3 +18,3 @@ const BufferList = require('obuf')

class CopyStreamQuery extends Transform {
class CopyStreamQuery extends Readable {
constructor(text, options) {

@@ -29,3 +29,5 @@ super(options)

this._pgDataHandler = null
this._errorCallback = null
this._drained = false
this._forwarding = false
this._onReadableEvent = this._onReadable.bind(this)
}

@@ -45,3 +47,5 @@

connectionStream.removeListener('data', this._pgDataHandler)
connectionStream.pipe(this)
connectionStream.pause()
this._forward()
connectionStream.on('readable', this._onReadableEvent)
}

@@ -52,3 +56,4 @@

const unreadBuffer = this._buffer.take(this._buffer.size)
connectionStream.unpipe(this)
//connectionStream.unpipe(this)
connectionStream.removeListener('readable', this._onReadableEvent)
connectionStream.addListener('data', this._pgDataHandler)

@@ -69,7 +74,28 @@ this._pgDataHandler(unreadBuffer)

this._pgDataHandler = null
this._errorCallback = null
this._onReadableEvent = null
}
_transform(chunk, enc, cb) {
_onReadable() {
this._forward()
}
_read() {
this._drained = true
this._forward()
}
_forward() {
if (this._forwarding || !this._drained || !this.connection) return
this._forwarding = true
const connectionStream = this.connection.stream
let chunk
while (this._drained && (chunk = connectionStream.read()) !== null) {
this._drained = this._parse(chunk)
}
this._forwarding = false
}
_parse(chunk) {
let done = false
let drained = true
this._buffer.push(chunk)

@@ -85,3 +111,2 @@

// the ActiveQuery
this._errorCallback = cb
this._detach()

@@ -137,3 +162,3 @@ return

if (len > 0) {
this.push(this._copyDataChunks.take(len))
drained = this.push(this._copyDataChunks.take(len))
}

@@ -143,11 +168,11 @@

this._detach()
this.end()
this.push(null)
this._cleanup()
}
cb()
return drained
}
handleError(e) {
this._errorCallback(e)
handleError(err) {
this.emit('error', err)
this._cleanup()

@@ -154,0 +179,0 @@ }

{
"name": "pg-copy-streams",
"version": "4.0.0",
"version": "5.0.0",
"description": "Low-Level COPY TO and COPY FROM streams for PostgreSQL in JavaScript using",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -57,3 +57,3 @@ ## pg-copy-streams

_Note_: In version prior to 4.0.0, when copying data into postgresql, it was necessary to wait for the 'end' event of `pg-copy-streams.from` to correctly detect the end of the COPY operation. This was necessary due to the internals of the module but non-standard. This is not true for versions including and after 4.0.0. The end of the COPY operation must now be detected via the standard 'finish' event.
_Note_: In version prior to 4.0.0, when copying data into postgresql, it was necessary to wait for the 'end' event of `pg-copy-streams.from` to correctly detect the end of the COPY operation. This was necessary due to the internals of the module but non-standard. This is not true for versions including and after 4.0.0. The end of the COPY operation must now be detected via the standard 'finish' event. **Users of 4.0.0+ should not wait for the 'end' event because it is not fired anymore.**

@@ -113,2 +113,9 @@ ## install

### version 5.0.0 - published 2020-05-14
This version's major change is a modification in the COPY TO implementation. The new implementation now extends `Readable` while previous version where extending `Transform`. This should not have an effect on how users use the module but was considered to justify a major version number because even if the test suite coverage is wide, it could have an impact on the streaming dynamics in certain edge cases that are not yet captured by the tests.
- Rewrite copy-to in order to have it extend `Readable` instead of `Transform`
### version 4.0.0 - published 2020-05-11

@@ -115,0 +122,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc