-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathfile-wrapper.min.js
1 lines (1 loc) · 1.43 KB
/
file-wrapper.min.js
1
var createFileWrapper=function(){function e(e,r){var n=this;if(n.isNode(e)){n.fs=require("fs");var t=require("string_decoder").StringDecoder;if(n.string_decoder=new t(r),void 0===n.fs.statSync(e))throw"File '"+e+"' doesn't exists!";var i=n.fs.openSync(e,"r");n.readChunk=function(e,r,t){var o=new Buffer(r);n.fs.read(i,o,0,r,e,function(e,r){t(e,o,r)})},n.decode=function(e,r){r(n.string_decoder.write(e))},n.getSize=function(){return n.fs.statSync(e).size}}else{if(!n.isHtml5File(e))throw"Given file should be instance of the File class for browser or a string containing a path to a file for Node.js, but it is neither: ["+typeof e+"] "+e;n.readChunk=function(r,n,t){lastPosition=r+n;var i=new FileReader;i.onloadend=function(e){var r;i.result&&(r=new Int8Array(i.result,0),r.slice=r.subarray),t(e.err,r,e.loaded)},i.readAsArrayBuffer(e.slice(r,r+n))},n.decode=function(e,n){var t=new FileReader;t.onloadend=function(e){n(e.currentTarget.result)},void 0!==r?t.readAsText(new Blob([e]),r):t.readAsText(new Blob([e]))},n.getSize=function(){return e.size}}}return e.prototype.isNode=function(e){return"undefined"!=typeof module&&module.exports&&"string"==typeof e},e.prototype.isHtml5File=function(e){return"undefined"!=typeof File&&e instanceof File},e};"undefined"!=typeof module&&module.exports?module.exports=createFileWrapper():"function"==typeof define?define(function(){return createFileWrapper()}):FileWrapper=createFileWrapper();