ARTICLE AD BOX
I'm pulling multiple CSV files from S3. Each CSV contains several rows in this format:
45,ABC,800046,HJN,9000
The first column is the employee ID.
I want to loop through all the files, parse each CSV, and filter rows where the employee ID matches a given list (e.g., [118, 675]).
However, when I log the parsed rows, they are still coming through as a Buffer instead of arrays of CSV fields. Here is the relevant part of my code:
function filterCsvRows(allCsvBuffers, employeeIds) { let resultRows = []; for (const { key, buffer } of allCsvBuffers) { const csvText = buffer.toString("utf8"); const rows = parse(csvText, { columns: false, skip_empty_lines: true, trim: true, delimiter: ",", }); console.log("Parsed rows:", rows); // <-- This still logs Buffer } return resultRows; }And I'm collecting the S3 objects like this:
const allCsvBuffers = []; for (const cont of Contents) { const key = cont.Key; const object = await getS3Object(bucketName, key); allCsvBuffers.push({ key, buffer: object.Body, }); } const filteredRows = filterCsvRows(allCsvBuffers, [118, 675]);Why are the parsed rows still showing as Buffer instead of parsed CSV rows, and how can I correctly parse and filter them?
