vslinko / deno-csv

Streaming API for reading and writing CSV for https://deno.land/
MIT License
51 stars 5 forks source link

Buffer Issue #2

Closed antoniotorres closed 4 years ago

antoniotorres commented 4 years ago

test.ts

import { readCSV } from "https://deno.land/x/csv/mod.ts";

const f = await Deno.open("./example.csv");

let rows = [];
for await (const row of readCSV(f)) {
  const cells = [];
  for await (const cell of row) {
    cells.push(cell);
  }
  rows.push(cells);
}
f.close();

CSV file example.csv

id,created_at,updated_at,deleted,json_file
b8e5c268-a4ae-428d-bc4a-0758aaa1aea4,2020-05-20T00:00:00.000Z,2020-05-20T00:00:00.000Z,false,"{""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false, ""key1"": false}"

Bash Result

deno run --allow-read test.ts
error: Uncaught RangeError: offset is out of bounds
    this.columnBuffer.set(
                      ^
    at Uint8Array.set (<anonymous>)
    at CSVReader.readChars (https://deno.land/x/csv/reader.ts:201:23)
    at CSVReader.parseCycle (https://deno.land/x/csv/reader.ts:369:16)
    at CSVReader.read (https://deno.land/x/csv/reader.ts:163:12)
    at https://deno.land/x/csv/reader.ts:711:21
    at new Promise (<anonymous>)
    at CSVRowIteratorReader.onRequested (https://deno.land/x/csv/reader.ts:708:17)
    at RowIterator.onRequested (https://deno.land/x/csv/reader.ts:733:51)
    at RowIterator.next (https://deno.land/x/csv/reader.ts:624:40)
    at file:///Users/antonio/migration-to-postgres/deno/test.ts:8:20
vslinko commented 4 years ago

Hello @antoniotorres. Thanks for your feedback!

You can enjoy the fix in v0.3.1.

vslinko commented 4 years ago

@antoniotorres btw, if you need to read whole rows, please use readCSVRows because it much performant than readCSV. readCSV is good when you have really huge cells.