Questions & Answers

Can I stream data?

Deepkit HTTP
50 up-votes
Warning: The answer is generated by an artificial intelligence. It might not be correct.
To adjust rating, open the thread in Discord and click on the up/down vote button.

You can stream data using the response.sendStream() method. This method allows you to send a readable stream as the response body. You can create a readable stream using Node.js' stream module or any other library that provides readable streams. Here's an example:

import { HttpRequest, HttpResponse } from '@deepkit/http';
import { createReadStream } from 'fs';

router.get('/image', (request: HttpRequest, response: HttpResponse) => {
    const stream = createReadStream('/path/to/image.jpg');
    response.sendStream(stream, 'image/jpeg');
});