Skip to content

Commit

Permalink
pass codepage option to DSV buffer parser
Browse files Browse the repository at this point in the history
Fixes SheetJS#1218 ; Closes SheetJS#1219
  • Loading branch information
starmon00 committed Aug 14, 2018
1 parent 82e909e commit 01de12d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions bits/40_harb.js
Original file line number Diff line number Diff line change
Expand Up @@ -833,13 +833,17 @@ var PRN = (function() {
switch(opts.type) {
case 'base64': str = Base64.decode(d); break;
case 'binary': str = d; break;
case 'buffer': str = d.toString('binary'); break;
case 'array': str = cc2str(d); break;
case 'buffer':
if(opts.codepage == 65001) str = d.toString('utf8');
else if(opts.codepage && typeof cptable !== 'undefined') str = cptable.utils.decode(opts.codepage, d);
else str = d.toString('binary');
break;
case 'array': str = cc2str(d); break;
case 'string': str = d; break;
default: throw new Error("Unrecognized type " + opts.type);
}
if(bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF) str = utf8read(str.slice(3));
else if((opts.type == 'binary' || opts.type == 'buffer') && typeof cptable !== 'undefined' && opts.codepage) str = cptable.utils.decode(opts.codepage, cptable.utils.encode(1252,str));
else if((opts.type == 'binary') && typeof cptable !== 'undefined' && opts.codepage) str = cptable.utils.decode(opts.codepage, cptable.utils.encode(1252,str));
if(str.slice(0,19) == "socialcalc:version:") return ETH.to_sheet(opts.type == 'string' ? str : utf8read(str), opts);
return prn_to_sheet_str(str, opts);
}
Expand Down Expand Up @@ -885,4 +889,3 @@ function read_wb_ID(d, opts) {
return PRN.to_workbook(d, opts);
}
}

0 comments on commit 01de12d

Please sign in to comment.