Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/myrotvorets/buffer-stream
Converts a Buffer into a Readable Stream
https://github.com/myrotvorets/buffer-stream
buffer-stream buffer-to-stream stream-buffer stream-to-buffer
Last synced: 23 days ago
JSON representation
Converts a Buffer into a Readable Stream
- Host: GitHub
- URL: https://github.com/myrotvorets/buffer-stream
- Owner: myrotvorets
- License: mit
- Created: 2020-08-05T20:42:15.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-12-16T04:11:17.000Z (26 days ago)
- Last Synced: 2024-12-16T20:36:04.868Z (26 days ago)
- Topics: buffer-stream, buffer-to-stream, stream-buffer, stream-to-buffer
- Language: TypeScript
- Homepage:
- Size: 2.62 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# buffer-stream
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=myrotvorets_buffer-stream&metric=alert_status)](https://sonarcloud.io/dashboard?id=myrotvorets_buffer-stream)
[![Build and Test](https://github.com/myrotvorets/buffer-stream/actions/workflows/build.yml/badge.svg)](https://github.com/myrotvorets/buffer-stream/actions/workflows/build.yml)Converts a Buffer into a Readable Stream.
Since version 1.1.0, it provides a helper to read the entire stream into a Buffer.
Since version 1.3.0, it provides a writable stream that stores the result in a buffer.
## Usage
```js
import { BufferStream, WritableBufferStream, streamToBuffer } from '@myrotvorets/buffer-stream';// BufferStream
const buf = Buffer.from('123');
const stream = new BufferStream(buf);// streamToBuffer
streamToBuffer(stream).then((buffer) => { /* ... */ })// WritableBufferStream
const stream = new WritableBufferStream();
stream.write('something', (err) => {
if (!err) {
console.log(stream.toString());stream.clear(); // Clear the internal buffer
}
});await stream.writeP('something else');
```See the [`test`](test) directory for usage examples.