Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions docs/modules/concat-stream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
description: Modern alternatives to the concat-stream package
---

# Replacements for `concat-stream`

## Utility Consumers (native, since Node.js 16.7.0)

### Consuming as a string

<!-- prettier-ignore -->
```js
import concat from 'concat-stream' // [!code --]
import { text } from 'node:stream/consumers' // [!code ++]

readable.pipe(concat((data) => { // [!code --]
const str = data.toString('utf-8') // [!code --]
console.log(str) // [!code --]
})) // [!code --]

const str = await text(readable) // [!code ++]
console.log(str) // [!code ++]
```

### Consuming as Buffer

<!-- prettier-ignore -->
```js
import concat from 'concat-stream' // [!code --]
import { buffer } from 'node:stream/consumers' // [!code ++]

readable.pipe(concat((data) => { // [!code --]
console.log(data.length) // [!code --]
})) // [!code --]

const data = await buffer(readable) // [!code ++]
console.log(data.length) // [!code ++]
```

### Consuming as an Array

<!-- prettier-ignore -->
```js
import concat from 'concat-stream' // [!code --]
import { toArray } from 'node:stream/consumers' // [!code ++]

readable.pipe(concat({ encoding: 'object' }, (items) => { // [!code --]
console.log(items) // [!code --]
})) // [!code --]

const items = await toArray(readable) // [!code ++]
console.log(items) // [!code ++]
```

Alternatively, using an async iterable loop:

```js
for await (const chunk of readable) {
// ...
}
```
6 changes: 6 additions & 0 deletions manifests/preferred.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@
"replacements": ["util.styleText", "picocolors", "ansis"],
"url": {"type": "e18e", "id": "chalk"}
},
"concat-stream": {
"type": "module",
"moduleName": "concat-stream",
"replacements": ["node:stream"],
"url": {"type": "e18e", "id": "concat-stream"}
},
"copy-text-to-clipboard": {
"type": "module",
"moduleName": "copy-text-to-clipboard",
Expand Down