🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

streamx

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

streamx - npm Package Compare versions

Comparing version

to
2.4.0

28

index.js

@@ -87,2 +87,3 @@ const { EventEmitter } = require('events')

const WRITE_QUEUED_AND_UNDRAINED = WRITE_QUEUED | WRITE_UNDRAINED
const WRITE_QUEUED_AND_ACTIVE = WRITE_QUEUED | WRITE_ACTIVE
const WRITE_DRAIN_STATUS = WRITE_QUEUED | WRITE_UNDRAINED | OPEN_STATUS | WRITE_ACTIVE

@@ -140,2 +141,15 @@ const WRITE_STATUS = OPEN_STATUS | WRITE_ACTIVE | WRITE_QUEUED

autoBatch (data, cb) {
const buffer = []
const stream = this.stream
buffer.push(data)
while ((stream._duplexState & WRITE_STATUS) === WRITE_QUEUED_AND_ACTIVE) {
buffer.push(stream._writableState.shift())
}
if ((stream._duplexState & OPEN_STATUS) !== 0) return cb(null)
stream._writev(buffer, cb)
}
update () {

@@ -654,2 +668,3 @@ const stream = this.stream

if (opts) {
if (opts.writev) this._writev = opts.writev
if (opts.write) this._write = opts.write

@@ -660,6 +675,10 @@ if (opts.final) this._final = opts.final

_write (data, cb) {
_writev (batch, cb) {
cb(null)
}
_write (data, cb) {
this._writableState.autoBatch(data, cb)
}
_final (cb) {

@@ -692,2 +711,3 @@ cb(null)

if (opts) {
if (opts.writev) this._writev = opts.writev
if (opts.write) this._write = opts.write

@@ -698,6 +718,10 @@ if (opts.final) this._final = opts.final

_write (data, cb) {
_writev (batch, cb) {
cb(null)
}
_write (data, cb) {
this._writableState.autoBatch(data, cb)
}
_final (cb) {

@@ -704,0 +728,0 @@ cb(null)

2

package.json
{
"name": "streamx",
"version": "2.3.0",
"version": "2.4.0",
"description": "An iteration of the Node.js core streams with a series of improvements",

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

@@ -284,2 +284,9 @@ # streamx

#### `ws._writev(batch, callback)`
Similar to `_write` but passes an array of all data in the current write buffer instead of the oldest one.
Useful if the destination you are writing the data to supports batching.
Can also be set using `options.writev` in the constructor.
#### `ws.end()`

@@ -286,0 +293,0 @@

@@ -79,1 +79,26 @@ const tape = require('tape')

})
tape('writev', function (t) {
const expected = [[], ['ho']]
const s = new Writable({
writev (batch, cb) {
t.same(batch, expected.shift())
cb(null)
}
})
for (let i = 0; i < 100; i++) {
expected[0].push('hi-' + i)
s.write('hi-' + i)
}
s.on('drain', function () {
s.write('ho')
s.end()
})
s.on('finish', function () {
t.end()
})
})