Skip to main content
100%

custom-writable-stream.js

✓ Published0🌍 Public
Aalessioalex
Last edited Nov 22, 2014
Created on Nov 22, 2014

This example demonstrates a custom Writable stream in Node.js that stores incoming data in an in-memory object. It shows how to extend the `stream.Writable` class, using `util.inherits` to create the `WMStrm` constructor, which initializes a `Buffer` for a given key. The overridden `_write` method concatenates each chunk, whether already a `Buffer` or converted from a string, to the stored buffer. The code then writes two strings to the stream, triggers the `finish` event, and logs the accumulated result from the `memStore` object.

AI-generated description

Similar vizzes