const file = bucket.file(`${folderName}/${fileName}`) const passThroughStream = new stream.PassThrough() passThroughStream.write(fileTitle) passThroughStream.write(fileHeader) passThroughStream.write(convertArrayToCSV(accounts.map(mapRecords))) passThroughStream.end() passThroughStream .pipe(file.createWriteStream()) .on('error', (err) => { console.error(makeLogEntry(err)) }) .on('finish', () => { console.log('writed') })