I want to use gzip and used 4 methods, only the first one convert to base64 works. But I want to use functions 2.0
- base64
import { gzipSync } from 'zlib'
export const handler = async () => {
return {
statusCode: 200,
headers: { 'Content-Encoding': 'gzip' },
body: gzipSync('Hello World').toString('base64'),
isBase64Encoded: true,
}
}
Content-Encoding: gzip
...
Hello World
- stream
import { stream } from "@netlify/functions"
import { gzipSync } from 'zlib'
export const handler = stream(async () => {
return {
statusCode: 200,
headers: { 'Content-Encoding': 'gzip' },
body: new ReadableStream({
start(controller) {
controller.enqueue(gzipSync('Hello World'))
controller.close()
}
}),
}
})
Content-Encoding: none
...
‹������óHÍÉÉWÏ/ÊI�V±J���
- functions 2.0
import { gzipSync } from 'zlib'
export default async () => {
return new Response(gzipSync('Hello World'), {
headers: { 'Content-Encoding': 'gzip' },
})
}
Content-Encoding: none
...
‹������óHÍÉÉWÏ/ÊI�V±J���
- functions 2.0 stream
import { gzipSync } from 'zlib'
export default async () => {
return new Response(new ReadableStream({
start(controller) {
controller.enqueue(gzipSync('Hello World'))
controller.close()
}
}), {
headers: { 'Content-Encoding': 'gzip' },
})
}
Content-Encoding: none
...
‹������óHÍÉÉWÏ/ÊI�V±J���