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

promise-duplex

Package Overview
Dependencies
Maintainers
0
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-duplex

Return promise for duplex stream

  • 8.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7K
increased by4.53%
Maintainers
0
Weekly downloads
 
Created
Source

promise-duplex

GitHub CI Trunk Check Coverage Status npm

This module allows to convert Duplex stream into its promisified version, which returns Promise object fulfilled when stream's events occurred.

The module combines promise-readable and promise- in one.

Requirements

This module requires Node >= 16.

Installation

npm install promise-duplex

Usage

import PromiseDuplex from "promise-duplex"

constructor

const promiseDuplex = new PromiseDuplex(stream)

PromiseDuplex object requires Duplex object to work.

Example:

import net from "node:net"
import PromiseDuplex from "promise-duplex"

const stream = new net.Socket()

const promiseDuplex = new PromiseDuplex(stream)

stream

const stream = promiseDuplex.stream

Original stream object.

Example:

console.log(promiseDuplex.stream.localAddress)

read

const chunk = await promiseDuplex.read(chunkSize)

Check PromiseReadable.read for details.

readAll

const content = await promiseDuplex.readAll()

Check PromiseReadable.readAll for details.

iterate

for await (const chunk of promiseDuplex.iterate(chunkSize)) {
}

Check PromiseReadable.iterate for details.

Symbol.asyncIterator

for await (const chunk of promiseDuplex.iterate(chunkSize)) {
}

Check PromiseReadable[Symbol.asyncIterator] for details.

setEncoding

promiseDuplex = await promiseDuplex.setEncoding(encoding)

Check PromiseReadable.setEncoding for details.

write

await promiseDuplex.write(chunk)

Check PromiseWritable.write for details.

writeAll

await promiseDuplex.writeAll(content, chunkSize)

Check PromiseWritable.writeAll for details.

end

await promiseDuplex.end()

Check PromiseWritable.once for details.

once

const result = await promiseDuplex.once(event)

Check PromiseReadable.once and PromiseWritable.once for details.

destroy

promiseDuplex = promiseDuplex.destroy()

This method calls destroy method on stream and cleans up all own handlers.

The method returns this object.

See also

PromiseReadable, PromiseWritable, PromiseSocket, PromisePiping.

License

Copyright (c) 2017-2024 Piotr Roszatycki piotr.roszatycki@gmail.com

MIT

Keywords

FAQs

Package last updated on 21 Jun 2024

Did you know?

Socket

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.

Install

Related posts

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