js-cfb/bits/49_readutils.js
SheetJS 0e33eb6e13 unify changes with main sheetjs project
- Fixed issue #14 h/t @wisekaa03
- CFB write truncate file names exceeding 32 characters

Co-authored-by: Stanislav Vyaliy <wisekaa03@gmail.com>
2022-03-31 04:57:58 -04:00

19 lines
871 B
JavaScript

function read_file(filename/*:string*/, options/*:CFBReadOpts*/) {
get_fs();
return parse(fs.readFileSync(filename), options);
}
function read(blob/*:RawBytes|string*/, options/*:CFBReadOpts*/) {
var type = options && options.type;
if(!type) {
if(has_buf && Buffer.isBuffer(blob)) type = "buffer";
}
switch(type || "base64") {
case "file": /*:: if(typeof blob !== 'string') throw "Must pass a filename when type='file'"; */return read_file(blob, options);
case "base64": /*:: if(typeof blob !== 'string') throw "Must pass a base64-encoded binary string when type='file'"; */return parse(s2a(Base64_decode(blob)), options);
case "binary": /*:: if(typeof blob !== 'string') throw "Must pass a binary string when type='file'"; */return parse(s2a(blob), options);
}
return parse(/*::typeof blob == 'string' ? new Buffer(blob, 'utf-8') : */blob, options);
}