Skip to content

Commit

Permalink
docs: clarify handling of streams and buffers (#5166)
Browse files Browse the repository at this point in the history
* docs: clarify handling of streams and buffers

* docs: fix typo

Co-authored-by: Andrey Chalkin <L2jLiga@gmail.com>

---------

Co-authored-by: Andrey Chalkin <L2jLiga@gmail.com>
  • Loading branch information
brettwillis and L2jLiga committed Nov 23, 2023
1 parent 99a405a commit 6a337b0
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions docs/Reference/Reply.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,12 @@ fastify.get('/json', options, function (request, reply) {
#### Streams
<a id="send-streams"></a>

*send* can also handle streams by setting the `'Content-Type'` header to
`'application/octet-stream'`.
If you are sending a stream and you have not set a `'Content-Type'` header,
*send* will set it to `'application/octet-stream'`.

As noted above, streams are considered to be pre-serialized, so they will be
sent unmodified without response validation.

```js
fastify.get('/streams', function (request, reply) {
const fs = require('node:fs')
Expand All @@ -690,6 +694,10 @@ fastify.get('/streams', async function (request, reply) {

If you are sending a buffer and you have not set a `'Content-Type'` header,
*send* will set it to `'application/octet-stream'`.

As noted above, Buffers are considered to be pre-serialized, so they will be
sent unmodified without response validation.

```js
const fs = require('node:fs')
fastify.get('/streams', function (request, reply) {
Expand All @@ -713,8 +721,12 @@ fastify.get('/streams', async function (request, reply) {
#### TypedArrays
<a id="send-typedarrays"></a>

`send` manages TypedArray and sets the `'Content-Type'=application/octet-stream'`
header if not already set.
`send` manages TypedArray like a Buffer, and sets the `'Content-Type'`
header to `'application/octet-stream'` if not already set.

As noted above, TypedArray/Buffers are considered to be pre-serialized, so they
will be sent unmodified without response validation.

```js
const fs = require('node:fs')
fastify.get('/streams', function (request, reply) {
Expand Down

0 comments on commit 6a337b0

Please sign in to comment.