Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

bare-stream

Package Overview
Dependencies
Maintainers
3
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bare-stream - npm Package Compare versions

Comparing version
2.10.0
to
2.11.0
+16
-1
index.d.ts
import EventEmitter, { EventMap } from 'bare-events'
import Buffer, { BufferEncoding } from 'bare-buffer'
import { AbortSignal } from 'bare-abort-controller'

@@ -55,2 +56,5 @@ type StreamEncoding = BufferEncoding | 'buffer'

readonly closed: boolean
readonly errored: Error | null
push(data: unknown | null, encoding?: BufferEncoding): boolean

@@ -95,3 +99,4 @@ unshift(data: unknown | null, encoding?: BufferEncoding): boolean

readonly destroyed: boolean
readonly closed: boolean
readonly errored: Error | null

@@ -171,2 +176,4 @@ write(data: unknown, encoding?: BufferEncoding, cb?: StreamCallback): boolean

export function duplexPair(opts?: DuplexOptions): [Duplex, Duplex]
export function finished(

@@ -188,5 +195,13 @@ stream: Stream,

export function isErrored(stream: Stream): boolean
export function isReadable(stream: Stream): boolean
export function isWritable(stream: Stream): boolean
export function getStreamError(stream: Stream, opts?: { all?: boolean }): Error | null
export function addAbortSignal<S extends Stream>(signal: AbortSignal, stream: S): S
}
export = Stream

@@ -16,4 +16,27 @@ const stream = require('streamx')

exports.isErrored = function isErrored(stream) {
return exports.getStreamError(stream) !== null
}
exports.isReadable = function isReadable(stream) {
return stream.readable && !stream.destroying && !exports.isEnded(stream)
}
exports.isWritable = function isWritable(stream) {
return stream.writable && !stream.destroying && !exports.isFinishing(stream)
}
exports.getStreamError = stream.getStreamError
exports.addAbortSignal = function addAbortSignal(signal, stream) {
function onAbort() {
stream.destroy(signal.reason)
}
if (signal.aborted) onAbort()
else signal.addEventListener('abort', onAbort)
return stream
}
exports.Stream = exports

@@ -42,2 +65,10 @@

get closed() {
return !exports.isReadable(this)
}
get errored() {
return stream.getStreamError(this)
}
push(chunk, encoding) {

@@ -58,2 +89,8 @@ if (typeof chunk === 'string') {

}
async [Symbol.asyncDispose]() {
if (!this.destroyed) this.destroy()
await new Promise((resolve) => exports.finished(this, resolve))
}
}

@@ -82,2 +119,10 @@

get closed() {
return !exports.isWritable(this)
}
get errored() {
return stream.getStreamError(this)
}
write(chunk, encoding, cb) {

@@ -126,2 +171,8 @@ if (typeof encoding === 'function') {

}
async [Symbol.asyncDispose]() {
if (!this.destroyed) this.destroy()
await new Promise((resolve) => exports.finished(this, resolve))
}
}

@@ -217,2 +268,39 @@

class DuplexSide extends exports.Duplex {
constructor(opts) {
super(opts)
this._otherSide = null
this._cb = null
}
_read() {
const cb = this._cb
if (!cb) return
this._cb = null
cb()
}
_write(chunk, encoding, cb) {
this._otherSide.push(chunk, encoding)
this._otherSide._cb = cb
}
_final(cb) {
this._otherSide.on('end', cb)
this._otherSide.push(null)
}
}
exports.duplexPair = function duplexPair(opts) {
const sideA = new DuplexSide(opts)
const sideB = new DuplexSide(opts)
sideA._otherSide = sideB
sideB._otherSide = sideA
return [sideA, sideB]
}
exports.Transform = class Transform extends stream.Transform {

@@ -219,0 +307,0 @@ constructor(opts = {}) {

{
"name": "bare-stream",
"version": "2.10.0",
"version": "2.11.0",
"description": "Streaming data for JavaScript",

@@ -44,2 +44,3 @@ "exports": {

"devDependencies": {
"bare-abort-controller": "^1.1.0",
"bare-buffer": "^3.0.0",

@@ -52,2 +53,3 @@ "bare-events": "^2.5.4",

"peerDependencies": {
"bare-abort-controller": "*",
"bare-buffer": "*",

@@ -57,2 +59,5 @@ "bare-events": "*"

"peerDependenciesMeta": {
"bare-abort-controller": {
"optional": true
},
"bare-buffer": {

@@ -59,0 +64,0 @@ "optional": true