Socket
Socket
Sign inDemoInstall

thread-stream

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

thread-stream - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

.husky/pre-commit

62

index.js

@@ -34,2 +34,31 @@ 'use strict'

function nextFlush (stream) {
const writeIndex = Atomics.load(stream._state, WRITE_INDEX)
const leftover = stream._data.length - writeIndex
if (leftover > 0) {
if (stream.buf.length === 0) {
stream.flushing = false
if (!stream.needDrain) {
// process._rawDebug('emitting drain')
stream.needDrain = true
process.nextTick(drain, stream)
}
return
}
// TODO handle truncated utf-8 chunks
const toWrite = stream.buf.slice(0, leftover)
stream.buf = stream.buf.slice(leftover)
stream._write(toWrite, nextFlush.bind(null, stream))
} else if (leftover === 0) {
stream.flush(() => {
Atomics.store(stream._state, READ_INDEX, 0)
Atomics.store(stream._state, WRITE_INDEX, 0)
nextFlush(stream)
})
} else {
throw new Error('overwritten')
}
}
class ThreadStream extends EventEmitter {

@@ -128,30 +157,5 @@ constructor (opts = {}) {

const next = () => {
const writeIndex = Atomics.load(this._state, WRITE_INDEX)
const leftover = this._data.length - writeIndex
if (leftover > 0) {
if (this.buf.length === 0) {
this.flushing = false
cb()
return
}
// TODO handle truncated utf-8 chunks
const toWrite = this.buf.slice(0, leftover)
this.buf = this.buf.slice(leftover)
this._write(toWrite, next)
} else if (leftover === 0) {
this.flush(() => {
Atomics.store(this._state, READ_INDEX, 0)
Atomics.store(this._state, WRITE_INDEX, 0)
next()
})
} else {
throw new Error('overwritten')
}
}
this.buf = data
this.flushing = true
next()
setImmediate(nextFlush, this)

@@ -187,2 +191,4 @@ return false

this.emit('error', err)
cb(err)
return
}

@@ -199,2 +205,6 @@ if (res === 'not-equal') {

flushSync () {
if (this.flushing) {
throw new Error('unable to flush while flushing')
}
const writeIndex = Atomics.load(this._state, WRITE_INDEX)

@@ -201,0 +211,0 @@

{
"name": "thread-stream",
"version": "0.2.0",
"version": "0.2.1",
"description": "A streaming way to send data to a Node.js Worker Thread",

@@ -15,8 +15,6 @@ "main": "index.js",

},
"hooks": {
"pre-commit": "npm test"
},
"scripts": {
"cov": "nyc tape test/*.test.js | tap-dot",
"test": "standard && tape test/*.test.js | tap-dot"
"test": "standard && tape test/*.test.js | tap-dot",
"prepare": "husky install"
},

@@ -23,0 +21,0 @@ "repository": {

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