diff --git a/docs/docs.html b/docs/docs.html index 261caa2..3adde71 100644 --- a/docs/docs.html +++ b/docs/docs.html @@ -429,6 +429,7 @@ var csv = Papa.unparse({ dynamicTyping: false, preview: 0, encoding: "", + decoder: undefined, worker: false, comments: false, step: undefined, @@ -530,6 +531,20 @@ var csv = Papa.unparse({ The encoding to use when opening local files. If specified, it must be a value supported by the FileReader API. +
decoder
+ worker
diff --git a/papaparse.js b/papaparse.js
index 6e68a52..0c65c29 100755
--- a/papaparse.js
+++ b/papaparse.js
@@ -852,7 +852,18 @@ License: MIT
{
try
{
- queue.push(typeof chunk === 'string' ? chunk : chunk.toString(this._config.encoding));
+ var encoding = this._config.encoding;
+ var decoder = this._config.decoder;
+ var encodedString = '';
+
+ if (typeof decoder === 'function') {
+ encodedString = decoder(chunk, encoding);
+ } else if (typeof chunk === 'string') {
+ encodedString = chunk;
+ } else {
+ encodedString = chunk.toString(encoding);
+ }
+ queue.push(encodedString);
if (parseOnData)
{
@@ -941,7 +952,19 @@ License: MIT
// when too many items have been added without their
// callback being invoked
parseCallbackQueue.push(bindFunction(function() {
- this.parseChunk(typeof chunk === 'string' ? chunk : chunk.toString(config.encoding));
+ var encoding = config.encoding;
+ var decoder = config.decoder;
+ var encodedString = '';
+
+ if (typeof decoder === 'function') {
+ encodedString = decoder(chunk, encoding);
+ } else if (typeof chunk === 'string') {
+ encodedString = chunk;
+ } else {
+ encodedString = chunk.toString(encoding);
+ }
+
+ this.parseChunk(encodedString);
if (isFunction(callback)) {
return callback();
}