3.4.75 • Published 4 months ago

@hishprorg/id-modi v3.4.75

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

@hishprorg/id-modi

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 @hishprorg/id-modi

build status

Usage

Use @hishprorg/id-modi(writable, readable, streamOptions) (or @hishprorg/id-modi.obj(writable, readable) to create an object stream)

var @hishprorg/id-modi = require('@hishprorg/id-modi')

// turn writableStream and readableStream into a single duplex stream
var dup = @hishprorg/id-modi(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 = @hishprorg/id-modi()

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 @hishprorg/id-modi = require('@hishprorg/id-modi')
var http = require('http')

var request = function(opts) {
  var req = http.request(opts)
  var dup = @hishprorg/id-modi(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

@hishprorg/id-modi is part of the mississippi stream utility collection which includes more useful stream modules similar to this one.

front-endkoreantacitignorepredictableES5Object.keyscall-bindelectronUnderscorehardlinksfindLastStyleSheetownrobustxtermreal-timeES2019banneroffsetsetterproxyString.prototype.matchAllFloat64Arraytypesafeglobreact-hook-forms3globalclassnamesinternalwhichFunction.prototype.nameless.jsstyleguidemergejQueryauthslotInt16ArraynumberebsObject.definePropertyObjectroute53ES2015typeshashesdotenvcolumnmockmonorepofunctionalglobalslibphonenumberglobal objectloghigher-orderArray.prototype.findLastIndexsortedflattenArray.prototype.filterreact-hooksparsebddbinaryqscircularquerytddES2022sameValueZerogetOwnPropertyDescriptordataviewJSONartECMAScript 2022react poseunicodedataViewinvariantargumentcodescloudsearchHyBiexecemrrequireimportexporteast-asian-widthmockinggroupByeventEmitterregexclistylesheetl10nsnstypedarraysES2016tostringtagjson-schemaec2es2016styled-componentscheckeffect-tsdiffbuffersframerespreemetadatafsinferencewhatwgwafvestcss-in-jscolorsprunedescriptionlocationstablefull-widthreadablestreamsigintexecfilenativeerror-handlingglobalThiseventsscheme-validationObservablechaidefinesqscryptmacosworkspace:*@@toStringTagtoobjectspinnerttycompile lesstslibtrimStartreadableforkaccessibilityapollologgingPromisecallbackisConcatSpreadableflagcertificateskinesismkdirnpmignorespinnersremovesymbolstatuspackagesmobilesuperstructUint16ArrayvalidatorstoragegatewayshellinrequestbinariesfindLastIndexencryptionArray.prototype.flattenfetchiterationjson-schema-validatorendpointcss variable3denumerablecloudtrailinputregexpenvironmentspureletMicrosoftpyyamldeep-clonejsonschemaconstfigletawesomesaucemodulepromisemodulesequalityjsxECMAScript 2021columnsES2018specgitignorepathless compilergetPrototypeOfeslint-plugin0PushfnmatchselfexecutecloudformationtoSortedECMAScript 6__proto__deletetransportYAMLisdirrulesSystem.globalprettyexit-codedeep-copyredactes2018timequotepostcssinternal slotObject.entriesjsECMAScript 2020shimes2017ES2020estreesetImmediateCSSStyleDeclarationfullschemapatchnameieiamMapoptimizerObject.ises2015RegExp.prototype.flagsArray.prototype.findLastsymbolsfunction.lengthprocessURLSearchParamsfastcloneTypedArraywalklinkconfigurableinstallerpicomatchecmascriptuser-streamsansioptimistjavascriptslicedeepclonees-abstractobjectzerowriteprotocol-buffersformatsequencebyteLengthminimalopensslspringstylingi18nlazyfromes8telephonecoerciblegraphqlECMAScript 2015core-js6to5oncefastcopypoint-freeexitpersistentexpressionchromiumless cssrecursivesigtermes-shimsemitUint8ClampedArrayobjpluginhttpcollectionES7Streamseslintpluginvariablesdependency managermake diroptioncolourprivate dataObject.fromEntriessignedruntimebrowserindicatorloggermaplastpackage.jsoncall-boundcontainsstringES2021consoleauthenticationIteratorURLsharedarraybufferInt8ArrayeslintconfigelbramdaECMAScript 7reduceReflect.getPrototypeOfnodejsless mixinsawsassertsflagstypedcallbindsuperagentroutehas-ownstatequeuemakestreamsArray.prototype.flatMapexpresscompilerfilewindowa11ytextlintquerystringshebangastarraysjwtjapanesechildlockfilesetPrototypeOfconsumees5gestureshandlersetcensormatchessharedfast-copyES2017ArrayBuffer.prototype.slicesafeasciiarray.envtrimRightutilitycommanderprop.gitignorecolorbrowserlistdropprotoregular expressionthreetestingfunctionspinojson-schema-validationiteratorapiwgethandlersfast-cloneserializationlanguageassertperformantflatmanagerlistenersharmonyidentifiersfunctionflatMapvaluesjsdiffhotvpc_.extendlocalFloat32ArrayboundRxJSjestbeanstalkagentcommandincludescharacterUint8ArrayhasOwnPropertyArrayBufferSymbol.toStringTagweakmapstringifierfilterperformancevarescapeString.prototype.trimshamrapidredirectgetterES3dependenciestypanionloadbalancingformsairbnbeventDispatchernested csskeysRegExp#flagssortkeyArray.prototype.includesvalidationStreamlivestructuredClonegetintrinsictyped arrayglobal this valueuploadfast-deep-copyfpvisualasyncomitsomehttpsclassnameenvconfigpackage managerECMAScript 2017bcryptES8createstyleslengthformfullwidthtc39bootstrap lessprefixbyteOffsetdataimportArray.prototype.containsInt32Arrayreact animationintrinsicpositivetrimEndObservablesdirectoryWeakSettypedarrayform-validationsubprocessmapreducedeterministiccomparecallSymbolautoprefixerReactiveXnamesservicereduxlesstoArrayserializegdprtsuninstallcss lessfast-deep-cloneRFC-6455assignschemezxTypeScriptstreamentriesWebSocketbinaccessorhelperjshintglacieridlebundlermatchAll256termmixinsanimationECMAScript 3arraybuffercollection.es6prototypecachefindAsyncIteratorvalidatewaitfantasy-landgetassertionimmutableWeakMapajvloadingdragbyteeslintroutingcurlJSON-SchemayupArrayhastrimLeftmulti-packageformattingpropertyECMAScript 2023typeoffastifyzodparserredux-toolkitfluxequalutil.inspectpasswordnpmreplayfile systemmkdirperrorjsdomio-tswindowsECMAScriptmkdirsreactsymlinksyntaxbabeltoStringTagutilitiesresolvefastnegativeviewmovelesscsshelpersswfelmspeednopeargstypescriptargvcorevarspropertiessidesettingspipeserializerprotobufreducerwarningObject.getPrototypeOfyamlsesback-endcallboundextendconcatMapclassesoutputclass-validator
3.4.75

4 months ago

3.4.74

4 months ago

3.4.73

4 months ago

3.4.72

4 months ago

3.4.71

4 months ago

3.4.70

4 months ago

3.4.69

4 months ago

3.4.68

4 months ago

3.4.67

4 months ago

3.4.66

4 months ago

3.4.65

4 months ago

3.4.64

4 months ago

3.3.64

4 months ago

3.3.63

4 months ago

3.3.62

4 months ago

3.3.61

4 months ago

3.3.60

4 months ago

3.3.59

4 months ago

3.3.58

4 months ago

3.3.57

5 months ago

3.3.56

5 months ago

3.3.55

5 months ago

3.3.54

5 months ago

3.3.53

5 months ago

3.3.52

5 months ago

3.3.51

5 months ago

3.3.50

5 months ago

3.3.49

5 months ago

3.3.48

5 months ago

3.3.47

5 months ago

3.3.46

5 months ago

3.3.45

5 months ago

3.3.44

5 months ago

3.3.43

5 months ago

3.3.42

5 months ago

3.3.41

5 months ago

3.3.40

5 months ago

3.3.39

5 months ago

3.3.38

5 months ago

3.3.37

5 months ago

3.3.36

5 months ago

3.3.35

5 months ago

3.3.34

5 months ago

3.3.33

5 months ago

3.3.32

5 months ago

3.3.31

5 months ago

3.3.30

5 months ago

3.3.29

5 months ago

3.3.28

5 months ago

3.3.27

6 months ago

3.3.26

6 months ago

3.3.25

6 months ago

3.3.24

6 months ago

3.3.23

6 months ago

3.3.22

6 months ago

3.3.21

6 months ago

3.3.20

6 months ago

3.3.19

6 months ago

2.3.19

6 months ago

2.3.18

6 months ago

2.3.17

6 months ago

2.3.16

6 months ago

2.3.15

6 months ago

2.3.14

6 months ago

2.3.13

6 months ago

2.3.12

6 months ago

2.2.12

6 months ago

2.2.11

6 months ago

2.2.10

6 months ago

2.2.9

6 months ago

2.2.8

6 months ago

2.2.7

6 months ago

2.1.7

6 months ago

1.1.7

6 months ago

1.1.6

6 months ago

1.1.5

6 months ago

1.1.4

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago