aboutsummaryrefslogtreecommitdiff
path: root/docs/guides/streams
diff options
context:
space:
mode:
authorGravatar Colin McDonnell <colinmcd94@gmail.com> 2023-07-26 14:59:39 -0700
committerGravatar GitHub <noreply@github.com> 2023-07-26 14:59:39 -0700
commit4c89c60867591b50e0b31bf5009fd5ad6a3cebe1 (patch)
treefc1d2f47309c0345a850933496baa40d94bfdcbb /docs/guides/streams
parent6bfee02301a2e2a0b79339974af0445eb5a2688f (diff)
downloadbun-4c89c60867591b50e0b31bf5009fd5ad6a3cebe1.tar.gz
bun-4c89c60867591b50e0b31bf5009fd5ad6a3cebe1.tar.zst
bun-4c89c60867591b50e0b31bf5009fd5ad6a3cebe1.zip
Add files (#3826)
Diffstat (limited to 'docs/guides/streams')
-rw-r--r--docs/guides/streams/index.json4
-rw-r--r--docs/guides/streams/to-array.md14
-rw-r--r--docs/guides/streams/to-arraybuffer.md14
-rw-r--r--docs/guides/streams/to-blob.md14
-rw-r--r--docs/guides/streams/to-buffer.md15
-rw-r--r--docs/guides/streams/to-json.md14
-rw-r--r--docs/guides/streams/to-string.md14
-rw-r--r--docs/guides/streams/to-typedarray.md15
8 files changed, 104 insertions, 0 deletions
diff --git a/docs/guides/streams/index.json b/docs/guides/streams/index.json
new file mode 100644
index 000000000..da6ff2629
--- /dev/null
+++ b/docs/guides/streams/index.json
@@ -0,0 +1,4 @@
+{
+ "name": "Streams",
+ "description": "A collection of guides for manipulating streams with Bun"
+}
diff --git a/docs/guides/streams/to-array.md b/docs/guides/streams/to-array.md
new file mode 100644
index 000000000..bca40cf12
--- /dev/null
+++ b/docs/guides/streams/to-array.md
@@ -0,0 +1,14 @@
+---
+name: Convert a ReadableStream to an array of chunks
+---
+
+Bun provides a number of convenience functions for reading the contents of a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) into different formats. The `Bun.readableStreamToArray` function reads the contents of a `ReadableStream` to an array of chunks.
+
+```ts
+const stream = new ReadableStream();
+const str = await Bun.readableStreamToArray(stream);
+```
+
+---
+
+See [Docs > API > Utils](/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
diff --git a/docs/guides/streams/to-arraybuffer.md b/docs/guides/streams/to-arraybuffer.md
new file mode 100644
index 000000000..b20d96a04
--- /dev/null
+++ b/docs/guides/streams/to-arraybuffer.md
@@ -0,0 +1,14 @@
+---
+name: Convert a ReadableStream to an ArrayBuffer
+---
+
+Bun provides a number of convenience functions for reading the contents of a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) into different formats.
+
+```ts
+const stream = new ReadableStream();
+const buf = await Bun.readableStreamToArrayBuffer(stream);
+```
+
+---
+
+See [Docs > API > Utils](/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
diff --git a/docs/guides/streams/to-blob.md b/docs/guides/streams/to-blob.md
new file mode 100644
index 000000000..3380dca38
--- /dev/null
+++ b/docs/guides/streams/to-blob.md
@@ -0,0 +1,14 @@
+---
+name: Convert a ReadableStream to a Blob
+---
+
+Bun provides a number of convenience functions for reading the contents of a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) into different formats.
+
+```ts
+const stream = new ReadableStream();
+const blob = await Bun.readableStreamToBlob(stream);
+```
+
+---
+
+See [Docs > API > Utils](/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
diff --git a/docs/guides/streams/to-buffer.md b/docs/guides/streams/to-buffer.md
new file mode 100644
index 000000000..d6450d644
--- /dev/null
+++ b/docs/guides/streams/to-buffer.md
@@ -0,0 +1,15 @@
+---
+name: Convert a ReadableStream to a Buffer
+---
+
+Bun provides a number of convenience functions for reading the contents of a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) into different formats. This snippet reads the contents of a `ReadableStream` to an [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer), then creates a [`Buffer`](https://nodejs.org/api/buffer.html) that points to it.
+
+```ts
+const stream = new ReadableStream();
+const arrBuf = await Bun.readableStreamToArrayBuffer(stream);
+const nodeBuf = Buffer.from(arrBuf);
+```
+
+---
+
+See [Docs > API > Utils](/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
diff --git a/docs/guides/streams/to-json.md b/docs/guides/streams/to-json.md
new file mode 100644
index 000000000..cf9e7c71e
--- /dev/null
+++ b/docs/guides/streams/to-json.md
@@ -0,0 +1,14 @@
+---
+name: Convert a ReadableStream to a JSON
+---
+
+Bun provides a number of convenience functions for reading the contents of a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) into different formats.
+
+```ts
+const stream = new ReadableStream();
+const json = await Bun.readableStreamToJSON(stream);
+```
+
+---
+
+See [Docs > API > Utils](/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
diff --git a/docs/guides/streams/to-string.md b/docs/guides/streams/to-string.md
new file mode 100644
index 000000000..a5963ae14
--- /dev/null
+++ b/docs/guides/streams/to-string.md
@@ -0,0 +1,14 @@
+---
+name: Convert a ReadableStream to a string
+---
+
+Bun provides a number of convenience functions for reading the contents of a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) into different formats.
+
+```ts
+const stream = new ReadableStream();
+const str = await Bun.readableStreamToString(stream);
+```
+
+---
+
+See [Docs > API > Utils](/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
diff --git a/docs/guides/streams/to-typedarray.md b/docs/guides/streams/to-typedarray.md
new file mode 100644
index 000000000..faa18e4ad
--- /dev/null
+++ b/docs/guides/streams/to-typedarray.md
@@ -0,0 +1,15 @@
+---
+name: Convert a ReadableStream to a Uint8Array
+---
+
+Bun provides a number of convenience functions for reading the contents of a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) into different formats. This snippet reads the contents of a `ReadableStream` to an [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer), then creates a [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) that points to the buffer.
+
+```ts
+const stream = new ReadableStream();
+const buf = await Bun.readableStreamToArrayBuffer(stream);
+const uint8 = new Uint8Array(buf);
+```
+
+---
+
+See [Docs > API > Utils](/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.