text-stream-accumulator

Accumulates all values of a text stream into a string

Usage no npm install needed!

<script type="module">
  import textStreamAccumulator from 'https://cdn.skypack.dev/text-stream-accumulator';
</script>

README

Node.js Text Stream Accumulator

Circle CI Coverage Status Language grade: JavaScript

This micro-library (with zero dependencies) gathers all the text that flows through through a Node.JS readable stream.

const { TextStreamAccumulator } = require("text-stream-accumulator")
const acc = new Accumulator(myStream)
// wait for events from myStream
acc.toString() // prints accumulated content from myStream

As an example, When your myStream object emits data events containing "hello" and "world" (in the form of a Buffer or string), calling acc.toString() will return "helloworld".

TextStreamAccumulator keeps all captured content in an internal buffer. To reduce the size of this buffer, call one of these methods after you have found what you have been looking for:

  • acc.reset() removes all captured content
  • acc.truncate("foo") removes all earlier captured content until (and including) the word "foo", but keeps content captured later around

Feedback

All feedback, no matter how big or small, is welcome. Please submit bugs, ideas, or improvements via an issue or pull request.

Development

  • run all tests: make test
  • run all linters: make lint
  • run all formatters: make fix
  • see all available Make commands: make help
  • deploy a new version:
    • update the version in package.json and commit to master
    • run npm publish