I want to reduce the size of the response by compressing the chunks written to the API response.
However, I’m not used to working with Node.js, so I’m not sure of the solution or keywords that might be relevant to the solution.
I use Node.js to write chunks in the response, and use it as an arrayBuffer on the client side.
API
const path = req.body.path;
try {
for await (chunk of stream(path)) {
res.write(chunk);
};
res.status(200).end();
}
Client
const res = await fetch("/api/get-buffer", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ path }),
});
const arrayBuffer = await res.arrayBuffer();
Currently, the above code can be used to get an ArrayBuffer from the API.
However, we would like to reduce the size of the response if it is possible.