FjordWardenF
Denoβ€’3y agoβ€’
1 reply
FjordWarden

Read CSV files inside zip file using the web streams API

I need to read a number of csv files inside a zip file.
The basic example I've got working so far is the following:

import {BlobReader,ZipReader,ZipWriter} from 'https://deno.land/x/zipjs/index.js'
import {readCSV} from 'https://deno.land/x/csv/mod.ts'
import {CsvParseStream} from 'https://deno.land/std@0.201.0/csv/mod.ts'

const srcFile = await Deno.open('/data.zip')
const zipReader = new ZipReader(srcFile)
for (let entry of (await zipReader.getEntries())) {
  console.log('filename ', entry.filename)
  let csvStream = new CsvParseStream({skipFirstRow:false,columns:undefined})
  if (entry.filename.startsWith('code')) {
    await entry.getData(csvStream.writable)
    for await (const chunk of csvStream.readable) {
      console.log(chunk)
    }
  }
}

The problem is that the chunk is some weird array of strings of numbers and not the row I would expect.

[ "34",  "67", "97", ...1356838 more items


Any help would be welcome.
Was this page helpful?