I am trying to understand Papaparse. I see a lot of examples do something like this
var file = evt.target.files[0];
Papa.parse(file, {
header: true,
dynamicTyping: true,
complete: function(results) {
data = results;
}
});
This is nice and simple, directly parse a file.
However, at the same time I see some examples like so
upload (e) {
const that = this
const fileToLoad = event.target.files[0]
const reader = new FileReader()
reader.onload = fileLoadedEvent => {
Papa.parse(fileLoadedEvent.target.result, {
header: true,
complete (results) {
console.log('complete', results)
that.doc = JSON.stringify(results.data, null, 2)
},
error (errors) {
console.log('error', errors)
}
})
}
reader.readAsText(fileToLoad)
},
That is a vuejs function, but I see other examples like this. So why do some call Papaparse directly, whilst others use a Filereader
to load the file before parsing?
Just trying to understand the difference between the two approaches?
Thanks
Example using Webworker and Filereader HERE Example doing a direct parse HERE