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

debugging-stream

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

debugging-stream - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

2

example.js
const Debugging = require('./')
const l = new Debugging(process.stdin, { latency: { read: [1500, 2500], connect: 5000 } })
const l = new Debugging(process.stdin, { latency: [1500, 2000] })

@@ -5,0 +5,0 @@ l.on('data', function (data) {

const { Duplex } = require('streamx')
module.exports = class DebuggingStream extends Duplex {
constructor (stream, { random = Math.random, latency = {} } = {}) {
constructor (stream, { random = Math.random, latency = 0 } = {}) {
super()
const { read = 0, connect = 0 } = latency
this._random = random
this._latency = toRange(read)
this._latency = toRange(latency)
this._queued = []
this._ondrain = null
this._connecting = true
const c = toRange(connect)
this._start = 0
this._connectLatency = c.start + Math.round(this._random() * c.variance)
this.stream = stream

@@ -52,17 +44,7 @@

_queue (evt) {
let l = this._connectLatency + this._latency.start + Math.round(this._random() * this._latency.variance)
const first = this._connecting
const l = this._latency.start + Math.round(this._random() * this._latency.variance)
if (first) {
this._start = Date.now()
} else {
const delta = Math.min(Date.now() - this._start, this._connectLatency)
l -= delta
}
this._connecting = false
this._queued.push(evt)
setTimeout(() => {
if (first) this._connectLatency = 0
evt.pending = false

@@ -112,6 +94,2 @@ this._drain()

}
_latency () {
return this._start + Math.round(Math.random() * this._var)
}
}

@@ -118,0 +96,0 @@

{
"name": "debugging-stream",
"version": "1.0.0",
"version": "2.0.0",
"description": "Debug streams, by adding latency etc",

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

@@ -15,6 +15,3 @@ # debugging-stream

const s = new DebuggingStream(anotherStream, {
latency: {
read: [100, 200] // add between 100-200ms read latency,
connect: [300, 500] // add between 300-500ms connect latency
}
latency: [100, 200] // add between 100-200ms read latency,
})

@@ -21,0 +18,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