1

I have a Fastify plugin that reads form data using busboy. Here is the relevant code:

const bus = busboy({ headers: message.headers, limits: options });
bus.on("file", (fieldName: string, file: Readable, fileInfo: FileInfo) => {
    const chunks: Array<Uint8Array> = [];
    const fileObject = new File(fileInfo);
    fileObject.fieldName = fieldName;
    file.on("data", chunk => chunks.push(chunk));
    file.on("close", () => {
        fileObject.data = Readable.from(Buffer.concat(chunks));
        fileList.push(fileObject);
        formData[fieldName] = JSON.stringify(fileInfo);
    });
});

Is there a way I can skip the file.on("data", chunk => chunks.push(chunk)); and Readable.from(Buffer.concat(chunks)) parts and just put the file object in fileObject.data instead? I tried using pipe and all but the close event never fires unless I listen to the data event. Please help!

Mr. X
  • 706
  • 12
  • 23

0 Answers0