2017-09-14 21:14:22 +00:00
|
|
|
function read_file(filename/*:string*/, options/*:CFBReadOpts*/) {
|
2017-10-20 20:36:54 +00:00
|
|
|
get_fs();
|
2014-11-03 04:02:42 +00:00
|
|
|
return parse(fs.readFileSync(filename), options);
|
2013-11-26 15:56:58 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 21:14:22 +00:00
|
|
|
function read(blob/*:RawBytes|string*/, options/*:CFBReadOpts*/) {
|
2017-07-28 17:53:08 +00:00
|
|
|
switch(options && options.type || "base64") {
|
2017-09-14 21:14:22 +00:00
|
|
|
case "file": /*:: if(typeof blob !== 'string') throw "Must pass a filename when type='file'"; */return read_file(blob, options);
|
2017-07-28 17:53:08 +00:00
|
|
|
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);
|
2013-11-26 15:56:58 +00:00
|
|
|
}
|
2017-07-28 17:53:08 +00:00
|
|
|
return parse(/*::typeof blob == 'string' ? new Buffer(blob, 'utf-8') : */blob, options);
|
2013-11-26 15:56:58 +00:00
|
|
|
}
|
|
|
|
|