4.11.84 • Published 11 months ago

@diotoborg/dolorum-unde v4.11.84

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

@diotoborg/dolorum-unde

Turn a writeable and readable stream into a single streams2 duplex stream.

Similar to duplexer2 except it supports both streams2 and streams1 as input and it allows you to set the readable and writable part asynchronously using setReadable(stream) and setWritable(stream)

npm install @diotoborg/dolorum-unde

build status

Usage

Use @diotoborg/dolorum-unde(writable, readable, streamOptions) (or @diotoborg/dolorum-unde.obj(writable, readable) to create an object stream)

var @diotoborg/dolorum-unde = require('@diotoborg/dolorum-unde')

// turn writableStream and readableStream into a single duplex stream
var dup = @diotoborg/dolorum-unde(writableStream, readableStream)

dup.write('hello world') // will write to writableStream
dup.on('data', function(data) {
  // will read from readableStream
})

You can also set the readable and writable parts asynchronously

var dup = @diotoborg/dolorum-unde()

dup.write('hello world') // write will buffer until the writable
                         // part has been set

// wait a bit ...
dup.setReadable(readableStream)

// maybe wait some more?
dup.setWritable(writableStream)

If you call setReadable or setWritable multiple times it will unregister the previous readable/writable stream. To disable the readable or writable part call setReadable or setWritable with null.

If the readable or writable streams emits an error or close it will destroy both streams and bubble up the event. You can also explicitly destroy the streams by calling dup.destroy(). The destroy method optionally takes an error object as argument, in which case the error is emitted as part of the error event.

dup.on('error', function(err) {
  console.log('readable or writable emitted an error - close will follow')
})

dup.on('close', function() {
  console.log('the duplex stream is destroyed')
})

dup.destroy() // calls destroy on the readable and writable part (if present)

HTTP request example

Turn a node core http request into a duplex stream is as easy as

var @diotoborg/dolorum-unde = require('@diotoborg/dolorum-unde')
var http = require('http')

var request = function(opts) {
  var req = http.request(opts)
  var dup = @diotoborg/dolorum-unde(req)
  req.on('response', function(res) {
    dup.setReadable(res)
  })
  return dup
}

var req = request({
  method: 'GET',
  host: 'www.google.com',
  port: 80
})

req.end()
req.pipe(process.stdout)

License

MIT

Related

@diotoborg/dolorum-unde is part of the mississippi stream utility collection which includes more useful stream modules similar to this one.

deep-clonergbstableArray.prototype.containselasticachewgetrandombinaryTypeBoxl10nclienttypedObject.valuesprotoignoresimpledbweakmapcacheStyleSheetdotenvproxypushaccessibilityspecfantasy-landIteratorparserttybundlingpromiseESsafeobjfunctionomiteffect-tssetPrototypeOfObject.definePropertymovetsArray.prototype.flatMapclassesInt32Arrayvalidatemulti-packageECMAScript 3workflowECMAScript 2015chaigdprdescriptorfast-copyrmindicatormomentbrowserslistreduxaccessortransportwaapihttpsbrowserlistfsschemetestingconcatMapprivateconcatserializationpackage managerutilcodespackagejestfigletconsumesettingses2017uninstalllogtranspilelinkcallboundfull-widthquotesnsvpcreworkexeceslintconfiglockfileReflect.getPrototypeOfreactWebSocketsefficientArrayBuffer.prototype.slicecommanderdeepcopyhelperjsdomwritedependenciesshimnpmignorerecursivetslibjsSymbol.toStringTaglocalinspectcall-boundhasOwnquerywebInt8Arraypositiveprototypeprunematcheses-abstractSetrangeerrorgenericsnopeObject.getPrototypeOftouchavanegative zeroRxECMAScript 2023setspinnersdommodulesenvironments[[Prototype]]kinesisslicechannelpreprocessorenvironmentvarsinternalreadablestreamchromepropertynameES2021lastreact posetransformtoReversedbyteOffsetmkdirsbuffersuperstructrmdirUint8ArraycallbindboundES2019mapreduceurlformrfc4122executesetImmediatecoveragefpsArray.prototype.findLastimmerpipefnmatchio-tsUint16Arraystyleguidecolourtypeoftypedarraysymbolsnativefile systemenderArrayBuffer#slicecomputed-typesrequireequalregular-expressionAsyncIteratorweaksetclonehasOwnPropertyArray.prototype.includesJSON-SchemaES2015ponyfillqueueURLemrPushremoveebsreact-testing-librarydeepclonefindLastIndexspeedcall0directoryawesomesauceassertinserializerinvariantcurloncearrayelectronsharedMaparraysjson-schemaArrayharmonyoffsetgetterregexpjshintansishelltc39findmkdirwaitrequesttimeworkerjoidragpackage.jsontelephonecloudsearchchinesevaluesgroupBytrimStarttddObservablepathtrimRighttoolsflagsreadableredirectcallbacklistenersfixed-widtherrorpostcssfromregular expressionscoercibleflagslotatomidlestyleESnextfunction.lengthdirtoobjectjsonObject.issymlinksstyleshashstringifierawskeysfullwidthes-shim APIxtermcolumnses2015reducebundlerdefineES3comparejQueryStreambinariesrdsparentshookformupglobal this valuecss-in-jsUint8ClampedArrayrapidinputconfigurabledayjslanguageviewspinnerschemaCSSStyleDeclarationuser-streamsfullStreamscolorarraybufferframeworkfetchfunctionstoSortedstringroutingargumentcontainssubprocesspluginpopmotionajaxcensorArray.prototype.findLastIndextoolkitsidejson-schema-validatorobjectieclass-validatorglobal objectdebugfilepyyamldateES2022es-shimsObject.assignhasstringifyprocessstreamsquerystringreact animationi18nfind-upgroupsqsprefixcommandnumberlookECMAScript 2017typescripteslintES6queueMicrotask6to5pureWeakMapkeyhardlinksES5URLSearchParamsdefinePropertyworkspace:*swfposeconsolemoduleES2016real-timecorecheckmatchoptimizera11yES2018walkingfindupelbECMAScript 2019prettyincludesautoprefixerescapegetyupsameValueZeroidfast-clonecollectionmochaString.prototype.trimasciieventsisConcatSpreadable@@toStringTag.envcircularRegExp.prototype.flagsrestfulglobalThistypanionroutesyntaxcommand-lineoutputjsonschematrimistanbulramdawalkfast-deep-cloneECMAScript 7fastcopyes2016artpatchutilsvariablesestreecore-jstapfastshamECMAScript 2022Int16ArraybindjsxspringES8someairbnbparseeveryxhrselfeast-asian-widthpropertiesreducerTypeScriptsortedcode pointsargvECMAScript 2021assertsfastifyglobgraphqlclibincloudformationprogresssource mapflatArrayBufferTypedArrayrulesreact-hook-formstarteranimationJSONtypeWeakSetroute53trimLeftmake dirtypedarraysintrinsicfpresolvetesterjson-schema-validationpinoprotocol-buffersObject.keysownredacthtmldynamodbbrowserjapanesecall-bindrobustterminaljavascriptapolloflatMap
4.11.84

11 months ago

4.11.83

11 months ago

4.10.83

11 months ago

4.10.82

11 months ago

4.10.81

11 months ago

4.10.80

11 months ago

4.10.79

11 months ago

4.10.78

11 months ago

4.9.78

11 months ago

4.9.77

11 months ago

4.9.76

11 months ago

4.9.75

11 months ago

4.9.74

11 months ago

4.9.73

11 months ago

4.9.72

11 months ago

4.9.71

11 months ago

4.9.70

11 months ago

4.9.69

11 months ago

4.9.68

11 months ago

4.9.67

11 months ago

4.9.66

11 months ago

4.9.65

11 months ago

4.9.64

11 months ago

4.9.63

11 months ago

4.9.62

11 months ago

4.8.62

11 months ago

4.7.62

11 months ago

4.7.61

12 months ago

4.7.60

12 months ago

4.7.59

12 months ago

3.7.59

12 months ago

3.7.58

12 months ago

3.6.58

12 months ago

3.6.57

12 months ago

3.6.56

12 months ago

3.6.55

12 months ago

3.6.54

12 months ago

3.6.53

12 months ago

3.5.53

12 months ago

3.5.52

12 months ago

3.5.51

12 months ago

3.5.50

12 months ago

3.5.49

12 months ago

3.5.48

12 months ago

3.5.47

12 months ago

3.5.46

12 months ago

3.5.45

12 months ago

3.5.44

1 year ago

3.5.43

1 year ago

3.5.42

1 year ago

3.5.41

1 year ago

3.5.40

1 year ago

3.5.39

1 year ago

3.5.38

1 year ago

3.5.37

1 year ago

2.5.37

1 year ago

2.5.36

1 year ago

2.5.35

1 year ago

2.5.34

1 year ago

2.5.33

1 year ago

2.5.32

1 year ago

2.5.31

1 year ago

2.4.31

1 year ago

2.4.30

1 year ago

2.4.29

1 year ago

2.4.28

1 year ago

2.4.27

1 year ago

2.4.26

1 year ago

2.4.25

1 year ago

2.3.25

1 year ago

2.3.24

1 year ago

2.3.23

1 year ago

2.3.22

1 year ago

2.3.21

1 year ago

2.3.20

1 year ago

2.2.20

1 year ago

2.2.19

1 year ago

2.2.18

1 year ago

2.1.18

1 year ago

2.1.17

1 year ago

2.1.16

1 year ago

2.1.15

1 year ago

2.1.14

1 year ago

2.1.13

1 year ago

2.1.12

1 year ago

2.1.11

1 year ago

2.1.10

1 year ago

2.1.9

1 year ago

2.1.8

1 year ago

2.1.7

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago