Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
dope-stream
Advanced tools
A simple and chain-able library to work with streams. It supports back-pressure by default by enforcing function as async.
A simple and chain-able library to work with streams. It supports back-pressure by default by enforcing function as async.
There are 2 different pipes in this library.
this is a fundamental building block which dictates 3 main functions, map
, filter
and forEach
.
interface Pipe<Value> {
map<NewValue>(fn: (val: Value) => Promise<NewValue>): Pipe<NewValue>
filter(fn: (val: Value) => Promise<boolean>): Pipe<Value>
forEach(fn: (val: Value) => Promise<void>): void
}
this is an extended version of Pipe
but with the ability to push values into the pipe.
export interface PushPipe<Value> extends Pipe<Value> {
push(val: Value): Promise<void>
}
push
method is a promised method. One interesting feature of push
is that if any method inside pipe throws an exception you can catch it.
import { createPushPipe } from 'dope-stream'
const pipe = createPushPipe<number>()
pipe.map(async (val) => {
if (n === 0) {
throw "value should not be zero"
}
return 1/n
}).forEach(async (val) => {
console.log(`the value is: ${val}`)
})
try {
await pipe.push(1) // this is OK
await pipe.push(2) // this is OK
await pipe.push(0) // this will catch the error
} catch (e) {
//
}
There is a special case of PushPipe which works with Readable streams
import { Readable } from 'stream'
import { createSourcePipe } from 'dope-stream'
class DummyReadable extends Readable {
constructor() {
super({
objectMode: true,
read: () => {
this.push({ data: new Date() })
},
highWaterMark: 10,
})
}
}
const source = new DummyReadable()
source.pause() // pause the stream
// create a pipe out of source which is a Readable stream
const pipe = createSourcePipe(source)
pipe.map(async (msg) => {
return msg
}).forEach(async (msg) => {
console.log(msg)
})
Note: Because each function in pipe is an async function, the back-pressure automatically created for you behind the scene. So once the
forEach
returns, then the next message will extract from source and pass down through pipe.
FAQs
A simple and chain-able library to work with streams. It supports back-pressure by default by enforcing function as async.
We found that dope-stream demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.