Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bergos/stream-chunks
Get all chunks of a stream
https://github.com/bergos/stream-chunks
Last synced: about 2 months ago
JSON representation
Get all chunks of a stream
- Host: GitHub
- URL: https://github.com/bergos/stream-chunks
- Owner: bergos
- Created: 2022-10-02T14:44:26.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-10-02T14:47:53.000Z (over 2 years ago)
- Last Synced: 2024-11-29T12:53:55.545Z (about 2 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# stream-chunks
[![build status](https://img.shields.io/github/workflow/status/bergos/stream-chunks/Test)](https://github.com/bergos/stream-chunks/actions/workflows/test.yaml)
[![npm version](https://img.shields.io/npm/v/stream-chunks.svg)](https://www.npmjs.com/package/stream-chunks)Get all chunks of a stream.
## Install
`npm install stream-chunks --save`
## Usage
There are multiple functions for collecting the chunks of a stream.
All of them are async functions, and expect the stream as the first argument.### Raw as array
The `chunks` function collects all chunks and puts them in order in an array.
```javascript
import chunks from 'stream-chunks/chunks.js'const array = await chunks(stream)
```### Combined into an Uint8Array
The `concat` function collects all chunks and combines them into a single Uint8Array object.
```javascript
import concat from 'stream-chunks/concat.js'const all = await concat(stream)
```### Combined into a string
The `decode` function collects all chunks, decodes them based on the given encoding, and combines them into a string.
```javascript
import decode from 'stream-chunks/decode.js'const str = await decode(stream, 'utf8')
```