Skip to content

Commit

Permalink
Avoid use of node stream in browser context.
Browse files Browse the repository at this point in the history
  • Loading branch information
jefbarn authored and Sergi Almacellas Abellana committed Nov 14, 2018
1 parent fff1ee1 commit 0e392e2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ module.exports = function(grunt) {
grunt.initConfig({
uglify: {
options: {
compress: {
global_defs: {
'PAPA_BROWSER_CONTEXT': true
},
dead_code: true
},
output: {
comments: 'some',
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"license": "MIT",
"main": "papaparse.js",
"browser": "papaparse.min.js",
"devDependencies": {
"chai": "^4.2.0",
"connect": "^3.3.3",
Expand Down
12 changes: 8 additions & 4 deletions papaparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ if (!Array.isArray)
Papa.FileStreamer = FileStreamer;
Papa.StringStreamer = StringStreamer;
Papa.ReadableStreamStreamer = ReadableStreamStreamer;
Papa.DuplexStreamStreamer = DuplexStreamStreamer;
if (typeof PAPA_BROWSER_CONTEXT === 'undefined') {
Papa.DuplexStreamStreamer = DuplexStreamStreamer;
}

if (global.jQuery)
{
Expand Down Expand Up @@ -241,7 +243,7 @@ if (!Array.isArray)
}

var streamer = null;
if (_input === Papa.NODE_STREAM_INPUT)
if (_input === Papa.NODE_STREAM_INPUT && typeof PAPA_BROWSER_CONTEXT === 'undefined')
{
// create a node Duplex stream for use
// with .pipe
Expand Down Expand Up @@ -982,8 +984,10 @@ if (!Array.isArray)
});
stream.once('finish', bindFunction(this._onWriteComplete, this));
}
DuplexStreamStreamer.prototype = Object.create(ChunkStreamer.prototype);
DuplexStreamStreamer.prototype.constructor = DuplexStreamStreamer;
if (typeof PAPA_BROWSER_CONTEXT === 'undefined') {
DuplexStreamStreamer.prototype = Object.create(ChunkStreamer.prototype);
DuplexStreamStreamer.prototype.constructor = DuplexStreamStreamer;
}


// Use one ParserHandle per entire CSV file or string
Expand Down
Loading

0 comments on commit 0e392e2

Please sign in to comment.