Skip to content

Repository files navigation

<datastream>

Commonly used stream patterns for Web Streams API and NodeJS Stream.

If you're iterating over an array more than once, it's time to use streams.


GitHub Actions unit test statusGitHub Actions dast test statusGitHub Actions perf test statusGitHub Actions SAST test statusGitHub Actions lint test status
npm versionnpm install sizenpm weekly downloadsnpm provenance
Open Source Security Foundation (OpenSSF) ScorecardSLSA 3Checked with BiomeConventional Commitscode coverage

  • @datastream/core
    • pipeline
    • pipejoin
    • result
    • streamToArray
    • streamToObject
    • streamToString
    • streamToBuffer
    • isReadable
    • isWritable
    • makeOptions
    • createReadableStream
    • createPassThroughStream
    • createTransformStream
    • createWritableStream
    • resolveLazy
    • shallowClone
    • deepClone
    • shallowEqual
    • deepEqual
    • timeout
    • createReadableStreamFromString (Node only)
    • createReadableStreamFromArrayBuffer (Node only)
    • backpressureGauge (Node only)

Streams

  • Readable: The start of a pipeline of streams that injects data into a stream.
  • PassThrough: Does not modify the data, but listens to the data and prepares a result that can be retrieved.
  • Transform: Modifies data as it passes through.
  • Writable: The end of a pipeline of streams that stores data from the stream.

Basics

  • @datastream/string
    • stringReadableStream [Readable]
    • stringLengthStream [PassThrough]
    • stringCountStream [PassThrough]
    • stringMinimumFirstChunkSize [Transform]
    • stringMinimumChunkSize [Transform]
    • stringSkipConsecutiveDuplicates [Transform]
    • stringReplaceStream [Transform]
    • stringSplitStream [Transform]
  • @datastream/object
    • objectReadableStream [Readable]
    • objectCountStream [PassThrough]
    • objectBatchStream [Transform]
    • objectPivotLongToWideStream [Transform]
    • objectPivotWideToLongStream [Transform]
    • objectKeyValueStream [Transform]
    • objectKeyValuesStream [Transform]
    • objectKeyJoinStream [Transform]
    • objectKeyMapStream [Transform]
    • objectValueMapStream [Transform]
    • objectPickStream [Transform]
    • objectOmitStream [Transform]
    • objectFromEntriesStream [Transform]
    • objectToEntriesStream [Transform]
    • objectSkipConsecutiveDuplicatesStream [Transform]

Common

Advanced

  • @datastream/csv[/{parse,format}]
    • csvParseStream [Transform]
    • csvFormatStream [Transform]
  • @datastream/json
    • jsonParseStream [Transform]
    • jsonFormatStream [Transform]
    • ndjsonParseStream [Transform]
    • ndjsonFormatStream [Transform]
  • @datastream/encrypt
    • encryptStream [Transform]
    • decryptStream [Transform]
    • generateEncryptionKey
  • @datastream/validate
    • validateStream [Transform]
  • @datastream/arrow
    • arrowDetectSchemaStream [PassThrough]
    • arrowBatchFromArrayStream [Transform]
    • arrowBatchFromObjectStream [Transform]
    • arrowToArrayStream [Transform]
    • arrowToObjectStream [Transform]
  • @datastream/duckdb
    • duckdbConnect (connection helper)
    • duckdbAppenderStream [Writable]
    • duckdbArrowInsertStream [Writable]
  • @datastream/indexeddb
    • indexedDBReadStream [Readable]
    • indexedDBWriteStream [Writable]
  • @datastream/ipfs
    • ipfsGetStream [Readable]
    • ipfsAddStream [Writable]
  • @datastream/protobuf
    • protobufEncodeStream [Transform]
    • protobufDecodeStream [Transform]
    • protobufLengthPrefixFrameStream [Transform]
    • protobufLengthPrefixUnframeStream [Transform]
  • @datastream/schema-registry
    • confluentFrameStream [Transform]
    • confluentUnframeStream [Transform]
    • glueFrameStream [Transform]
    • glueUnframeStream [Transform]
  • @datastream/kafka
    • kafkaConnect (producer/consumer connection helper)
    • kafkaConsumeStream [Readable]
    • kafkaProduceStream [Writable]
  • @datastream/aws/msk-iam
    • awsMskIamMechanism (kafkajs OAUTHBEARER SASL config)
  • @datastream/aws/glue-schema-registry
    • awsGlueSchemaRegistryResolver (cached GetSchemaVersion lookup)

Setup

npm install @datastream/core @datastream/{module}

Flows

stateDiagram-v2
[*] --> fileRead: path
[*] --> fetchResponse: URL
[*] --> sqlCopyTo*: SQL
[*] --> stringReadable: string
[*] --> stringReadable: string[]
[*] --> objectReadable: object[]
[*] --> createReadable: blob
readable --> charsetDetect: binary
charsetDetect --> [*]
readable --> decryption
decryption --> passThroughBuffer: buffer
readable --> decompression
decompression --> passThroughBuffer: buffer
passThroughBuffer --> charsetDecode: buffer
charsetDecode --> passThroughString: string
passThroughString --> parse: string
parse --> validate: object
validate --> passThroughObject: object
passThroughObject --> transform: object
transform --> format: object
format --> charsetEncode: string
charsetEncode --> compression: buffer
compression --> writable: buffer
charsetEncode --> encryption: buffer
encryption --> writable: buffer
state readable {
fileRead
fetchResponse
sqlCopyTo*
createReadable
stringReadable
objectReadable
awsS3Get
awsDynamoDBQuery
awsDynamoDBScan
awsDynamoDBGet
}
state decompression {
brotliDecompress
gzipDecompress
deflateDecompress
zstdDecompress
}
state decryption {
decrypt
}
state parse {
csvParse
jsonParse
xmlParse*
}
state passThroughBuffer {
digest
}
state passThroughString {
stringLength
stringCount
}
state passThroughObject {
objectCount
objectBatch
}
state transform {
objectBatch
objectPivotLongToWide
objectPivotWideToLong
objectKeyValue
objectKeyValue
}
state format {
csvFormat
jsonFormat
xmlFormat*
}
state compression {
brotliCompress
gzipCompress
deflateCompress
zstdCompress
}
state encryption {
encrypt
}
state writable {
fileWrite
fetchRequest*
sqlCopyFrom
awsS3Put
awsDynamoDBPut
awsDynamoDBDelete
}
writable --> [*]
Loading

* possible future package

Write your own

Readable

NodeJS Streams

Web Streams API

Transform

NodeJS Streams

Web Streams API

Writeable

NodeJS Streams

Web Streams API

End-to-End Examples

NodeJS: Import CSV into SQL database

Read a CSV file, validate the structure, pivot data, then save compressed.

  • fs.creatReadStream
  • gzip
  • cryptoDigest
  • charsetDecode
  • csvParse
  • countChunks
  • validate
  • changeCase (pascal to snake)
  • parquet?
  • csvFormat
  • postgesCopyFrom

WebWorker: Validate and collect metadata about file prior to upload

  • cryptoDigest
  • charsetDetect
  • jsonParse?
  • validate

WebWorker: Upload file compressed

Upload file with brotli compression?

WebWorker: Decode protobuf-encoded requests into JSON

Fetch a protobuf-encoded file, decode the protobuf framing, then parse JSON

streams

  • filter

  • file (docs only?)

examples

  • fetch
  • node:fs
  • input type=file
  • readable string/array/etc

License

Licensed under MIT License. Copyright (c) 2026 will Farrell and contributors.

About

Commonly used stream patterns for Web Streams API and NodeJS Streams

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

8 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages