1

I would like to read a large, local CSV file in chunks using Papa parse in JavaScript, so that the application doesn't get stuck while the file is read. By "local" I mean that the file is on the server-side, accessible to javascript (it's not coming from the user's computer). The application doesn't use Node.js.

Papa parse documentation suggests this can be done by passing step or chunk (both not both) to the parse function as well as a file object:

Papa.parse(file, 
        {worker: true,
         chunk: function(rows) { ... },
         complete: ...))

however it does not say what file should be. Other answers on here (How can I read a local file with Papa Parse?) say it should be a streamable file object but all the answers rely on require('fs') from node.js, which this application doesn't use.

Is there a way to read a local (server-side) file in chunks using Papaparse in a way that can be run in the browser, without needing node.js?

The method I have tried is this:

$.get("./file.csv", function(contents) { 
   // pass contents of file to Papa.parse
   Papa.parse(contents,  {chunk: ...});
});

however, since the contents of the csv file are passed as a string to Papa.parse, the browser does become slow and unresponsive when it's running presumably because loading the string into memory is slow. how can I make it so that it's actually streaming from the file object? thanks.

user20c
  • 31
  • 2

0 Answers0