js-cfb/bits/49_readutils.js
SheetJS 9e22a4425e version bump 0.13.2
- file writing includes `fs` as appropriate
- CLI modify and write options
- infrastructure update
2017-10-20 16:36:54 -04:00

15 lines
781 B
JavaScript

function read_file(filename/*:string*/, options/*:CFBReadOpts*/) {
get_fs();
return parse(fs.readFileSync(filename), options);
}
function read(blob/*:RawBytes|string*/, options/*:CFBReadOpts*/) {
switch(options && options.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);
}