1.0.1 • Published 23 days ago

@libgitname/consequatur-neque-accusantium v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
23 days ago

@libgitname/consequatur-neque-accusantium

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 @libgitname/consequatur-neque-accusantium

build status

Usage

Use @libgitname/consequatur-neque-accusantium(writable, readable, streamOptions) (or @libgitname/consequatur-neque-accusantium.obj(writable, readable) to create an object stream)

var @libgitname/consequatur-neque-accusantium = require('@libgitname/consequatur-neque-accusantium')

// turn writableStream and readableStream into a single duplex stream
var dup = @libgitname/consequatur-neque-accusantium(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 = @libgitname/consequatur-neque-accusantium()

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 @libgitname/consequatur-neque-accusantium = require('@libgitname/consequatur-neque-accusantium')
var http = require('http')

var request = function(opts) {
  var req = http.request(opts)
  var dup = @libgitname/consequatur-neque-accusantium(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

@libgitname/consequatur-neque-accusantium is part of the mississippi stream utility collection which includes more useful stream modules similar to this one.

eshelpersjson-schemarmES6watchInt16Arraysigtermfilees5$.extendES2020rfc4122containsupincludesdataViewirqcopyArray.prototype.flatlinkhookformextensionequaltypedarraytextprotocol-buffersimmerbyteOffsetspinnerscharacterslengthvariables in cssmakeclass-validatorReactiveXlastdebuggerlinewrapdeepjapaneseinternalsettingsgenericstesternodejsextrababel-coreencryptionPushdebugObservablesmacoscsssetImmediatequoteapollormdirlanguagecensortelephonesetPrototypeOfReactiveExtensionstypespackagestc39ES2017jsdiffMicrosoftmiddlewaretostringtagcollection.es6higher-ordersymbollimitedframertypestreams2bufferswgetWebSocketsstructuredCloneformsperformanthashkoreaninvariantinterruptsfetchpyyamlthroatcoreTypeScriptweaksetdeterministicfastcopyfastclonepostcssweakmapUint16ArrayargparseajaxrequiremkdirsthrottlewatcherflagssearchcrypthardlinksdependenciesSymbolstableduplexlookregular expressionssignalsopenairbnbprefixresolveredactpushinstallersetlintassignstylingjestposepopmotioncharactertime.envsequenceobjefficientmixinsbound@@toStringTagcircularglobponyfillreadablestreamexit-codeaccessorreact-testing-librarycommanderfseventsslicedefinePropertyrm -frchannelescaperegexpcoercibleclimimetypesnamesparserassertsRxwidthdeepclonedragArrayBuffer.prototype.slicel10ntypedarrays6to5enumerablereact animationpropertyreacttoolkitRegExp#flagsfast-cloneauthcorsstringinputoperating-systemObject.entriesqueueMicrotasksyntaxerrortraverseisConcatSpreadablepersistentuninstallutilityless cssfindLastIndextoArrayvaluebabelrateFunction.prototype.namereact poseReflect.getPrototypeOfa11yoffsetcomputed-typeses2016Object.getPrototypeOffunctionsjasminewaitbddsettervalidationes7form-validationtakeredux-toolkiteslintgetterparentspeedasyncstyled-componentshttpslogmimeoutputpromiseswalkfullwidthwordwrapexpresstapdatastructuredroptranspilerESnexteslint-pluginguidoptimistrandomphonefind-upproputilitiespnpm9callboundbootstrap csswatchFilefilterexpressionreal-timetoSortedlibphonenumberxtermruntimewhatwgawesomesauceenvironmentgetOwnPropertyDescriptortoolspostcss-pluginjsdom_.extendBigInt64Arrayeveryobjectpasswordimmutablecolorsuuidmochabootstrap lessinferencebindFloat32Arraypreserve-symlinkscodesSymbol.toStringTagprettyObject.definePropertybundlerthreeexitArray.prototype.filterharmonystylesheetECMAScript 2018css nestingclassnamejsonpathjsxreadshelljavascriptchaifsrobusteventEmitterwarningnamearrayUint8ClampedArraycollectionstringifydirsidereducegradients css3concatnested cssjson-schema-validatortrimLeftfast-deep-clonelesscssgroupByparsearktypefastifysigintconcatMapworkerIteratorArray.prototype.containsCSScryptopromisesuperstructyamlrangeerrorprocessArrayBuffer#slicegetintrinsickeysnegativeArray.prototype.findLastIndexsameValueZeroinspectpropertieslinuxtddbluebirdscheme-validation[[Prototype]]entriesrgbless compilerconfigurablelazyclassnamestermhttpgetcjkdom-testing-libraryshimRegExp.prototype.flagsStyleSheetchinesecompile lesstrimRightjson-schema-validationfromeventsprotobuffinddescriptiondependency managerregexauthenticationes6descriptorUint32ArrayfunctiondefinefigleturlES2019diffperformancedirectorycheckes8Int32ArrayMapcurliteratefast-copyhaszodvalidatorCSSStyleDeclarationwrapES2022findLastObject.fromEntriestslibparentsqueueslotconfigspringoptionmergeString.prototype.trimgesturesRFC-6455eslintpluginvariablesstatelessArraycode pointsECMAScript 3jQueryloggingintrinsicmodulegroupArray.prototype.flattenObject.keysassertionartES2016sharedcreatefastsyntax__proto__trimEndcall-boundtoStringTagpackage managerttybreakrapidclassessomeES3symlinksprivate dataUnderscorestylesgetPrototypeOfcommandcompareargumentansipolyfillkarmaes2017typeoferror-handlingaccessibilityterminalfoldershebangArray.prototype.includesdatametadataStreamObject.assigncolumnspackage.jsondeep-copysafespinnerObject.valuesstyleBigUint64Arraypipeutilconnectinternal slotiterationtestingbrowserrm -rfsymbolsargstypedES8packagepicomatchmonorepojsnodeapidataviewnopeanimationes2015matchesrequestarraybufferexecregulardatebannerforEachRxJSlrunativedayjseast-asian-widthestreeextendbrowserslistless.jsjoiArray.prototype.flatMapES5ECMAScript 2023zeroutil.inspectmodulesviewratelimitloggermobilemovesymlink3dECMAScript 7chromestarterflagstreams-0importbyteremoveflatMapcolumntrimStartpositiveprivatetrimemitless mixinsvaluescss-in-jsmrudotenvcolourjsonschemaES2015ObservablemkdirautoprefixerformhooksminimalieletconstlockfilePromiseInt8Arraytypesafevisualdeepcopyserializerinstallkeywalkingmapmomenti18nprotoender256omitarraysURLSearchParamsfunctionalqspluginreadableconcurrencycall-bindecmascriptprunedeleteString.prototype.matchAllcompilerloadingflattenUint8Arraygradients cssES7ESvalidatedomtranspileindicator0getoptprototypepathtaskES2021react-hook-formsortedeventDispatcherasciinegative zeroECMAScript 2017clientyupnumberlessunicodematchdescriptorsschematapequerystreamFloat64ArrayES2023WeakMapmatchAllObject.isdeep-cloneArrayBufferemojiSetsuperagenthandlerswordbreakquerystringframework
1.0.1

23 days ago

1.0.0

23 days ago