How does Nextjs handle compressing a response in a server action. Will the browser automatically know the returned repsonse is compressed and automatically decompress it on the client side? Here's my code compressing the response. I read that I need to set the header content-encoding to gzip in order for the browser to know to decompress it
export async function transformData(arrayBuffer: string) {
console.log("In server action");
const buffer = Buffer.from(arrayBuffer);
const data = buffer.toString('utf-8');
// console.log(data);
const result = Papa.parse(data, {
header: true,
}) as {data: Advertising[]};
const jsonData = result.data;
const modifiedData = await modifyData(jsonData) as Advertising[];
getPayloadSize(modifiedData, "Modified JSON");
const compressedData = await compressData(modifiedData);
return compressedData
}
async function compressData(data: Advertising[]) {
return new Promise((resolve, reject) => {
const jsonData = JSON.stringify(data);
gzip(new TextEncoder().encode(jsonData), (err, compressed) => {
if (err) {
reject(err);
} else {
resolve(compressed);
}
});
});
}