import stream from 'node:stream'
import { promisify } from 'node:util'
import fs from 'node:fs'
import got from 'got'
const pipeline = promisify(stream.pipeline)
// Read
await pipeline(
fs.createReadStream('foo.txt'),
got.stream.post('<https://example.com>'),
)
// Write
await pipeline(
got.stream('<https://example.com>'),
fs.createWriteStream('foo.txt'),
)
import got from 'got'
got
.stream('<https://example.com>')
.on('response', response => {
// Modify response
})
.pipe(anotherResponse)
If the stream goes through multiple pipes, decompress needs to be false, or content-length header may be wrong (on Vercel it becomes 0):
import got from 'got'
import sharp from 'sharp'
got
.stream(url, {
decompress: false,
})
.pipe(sharp().avif())
.pipe(response)