markdown-it-imsize.js 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define(factory);
  6. else if(typeof exports === 'object')
  7. exports["markdown-it-imsize.js"] = factory();
  8. else
  9. root["markdown-it-imsize.js"] = factory();
  10. })(this, function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/ // The require function
  15. /******/ function __webpack_require__(moduleId) {
  16. /******/ // Check if module is in cache
  17. /******/ if(installedModules[moduleId])
  18. /******/ return installedModules[moduleId].exports;
  19. /******/ // Create a new module (and put it into the cache)
  20. /******/ var module = installedModules[moduleId] = {
  21. /******/ exports: {},
  22. /******/ id: moduleId,
  23. /******/ loaded: false
  24. /******/ };
  25. /******/ // Execute the module function
  26. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  27. /******/ // Flag the module as loaded
  28. /******/ module.loaded = true;
  29. /******/ // Return the exports of the module
  30. /******/ return module.exports;
  31. /******/ }
  32. /******/ // expose the modules object (__webpack_modules__)
  33. /******/ __webpack_require__.m = modules;
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/ // __webpack_public_path__
  37. /******/ __webpack_require__.p = "";
  38. /******/ // Load entry module and return exports
  39. /******/ return __webpack_require__(0);
  40. /******/ })
  41. /************************************************************************/
  42. /******/ ([
  43. /* 0 */
  44. /***/ function(module, exports, __webpack_require__) {
  45. // Process ![test]( x =100x200)
  46. // ^^^^^^^^ this size specification
  47. 'use strict';
  48. var sizeOf = __webpack_require__(2);
  49. var parseImageSize = __webpack_require__(1);
  50. function image_with_size(md, options) {
  51. return function(state, silent) {
  52. var attrs,
  53. code,
  54. label,
  55. labelEnd,
  56. labelStart,
  57. pos,
  58. ref,
  59. res,
  60. title,
  61. width = '',
  62. height = '',
  63. token,
  64. tokens,
  65. start,
  66. href = '',
  67. oldPos = state.pos,
  68. max = state.posMax;
  69. if (state.src.charCodeAt(state.pos) !== 0x21/* ! */) { return false; }
  70. if (state.src.charCodeAt(state.pos + 1) !== 0x5B/* [ */) { return false; }
  71. labelStart = state.pos + 2;
  72. labelEnd = md.helpers.parseLinkLabel(state, state.pos + 1, false);
  73. // parser failed to find ']', so it's not a valid link
  74. if (labelEnd < 0) { return false; }
  75. pos = labelEnd + 1;
  76. if (pos < max && state.src.charCodeAt(pos) === 0x28/* ( */) {
  77. //
  78. // Inline link
  79. //
  80. // [link]( <href> "title" )
  81. // ^^ skipping these spaces
  82. pos++;
  83. for (; pos < max; pos++) {
  84. code = state.src.charCodeAt(pos);
  85. if (code !== 0x20 && code !== 0x0A) { break; }
  86. }
  87. if (pos >= max) { return false; }
  88. // [link]( <href> "title" )
  89. // ^^^^^^ parsing link destination
  90. start = pos;
  91. res = md.helpers.parseLinkDestination(state.src, pos, state.posMax);
  92. if (res.ok) {
  93. href = state.md.normalizeLink(res.str);
  94. if (state.md.validateLink(href)) {
  95. pos = res.pos;
  96. } else {
  97. href = '';
  98. }
  99. }
  100. // [link]( <href> "title" )
  101. // ^^ skipping these spaces
  102. start = pos;
  103. for (; pos < max; pos++) {
  104. code = state.src.charCodeAt(pos);
  105. if (code !== 0x20 && code !== 0x0A) { break; }
  106. }
  107. // [link]( <href> "title" )
  108. // ^^^^^^^ parsing link title
  109. res = md.helpers.parseLinkTitle(state.src, pos, state.posMax);
  110. if (pos < max && start !== pos && res.ok) {
  111. title = res.str;
  112. pos = res.pos;
  113. // [link]( <href> "title" )
  114. // ^^ skipping these spaces
  115. for (; pos < max; pos++) {
  116. code = state.src.charCodeAt(pos);
  117. if (code !== 0x20 && code !== 0x0A) { break; }
  118. }
  119. } else {
  120. title = '';
  121. }
  122. // [link]( <href> "title" =WxH )
  123. // ^^^^ parsing image size
  124. if (pos - 1 >= 0) {
  125. code = state.src.charCodeAt(pos - 1);
  126. // there must be at least one white spaces
  127. // between previous field and the size
  128. if (code === 0x20) {
  129. res = parseImageSize(state.src, pos, state.posMax);
  130. if (res.ok) {
  131. width = res.width;
  132. height = res.height;
  133. pos = res.pos;
  134. // [link]( <href> "title" =WxH )
  135. // ^^ skipping these spaces
  136. for (; pos < max; pos++) {
  137. code = state.src.charCodeAt(pos);
  138. if (code !== 0x20 && code !== 0x0A) { break; }
  139. }
  140. }
  141. }
  142. }
  143. if (pos >= max || state.src.charCodeAt(pos) !== 0x29/* ) */) {
  144. state.pos = oldPos;
  145. return false;
  146. }
  147. pos++;
  148. } else {
  149. //
  150. // Link reference
  151. //
  152. if (typeof state.env.references === 'undefined') { return false; }
  153. // [foo] [bar]
  154. // ^^ optional whitespace (can include newlines)
  155. for (; pos < max; pos++) {
  156. code = state.src.charCodeAt(pos);
  157. if (code !== 0x20 && code !== 0x0A) { break; }
  158. }
  159. if (pos < max && state.src.charCodeAt(pos) === 0x5B/* [ */) {
  160. start = pos + 1;
  161. pos = md.helpers.parseLinkLabel(state, pos);
  162. if (pos >= 0) {
  163. label = state.src.slice(start, pos++);
  164. } else {
  165. pos = labelEnd + 1;
  166. }
  167. } else {
  168. pos = labelEnd + 1;
  169. }
  170. // covers label === '' and label === undefined
  171. // (collapsed reference link and shortcut reference link respectively)
  172. if (!label) { label = state.src.slice(labelStart, labelEnd); }
  173. ref = state.env.references[md.utils.normalizeReference(label)];
  174. if (!ref) {
  175. state.pos = oldPos;
  176. return false;
  177. }
  178. href = ref.href;
  179. title = ref.title;
  180. }
  181. //
  182. // We found the end of the link, and know for a fact it's a valid link;
  183. // so all that's left to do is to call tokenizer.
  184. //
  185. if (!silent) {
  186. state.pos = labelStart;
  187. state.posMax = labelEnd;
  188. var newState = new state.md.inline.State(
  189. state.src.slice(labelStart, labelEnd),
  190. state.md,
  191. state.env,
  192. tokens = []
  193. );
  194. newState.md.inline.tokenize(newState);
  195. // if 'autofill' option is specified
  196. // and width/height are both blank,
  197. // they are filled automatically
  198. if (options) {
  199. if (options.autofill && width === '' && height === '') {
  200. try {
  201. var dimensions = sizeOf(href);
  202. width = dimensions.width;
  203. height = dimensions.height;
  204. } catch (e) { }
  205. }
  206. }
  207. token = state.push('image', 'img', 0);
  208. token.attrs = attrs = [ [ 'src', href ],
  209. [ 'alt', '' ] ];
  210. token.children = tokens;
  211. if (title) {
  212. attrs.push([ 'title', title ]);
  213. }
  214. if (width !== '') {
  215. attrs.push([ 'width', width ]);
  216. }
  217. if (height !== '') {
  218. attrs.push([ 'height', height ]);
  219. }
  220. }
  221. state.pos = pos;
  222. state.posMax = max;
  223. return true;
  224. };
  225. }
  226. module.exports = function imsize_plugin(md, options) {
  227. md.inline.ruler.before('emphasis', 'image', image_with_size(md, options));
  228. };
  229. /***/ },
  230. /* 1 */
  231. /***/ function(module, exports, __webpack_require__) {
  232. // Parse image size
  233. //
  234. 'use strict';
  235. function parseNextNumber(str, pos, max) {
  236. var code,
  237. start = pos,
  238. result = {
  239. ok: false,
  240. pos: pos,
  241. value: ''
  242. };
  243. code = str.charCodeAt(pos);
  244. while (pos < max && (code >= 0x30 /* 0 */ && code <= 0x39 /* 9 */) || code === 0x25 /* % */) {
  245. code = str.charCodeAt(++pos);
  246. }
  247. result.ok = true;
  248. result.pos = pos;
  249. result.value = str.slice(start, pos);
  250. return result;
  251. }
  252. module.exports = function parseImageSize(str, pos, max) {
  253. var code,
  254. result = {
  255. ok: false,
  256. pos: 0,
  257. width: '',
  258. height: ''
  259. };
  260. if (pos >= max) { return result; }
  261. code = str.charCodeAt(pos);
  262. if (code !== 0x3d /* = */) { return result; }
  263. pos++;
  264. // size must follow = without any white spaces as follows
  265. // (1) =300x200
  266. // (2) =300x
  267. // (3) =x200
  268. code = str.charCodeAt(pos);
  269. if (code !== 0x78 /* x */ && (code < 0x30 || code > 0x39) /* [0-9] */) {
  270. return result;
  271. }
  272. // parse width
  273. var resultW = parseNextNumber(str, pos, max);
  274. pos = resultW.pos;
  275. // next charactor must be 'x'
  276. code = str.charCodeAt(pos);
  277. if (code !== 0x78 /* x */) { return result; }
  278. pos++;
  279. // parse height
  280. var resultH = parseNextNumber(str, pos, max);
  281. pos = resultH.pos;
  282. result.width = resultW.value;
  283. result.height = resultH.value;
  284. result.pos = pos;
  285. result.ok = true;
  286. return result;
  287. };
  288. /***/ },
  289. /* 2 */
  290. /***/ function(module, exports, __webpack_require__) {
  291. /* WEBPACK VAR INJECTION */(function(Buffer) {'use strict';
  292. var fs = __webpack_require__(16);
  293. var path = __webpack_require__(6);
  294. var detector = __webpack_require__(3);
  295. var handlers = {};
  296. var types = __webpack_require__(5);
  297. types.forEach(function(type) {
  298. handlers[type] = __webpack_require__(4)("./" + type);
  299. });
  300. var MaxBufferSize = 128 * 1024;
  301. function lookup(buffer, filepath) {
  302. var type = detector(buffer, filepath);
  303. if (type in handlers) {
  304. var size = handlers[type].calculate(buffer, filepath);
  305. if (size !== false) {
  306. size.type = type;
  307. return size;
  308. }
  309. }
  310. throw new TypeError('Unsupported file type');
  311. }
  312. function asyncFileToBuffer(filepath, callback) {
  313. fs.open(filepath, 'r', function(err0, descriptor) {
  314. if (err0) {
  315. return callback(err0);
  316. }
  317. var size = fs.fstatSync(descriptor).size;
  318. var bufferSize = Math.min(size, MaxBufferSize);
  319. var buffer = new Buffer(bufferSize);
  320. fs.read(descriptor, buffer, 0, bufferSize, 0, function(err1) {
  321. if (err1) {
  322. return callback(err1);
  323. }
  324. fs.close(descriptor, function(err2) {
  325. callback(err2, buffer);
  326. });
  327. });
  328. });
  329. }
  330. function syncFileToBuffer(filepath) {
  331. var descriptor = fs.openSync(filepath, 'r');
  332. var size = fs.fstatSync(descriptor).size;
  333. var bufferSize = Math.min(size, MaxBufferSize);
  334. var buffer = new Buffer(bufferSize);
  335. fs.readSync(descriptor, buffer, 0, bufferSize, 0);
  336. fs.closeSync(descriptor);
  337. return buffer;
  338. }
  339. /**
  340. * Returns the dimensions of the image file
  341. * @param[in] input: input image path
  342. * @param[in] callback(option): if specified, gets size async.
  343. */
  344. module.exports = function(input, callback) {
  345. if (typeof input !== 'string') {
  346. throw new TypeError('Input must be file name');
  347. }
  348. var filepath = path.resolve(input);
  349. if (typeof callback === 'function') {
  350. asyncFileToBuffer(filepath, function(err, buffer) {
  351. if (err) {
  352. return callback(err);
  353. }
  354. var dimensions;
  355. try {
  356. dimensions = lookup(buffer, filepath);
  357. } catch (e) {
  358. err = e;
  359. }
  360. callback(err, dimensions);
  361. });
  362. } else {
  363. var buffer = syncFileToBuffer(filepath);
  364. return lookup(buffer, filepath);
  365. }
  366. };
  367. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(7).Buffer))
  368. /***/ },
  369. /* 3 */
  370. /***/ function(module, exports, __webpack_require__) {
  371. 'use strict';
  372. var typeMap = {};
  373. var types = __webpack_require__(5);
  374. types.forEach(function(type) {
  375. typeMap[type] = __webpack_require__(4)("./" + type).detect;
  376. });
  377. module.exports = function(buffer, filepath) {
  378. var type, result;
  379. for (type in typeMap) {
  380. if (type in typeMap) {
  381. result = typeMap[type](buffer, filepath);
  382. if (result) {
  383. return type;
  384. }
  385. }
  386. }
  387. throw new TypeError('Unsupported type');
  388. };
  389. /***/ },
  390. /* 4 */
  391. /***/ function(module, exports, __webpack_require__) {
  392. var map = {
  393. "./bmp": 8,
  394. "./bmp.js": 8,
  395. "./gif": 9,
  396. "./gif.js": 9,
  397. "./jpg": 10,
  398. "./jpg.js": 10,
  399. "./png": 11,
  400. "./png.js": 11,
  401. "./psd": 12,
  402. "./psd.js": 12,
  403. "./svg": 13,
  404. "./svg.js": 13,
  405. "./tiff": 14,
  406. "./tiff.js": 14,
  407. "./webp": 15,
  408. "./webp.js": 15
  409. };
  410. function webpackContext(req) {
  411. return __webpack_require__(webpackContextResolve(req));
  412. };
  413. function webpackContextResolve(req) {
  414. return map[req] || (function() { throw new Error("Cannot find module '" + req + "'.") }());
  415. };
  416. webpackContext.keys = function webpackContextKeys() {
  417. return Object.keys(map);
  418. };
  419. webpackContext.resolve = webpackContextResolve;
  420. module.exports = webpackContext;
  421. webpackContext.id = 4;
  422. /***/ },
  423. /* 5 */
  424. /***/ function(module, exports, __webpack_require__) {
  425. 'use strict';
  426. module.exports = [
  427. 'bmp',
  428. 'gif',
  429. 'jpg',
  430. 'png',
  431. 'tiff',
  432. ];
  433. /***/ },
  434. /* 6 */
  435. /***/ function(module, exports, __webpack_require__) {
  436. /* WEBPACK VAR INJECTION */(function(process) {// Copyright Joyent, Inc. and other Node contributors.
  437. //
  438. // Permission is hereby granted, free of charge, to any person obtaining a
  439. // copy of this software and associated documentation files (the
  440. // "Software"), to deal in the Software without restriction, including
  441. // without limitation the rights to use, copy, modify, merge, publish,
  442. // distribute, sublicense, and/or sell copies of the Software, and to permit
  443. // persons to whom the Software is furnished to do so, subject to the
  444. // following conditions:
  445. //
  446. // The above copyright notice and this permission notice shall be included
  447. // in all copies or substantial portions of the Software.
  448. //
  449. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  450. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  451. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  452. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  453. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  454. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  455. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  456. // resolves . and .. elements in a path array with directory names there
  457. // must be no slashes, empty elements, or device names (c:\) in the array
  458. // (so also no leading and trailing slashes - it does not distinguish
  459. // relative and absolute paths)
  460. function normalizeArray(parts, allowAboveRoot) {
  461. // if the path tries to go above the root, `up` ends up > 0
  462. var up = 0;
  463. for (var i = parts.length - 1; i >= 0; i--) {
  464. var last = parts[i];
  465. if (last === '.') {
  466. parts.splice(i, 1);
  467. } else if (last === '..') {
  468. parts.splice(i, 1);
  469. up++;
  470. } else if (up) {
  471. parts.splice(i, 1);
  472. up--;
  473. }
  474. }
  475. // if the path is allowed to go above the root, restore leading ..s
  476. if (allowAboveRoot) {
  477. for (; up--; up) {
  478. parts.unshift('..');
  479. }
  480. }
  481. return parts;
  482. }
  483. // Split a filename into [root, dir, basename, ext], unix version
  484. // 'root' is just a slash, or nothing.
  485. var splitPathRe =
  486. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  487. var splitPath = function(filename) {
  488. return splitPathRe.exec(filename).slice(1);
  489. };
  490. // path.resolve([from ...], to)
  491. // posix version
  492. exports.resolve = function() {
  493. var resolvedPath = '',
  494. resolvedAbsolute = false;
  495. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  496. var path = (i >= 0) ? arguments[i] : process.cwd();
  497. // Skip empty and invalid entries
  498. if (typeof path !== 'string') {
  499. throw new TypeError('Arguments to path.resolve must be strings');
  500. } else if (!path) {
  501. continue;
  502. }
  503. resolvedPath = path + '/' + resolvedPath;
  504. resolvedAbsolute = path.charAt(0) === '/';
  505. }
  506. // At this point the path should be resolved to a full absolute path, but
  507. // handle relative paths to be safe (might happen when process.cwd() fails)
  508. // Normalize the path
  509. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
  510. return !!p;
  511. }), !resolvedAbsolute).join('/');
  512. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  513. };
  514. // path.normalize(path)
  515. // posix version
  516. exports.normalize = function(path) {
  517. var isAbsolute = exports.isAbsolute(path),
  518. trailingSlash = substr(path, -1) === '/';
  519. // Normalize the path
  520. path = normalizeArray(filter(path.split('/'), function(p) {
  521. return !!p;
  522. }), !isAbsolute).join('/');
  523. if (!path && !isAbsolute) {
  524. path = '.';
  525. }
  526. if (path && trailingSlash) {
  527. path += '/';
  528. }
  529. return (isAbsolute ? '/' : '') + path;
  530. };
  531. // posix version
  532. exports.isAbsolute = function(path) {
  533. return path.charAt(0) === '/';
  534. };
  535. // posix version
  536. exports.join = function() {
  537. var paths = Array.prototype.slice.call(arguments, 0);
  538. return exports.normalize(filter(paths, function(p, index) {
  539. if (typeof p !== 'string') {
  540. throw new TypeError('Arguments to path.join must be strings');
  541. }
  542. return p;
  543. }).join('/'));
  544. };
  545. // path.relative(from, to)
  546. // posix version
  547. exports.relative = function(from, to) {
  548. from = exports.resolve(from).substr(1);
  549. to = exports.resolve(to).substr(1);
  550. function trim(arr) {
  551. var start = 0;
  552. for (; start < arr.length; start++) {
  553. if (arr[start] !== '') break;
  554. }
  555. var end = arr.length - 1;
  556. for (; end >= 0; end--) {
  557. if (arr[end] !== '') break;
  558. }
  559. if (start > end) return [];
  560. return arr.slice(start, end - start + 1);
  561. }
  562. var fromParts = trim(from.split('/'));
  563. var toParts = trim(to.split('/'));
  564. var length = Math.min(fromParts.length, toParts.length);
  565. var samePartsLength = length;
  566. for (var i = 0; i < length; i++) {
  567. if (fromParts[i] !== toParts[i]) {
  568. samePartsLength = i;
  569. break;
  570. }
  571. }
  572. var outputParts = [];
  573. for (var i = samePartsLength; i < fromParts.length; i++) {
  574. outputParts.push('..');
  575. }
  576. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  577. return outputParts.join('/');
  578. };
  579. exports.sep = '/';
  580. exports.delimiter = ':';
  581. exports.dirname = function(path) {
  582. var result = splitPath(path),
  583. root = result[0],
  584. dir = result[1];
  585. if (!root && !dir) {
  586. // No dirname whatsoever
  587. return '.';
  588. }
  589. if (dir) {
  590. // It has a dirname, strip trailing slash
  591. dir = dir.substr(0, dir.length - 1);
  592. }
  593. return root + dir;
  594. };
  595. exports.basename = function(path, ext) {
  596. var f = splitPath(path)[2];
  597. // TODO: make this comparison case-insensitive on windows?
  598. if (ext && f.substr(-1 * ext.length) === ext) {
  599. f = f.substr(0, f.length - ext.length);
  600. }
  601. return f;
  602. };
  603. exports.extname = function(path) {
  604. return splitPath(path)[3];
  605. };
  606. function filter (xs, f) {
  607. if (xs.filter) return xs.filter(f);
  608. var res = [];
  609. for (var i = 0; i < xs.length; i++) {
  610. if (f(xs[i], i, xs)) res.push(xs[i]);
  611. }
  612. return res;
  613. }
  614. // String.prototype.substr - negative index don't work in IE8
  615. var substr = 'ab'.substr(-1) === 'b'
  616. ? function (str, start, len) { return str.substr(start, len) }
  617. : function (str, start, len) {
  618. if (start < 0) start = str.length + start;
  619. return str.substr(start, len);
  620. }
  621. ;
  622. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(18)))
  623. /***/ },
  624. /* 7 */
  625. /***/ function(module, exports, __webpack_require__) {
  626. /* WEBPACK VAR INJECTION */(function(Buffer) {/*!
  627. * The buffer module from node.js, for the browser.
  628. *
  629. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  630. * @license MIT
  631. */
  632. var base64 = __webpack_require__(21)
  633. var ieee754 = __webpack_require__(19)
  634. var isArray = __webpack_require__(20)
  635. exports.Buffer = Buffer
  636. exports.SlowBuffer = SlowBuffer
  637. exports.INSPECT_MAX_BYTES = 50
  638. Buffer.poolSize = 8192 // not used by this implementation
  639. var kMaxLength = 0x3fffffff
  640. var rootParent = {}
  641. /**
  642. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  643. * === true Use Uint8Array implementation (fastest)
  644. * === false Use Object implementation (most compatible, even IE6)
  645. *
  646. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  647. * Opera 11.6+, iOS 4.2+.
  648. *
  649. * Note:
  650. *
  651. * - Implementation must support adding new properties to `Uint8Array` instances.
  652. * Firefox 4-29 lacked support, fixed in Firefox 30+.
  653. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  654. *
  655. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  656. *
  657. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  658. * incorrect length in some situations.
  659. *
  660. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they will
  661. * get the Object implementation, which is slower but will work correctly.
  662. */
  663. Buffer.TYPED_ARRAY_SUPPORT = (function () {
  664. try {
  665. var buf = new ArrayBuffer(0)
  666. var arr = new Uint8Array(buf)
  667. arr.foo = function () { return 42 }
  668. return arr.foo() === 42 && // typed array instances can be augmented
  669. typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
  670. new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
  671. } catch (e) {
  672. return false
  673. }
  674. })()
  675. /**
  676. * Class: Buffer
  677. * =============
  678. *
  679. * The Buffer constructor returns instances of `Uint8Array` that are augmented
  680. * with function properties for all the node `Buffer` API functions. We use
  681. * `Uint8Array` so that square bracket notation works as expected -- it returns
  682. * a single octet.
  683. *
  684. * By augmenting the instances, we can avoid modifying the `Uint8Array`
  685. * prototype.
  686. */
  687. function Buffer (subject, encoding) {
  688. var self = this
  689. if (!(self instanceof Buffer)) return new Buffer(subject, encoding)
  690. var type = typeof subject
  691. var length
  692. if (type === 'number') {
  693. length = +subject
  694. } else if (type === 'string') {
  695. length = Buffer.byteLength(subject, encoding)
  696. } else if (type === 'object' && subject !== null) {
  697. // assume object is array-like
  698. if (subject.type === 'Buffer' && isArray(subject.data)) subject = subject.data
  699. length = +subject.length
  700. } else {
  701. throw new TypeError('must start with number, buffer, array or string')
  702. }
  703. if (length > kMaxLength) {
  704. throw new RangeError('Attempt to allocate Buffer larger than maximum size: 0x' +
  705. kMaxLength.toString(16) + ' bytes')
  706. }
  707. if (length < 0) length = 0
  708. else length >>>= 0 // coerce to uint32
  709. if (Buffer.TYPED_ARRAY_SUPPORT) {
  710. // Preferred: Return an augmented `Uint8Array` instance for best performance
  711. self = Buffer._augment(new Uint8Array(length)) // eslint-disable-line consistent-this
  712. } else {
  713. // Fallback: Return THIS instance of Buffer (created by `new`)
  714. self.length = length
  715. self._isBuffer = true
  716. }
  717. var i
  718. if (Buffer.TYPED_ARRAY_SUPPORT && typeof subject.byteLength === 'number') {
  719. // Speed optimization -- use set if we're copying from a typed array
  720. self._set(subject)
  721. } else if (isArrayish(subject)) {
  722. // Treat array-ish objects as a byte array
  723. if (Buffer.isBuffer(subject)) {
  724. for (i = 0; i < length; i++) {
  725. self[i] = subject.readUInt8(i)
  726. }
  727. } else {
  728. for (i = 0; i < length; i++) {
  729. self[i] = ((subject[i] % 256) + 256) % 256
  730. }
  731. }
  732. } else if (type === 'string') {
  733. self.write(subject, 0, encoding)
  734. } else if (type === 'number' && !Buffer.TYPED_ARRAY_SUPPORT) {
  735. for (i = 0; i < length; i++) {
  736. self[i] = 0
  737. }
  738. }
  739. if (length > 0 && length <= Buffer.poolSize) self.parent = rootParent
  740. return self
  741. }
  742. function SlowBuffer (subject, encoding) {
  743. if (!(this instanceof SlowBuffer)) return new SlowBuffer(subject, encoding)
  744. var buf = new Buffer(subject, encoding)
  745. delete buf.parent
  746. return buf
  747. }
  748. Buffer.isBuffer = function isBuffer (b) {
  749. return !!(b != null && b._isBuffer)
  750. }
  751. Buffer.compare = function compare (a, b) {
  752. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  753. throw new TypeError('Arguments must be Buffers')
  754. }
  755. if (a === b) return 0
  756. var x = a.length
  757. var y = b.length
  758. for (var i = 0, len = Math.min(x, y); i < len && a[i] === b[i]; i++) {}
  759. if (i !== len) {
  760. x = a[i]
  761. y = b[i]
  762. }
  763. if (x < y) return -1
  764. if (y < x) return 1
  765. return 0
  766. }
  767. Buffer.isEncoding = function isEncoding (encoding) {
  768. switch (String(encoding).toLowerCase()) {
  769. case 'hex':
  770. case 'utf8':
  771. case 'utf-8':
  772. case 'ascii':
  773. case 'binary':
  774. case 'base64':
  775. case 'raw':
  776. case 'ucs2':
  777. case 'ucs-2':
  778. case 'utf16le':
  779. case 'utf-16le':
  780. return true
  781. default:
  782. return false
  783. }
  784. }
  785. Buffer.concat = function concat (list, totalLength) {
  786. if (!isArray(list)) throw new TypeError('list argument must be an Array of Buffers.')
  787. if (list.length === 0) {
  788. return new Buffer(0)
  789. } else if (list.length === 1) {
  790. return list[0]
  791. }
  792. var i
  793. if (totalLength === undefined) {
  794. totalLength = 0
  795. for (i = 0; i < list.length; i++) {
  796. totalLength += list[i].length
  797. }
  798. }
  799. var buf = new Buffer(totalLength)
  800. var pos = 0
  801. for (i = 0; i < list.length; i++) {
  802. var item = list[i]
  803. item.copy(buf, pos)
  804. pos += item.length
  805. }
  806. return buf
  807. }
  808. Buffer.byteLength = function byteLength (str, encoding) {
  809. var ret
  810. str = str + ''
  811. switch (encoding || 'utf8') {
  812. case 'ascii':
  813. case 'binary':
  814. case 'raw':
  815. ret = str.length
  816. break
  817. case 'ucs2':
  818. case 'ucs-2':
  819. case 'utf16le':
  820. case 'utf-16le':
  821. ret = str.length * 2
  822. break
  823. case 'hex':
  824. ret = str.length >>> 1
  825. break
  826. case 'utf8':
  827. case 'utf-8':
  828. ret = utf8ToBytes(str).length
  829. break
  830. case 'base64':
  831. ret = base64ToBytes(str).length
  832. break
  833. default:
  834. ret = str.length
  835. }
  836. return ret
  837. }
  838. // pre-set for values that may exist in the future
  839. Buffer.prototype.length = undefined
  840. Buffer.prototype.parent = undefined
  841. // toString(encoding, start=0, end=buffer.length)
  842. Buffer.prototype.toString = function toString (encoding, start, end) {
  843. var loweredCase = false
  844. start = start >>> 0
  845. end = end === undefined || end === Infinity ? this.length : end >>> 0
  846. if (!encoding) encoding = 'utf8'
  847. if (start < 0) start = 0
  848. if (end > this.length) end = this.length
  849. if (end <= start) return ''
  850. while (true) {
  851. switch (encoding) {
  852. case 'hex':
  853. return hexSlice(this, start, end)
  854. case 'utf8':
  855. case 'utf-8':
  856. return utf8Slice(this, start, end)
  857. case 'ascii':
  858. return asciiSlice(this, start, end)
  859. case 'binary':
  860. return binarySlice(this, start, end)
  861. case 'base64':
  862. return base64Slice(this, start, end)
  863. case 'ucs2':
  864. case 'ucs-2':
  865. case 'utf16le':
  866. case 'utf-16le':
  867. return utf16leSlice(this, start, end)
  868. default:
  869. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  870. encoding = (encoding + '').toLowerCase()
  871. loweredCase = true
  872. }
  873. }
  874. }
  875. Buffer.prototype.equals = function equals (b) {
  876. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  877. if (this === b) return true
  878. return Buffer.compare(this, b) === 0
  879. }
  880. Buffer.prototype.inspect = function inspect () {
  881. var str = ''
  882. var max = exports.INSPECT_MAX_BYTES
  883. if (this.length > 0) {
  884. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  885. if (this.length > max) str += ' ... '
  886. }
  887. return '<Buffer ' + str + '>'
  888. }
  889. Buffer.prototype.compare = function compare (b) {
  890. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  891. if (this === b) return 0
  892. return Buffer.compare(this, b)
  893. }
  894. Buffer.prototype.indexOf = function indexOf (val, byteOffset) {
  895. if (byteOffset > 0x7fffffff) byteOffset = 0x7fffffff
  896. else if (byteOffset < -0x80000000) byteOffset = -0x80000000
  897. byteOffset >>= 0
  898. if (this.length === 0) return -1
  899. if (byteOffset >= this.length) return -1
  900. // Negative offsets start from the end of the buffer
  901. if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0)
  902. if (typeof val === 'string') {
  903. if (val.length === 0) return -1 // special case: looking for empty string always fails
  904. return String.prototype.indexOf.call(this, val, byteOffset)
  905. }
  906. if (Buffer.isBuffer(val)) {
  907. return arrayIndexOf(this, val, byteOffset)
  908. }
  909. if (typeof val === 'number') {
  910. if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') {
  911. return Uint8Array.prototype.indexOf.call(this, val, byteOffset)
  912. }
  913. return arrayIndexOf(this, [ val ], byteOffset)
  914. }
  915. function arrayIndexOf (arr, val, byteOffset) {
  916. var foundIndex = -1
  917. for (var i = 0; byteOffset + i < arr.length; i++) {
  918. if (arr[byteOffset + i] === val[foundIndex === -1 ? 0 : i - foundIndex]) {
  919. if (foundIndex === -1) foundIndex = i
  920. if (i - foundIndex + 1 === val.length) return byteOffset + foundIndex
  921. } else {
  922. foundIndex = -1
  923. }
  924. }
  925. return -1
  926. }
  927. throw new TypeError('val must be string, number or Buffer')
  928. }
  929. // `get` will be removed in Node 0.13+
  930. Buffer.prototype.get = function get (offset) {
  931. console.log('.get() is deprecated. Access using array indexes instead.')
  932. return this.readUInt8(offset)
  933. }
  934. // `set` will be removed in Node 0.13+
  935. Buffer.prototype.set = function set (v, offset) {
  936. console.log('.set() is deprecated. Access using array indexes instead.')
  937. return this.writeUInt8(v, offset)
  938. }
  939. function hexWrite (buf, string, offset, length) {
  940. offset = Number(offset) || 0
  941. var remaining = buf.length - offset
  942. if (!length) {
  943. length = remaining
  944. } else {
  945. length = Number(length)
  946. if (length > remaining) {
  947. length = remaining
  948. }
  949. }
  950. // must be an even number of digits
  951. var strLen = string.length
  952. if (strLen % 2 !== 0) throw new Error('Invalid hex string')
  953. if (length > strLen / 2) {
  954. length = strLen / 2
  955. }
  956. for (var i = 0; i < length; i++) {
  957. var parsed = parseInt(string.substr(i * 2, 2), 16)
  958. if (isNaN(parsed)) throw new Error('Invalid hex string')
  959. buf[offset + i] = parsed
  960. }
  961. return i
  962. }
  963. function utf8Write (buf, string, offset, length) {
  964. var charsWritten = blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  965. return charsWritten
  966. }
  967. function asciiWrite (buf, string, offset, length) {
  968. var charsWritten = blitBuffer(asciiToBytes(string), buf, offset, length)
  969. return charsWritten
  970. }
  971. function binaryWrite (buf, string, offset, length) {
  972. return asciiWrite(buf, string, offset, length)
  973. }
  974. function base64Write (buf, string, offset, length) {
  975. var charsWritten = blitBuffer(base64ToBytes(string), buf, offset, length)
  976. return charsWritten
  977. }
  978. function utf16leWrite (buf, string, offset, length) {
  979. var charsWritten = blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  980. return charsWritten
  981. }
  982. Buffer.prototype.write = function write (string, offset, length, encoding) {
  983. // Support both (string, offset, length, encoding)
  984. // and the legacy (string, encoding, offset, length)
  985. if (isFinite(offset)) {
  986. if (!isFinite(length)) {
  987. encoding = length
  988. length = undefined
  989. }
  990. } else { // legacy
  991. var swap = encoding
  992. encoding = offset
  993. offset = length
  994. length = swap
  995. }
  996. offset = Number(offset) || 0
  997. if (length < 0 || offset < 0 || offset > this.length) {
  998. throw new RangeError('attempt to write outside buffer bounds')
  999. }
  1000. var remaining = this.length - offset
  1001. if (!length) {
  1002. length = remaining
  1003. } else {
  1004. length = Number(length)
  1005. if (length > remaining) {
  1006. length = remaining
  1007. }
  1008. }
  1009. encoding = String(encoding || 'utf8').toLowerCase()
  1010. var ret
  1011. switch (encoding) {
  1012. case 'hex':
  1013. ret = hexWrite(this, string, offset, length)
  1014. break
  1015. case 'utf8':
  1016. case 'utf-8':
  1017. ret = utf8Write(this, string, offset, length)
  1018. break
  1019. case 'ascii':
  1020. ret = asciiWrite(this, string, offset, length)
  1021. break
  1022. case 'binary':
  1023. ret = binaryWrite(this, string, offset, length)
  1024. break
  1025. case 'base64':
  1026. ret = base64Write(this, string, offset, length)
  1027. break
  1028. case 'ucs2':
  1029. case 'ucs-2':
  1030. case 'utf16le':
  1031. case 'utf-16le':
  1032. ret = utf16leWrite(this, string, offset, length)
  1033. break
  1034. default:
  1035. throw new TypeError('Unknown encoding: ' + encoding)
  1036. }
  1037. return ret
  1038. }
  1039. Buffer.prototype.toJSON = function toJSON () {
  1040. return {
  1041. type: 'Buffer',
  1042. data: Array.prototype.slice.call(this._arr || this, 0)
  1043. }
  1044. }
  1045. function base64Slice (buf, start, end) {
  1046. if (start === 0 && end === buf.length) {
  1047. return base64.fromByteArray(buf)
  1048. } else {
  1049. return base64.fromByteArray(buf.slice(start, end))
  1050. }
  1051. }
  1052. function utf8Slice (buf, start, end) {
  1053. var res = ''
  1054. var tmp = ''
  1055. end = Math.min(buf.length, end)
  1056. for (var i = start; i < end; i++) {
  1057. if (buf[i] <= 0x7F) {
  1058. res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i])
  1059. tmp = ''
  1060. } else {
  1061. tmp += '%' + buf[i].toString(16)
  1062. }
  1063. }
  1064. return res + decodeUtf8Char(tmp)
  1065. }
  1066. function asciiSlice (buf, start, end) {
  1067. var ret = ''
  1068. end = Math.min(buf.length, end)
  1069. for (var i = start; i < end; i++) {
  1070. ret += String.fromCharCode(buf[i] & 0x7F)
  1071. }
  1072. return ret
  1073. }
  1074. function binarySlice (buf, start, end) {
  1075. var ret = ''
  1076. end = Math.min(buf.length, end)
  1077. for (var i = start; i < end; i++) {
  1078. ret += String.fromCharCode(buf[i])
  1079. }
  1080. return ret
  1081. }
  1082. function hexSlice (buf, start, end) {
  1083. var len = buf.length
  1084. if (!start || start < 0) start = 0
  1085. if (!end || end < 0 || end > len) end = len
  1086. var out = ''
  1087. for (var i = start; i < end; i++) {
  1088. out += toHex(buf[i])
  1089. }
  1090. return out
  1091. }
  1092. function utf16leSlice (buf, start, end) {
  1093. var bytes = buf.slice(start, end)
  1094. var res = ''
  1095. for (var i = 0; i < bytes.length; i += 2) {
  1096. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
  1097. }
  1098. return res
  1099. }
  1100. Buffer.prototype.slice = function slice (start, end) {
  1101. var len = this.length
  1102. start = ~~start
  1103. end = end === undefined ? len : ~~end
  1104. if (start < 0) {
  1105. start += len
  1106. if (start < 0) start = 0
  1107. } else if (start > len) {
  1108. start = len
  1109. }
  1110. if (end < 0) {
  1111. end += len
  1112. if (end < 0) end = 0
  1113. } else if (end > len) {
  1114. end = len
  1115. }
  1116. if (end < start) end = start
  1117. var newBuf
  1118. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1119. newBuf = Buffer._augment(this.subarray(start, end))
  1120. } else {
  1121. var sliceLen = end - start
  1122. newBuf = new Buffer(sliceLen, undefined)
  1123. for (var i = 0; i < sliceLen; i++) {
  1124. newBuf[i] = this[i + start]
  1125. }
  1126. }
  1127. if (newBuf.length) newBuf.parent = this.parent || this
  1128. return newBuf
  1129. }
  1130. /*
  1131. * Need to make sure that buffer isn't trying to write out of bounds.
  1132. */
  1133. function checkOffset (offset, ext, length) {
  1134. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  1135. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  1136. }
  1137. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  1138. offset = offset >>> 0
  1139. byteLength = byteLength >>> 0
  1140. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1141. var val = this[offset]
  1142. var mul = 1
  1143. var i = 0
  1144. while (++i < byteLength && (mul *= 0x100)) {
  1145. val += this[offset + i] * mul
  1146. }
  1147. return val
  1148. }
  1149. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  1150. offset = offset >>> 0
  1151. byteLength = byteLength >>> 0
  1152. if (!noAssert) {
  1153. checkOffset(offset, byteLength, this.length)
  1154. }
  1155. var val = this[offset + --byteLength]
  1156. var mul = 1
  1157. while (byteLength > 0 && (mul *= 0x100)) {
  1158. val += this[offset + --byteLength] * mul
  1159. }
  1160. return val
  1161. }
  1162. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  1163. if (!noAssert) checkOffset(offset, 1, this.length)
  1164. return this[offset]
  1165. }
  1166. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  1167. if (!noAssert) checkOffset(offset, 2, this.length)
  1168. return this[offset] | (this[offset + 1] << 8)
  1169. }
  1170. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  1171. if (!noAssert) checkOffset(offset, 2, this.length)
  1172. return (this[offset] << 8) | this[offset + 1]
  1173. }
  1174. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  1175. if (!noAssert) checkOffset(offset, 4, this.length)
  1176. return ((this[offset]) |
  1177. (this[offset + 1] << 8) |
  1178. (this[offset + 2] << 16)) +
  1179. (this[offset + 3] * 0x1000000)
  1180. }
  1181. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  1182. if (!noAssert) checkOffset(offset, 4, this.length)
  1183. return (this[offset] * 0x1000000) +
  1184. ((this[offset + 1] << 16) |
  1185. (this[offset + 2] << 8) |
  1186. this[offset + 3])
  1187. }
  1188. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  1189. offset = offset >>> 0
  1190. byteLength = byteLength >>> 0
  1191. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1192. var val = this[offset]
  1193. var mul = 1
  1194. var i = 0
  1195. while (++i < byteLength && (mul *= 0x100)) {
  1196. val += this[offset + i] * mul
  1197. }
  1198. mul *= 0x80
  1199. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1200. return val
  1201. }
  1202. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  1203. offset = offset >>> 0
  1204. byteLength = byteLength >>> 0
  1205. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1206. var i = byteLength
  1207. var mul = 1
  1208. var val = this[offset + --i]
  1209. while (i > 0 && (mul *= 0x100)) {
  1210. val += this[offset + --i] * mul
  1211. }
  1212. mul *= 0x80
  1213. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1214. return val
  1215. }
  1216. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  1217. if (!noAssert) checkOffset(offset, 1, this.length)
  1218. if (!(this[offset] & 0x80)) return (this[offset])
  1219. return ((0xff - this[offset] + 1) * -1)
  1220. }
  1221. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  1222. if (!noAssert) checkOffset(offset, 2, this.length)
  1223. var val = this[offset] | (this[offset + 1] << 8)
  1224. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1225. }
  1226. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  1227. if (!noAssert) checkOffset(offset, 2, this.length)
  1228. var val = this[offset + 1] | (this[offset] << 8)
  1229. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1230. }
  1231. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  1232. if (!noAssert) checkOffset(offset, 4, this.length)
  1233. return (this[offset]) |
  1234. (this[offset + 1] << 8) |
  1235. (this[offset + 2] << 16) |
  1236. (this[offset + 3] << 24)
  1237. }
  1238. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  1239. if (!noAssert) checkOffset(offset, 4, this.length)
  1240. return (this[offset] << 24) |
  1241. (this[offset + 1] << 16) |
  1242. (this[offset + 2] << 8) |
  1243. (this[offset + 3])
  1244. }
  1245. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  1246. if (!noAssert) checkOffset(offset, 4, this.length)
  1247. return ieee754.read(this, offset, true, 23, 4)
  1248. }
  1249. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  1250. if (!noAssert) checkOffset(offset, 4, this.length)
  1251. return ieee754.read(this, offset, false, 23, 4)
  1252. }
  1253. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  1254. if (!noAssert) checkOffset(offset, 8, this.length)
  1255. return ieee754.read(this, offset, true, 52, 8)
  1256. }
  1257. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  1258. if (!noAssert) checkOffset(offset, 8, this.length)
  1259. return ieee754.read(this, offset, false, 52, 8)
  1260. }
  1261. function checkInt (buf, value, offset, ext, max, min) {
  1262. if (!Buffer.isBuffer(buf)) throw new TypeError('buffer must be a Buffer instance')
  1263. if (value > max || value < min) throw new RangeError('value is out of bounds')
  1264. if (offset + ext > buf.length) throw new RangeError('index out of range')
  1265. }
  1266. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  1267. value = +value
  1268. offset = offset >>> 0
  1269. byteLength = byteLength >>> 0
  1270. if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0)
  1271. var mul = 1
  1272. var i = 0
  1273. this[offset] = value & 0xFF
  1274. while (++i < byteLength && (mul *= 0x100)) {
  1275. this[offset + i] = (value / mul) >>> 0 & 0xFF
  1276. }
  1277. return offset + byteLength
  1278. }
  1279. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  1280. value = +value
  1281. offset = offset >>> 0
  1282. byteLength = byteLength >>> 0
  1283. if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0)
  1284. var i = byteLength - 1
  1285. var mul = 1
  1286. this[offset + i] = value & 0xFF
  1287. while (--i >= 0 && (mul *= 0x100)) {
  1288. this[offset + i] = (value / mul) >>> 0 & 0xFF
  1289. }
  1290. return offset + byteLength
  1291. }
  1292. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  1293. value = +value
  1294. offset = offset >>> 0
  1295. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  1296. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  1297. this[offset] = value
  1298. return offset + 1
  1299. }
  1300. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  1301. if (value < 0) value = 0xffff + value + 1
  1302. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) {
  1303. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  1304. (littleEndian ? i : 1 - i) * 8
  1305. }
  1306. }
  1307. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  1308. value = +value
  1309. offset = offset >>> 0
  1310. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1311. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1312. this[offset] = value
  1313. this[offset + 1] = (value >>> 8)
  1314. } else {
  1315. objectWriteUInt16(this, value, offset, true)
  1316. }
  1317. return offset + 2
  1318. }
  1319. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  1320. value = +value
  1321. offset = offset >>> 0
  1322. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1323. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1324. this[offset] = (value >>> 8)
  1325. this[offset + 1] = value
  1326. } else {
  1327. objectWriteUInt16(this, value, offset, false)
  1328. }
  1329. return offset + 2
  1330. }
  1331. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  1332. if (value < 0) value = 0xffffffff + value + 1
  1333. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) {
  1334. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  1335. }
  1336. }
  1337. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  1338. value = +value
  1339. offset = offset >>> 0
  1340. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1341. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1342. this[offset + 3] = (value >>> 24)
  1343. this[offset + 2] = (value >>> 16)
  1344. this[offset + 1] = (value >>> 8)
  1345. this[offset] = value
  1346. } else {
  1347. objectWriteUInt32(this, value, offset, true)
  1348. }
  1349. return offset + 4
  1350. }
  1351. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  1352. value = +value
  1353. offset = offset >>> 0
  1354. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1355. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1356. this[offset] = (value >>> 24)
  1357. this[offset + 1] = (value >>> 16)
  1358. this[offset + 2] = (value >>> 8)
  1359. this[offset + 3] = value
  1360. } else {
  1361. objectWriteUInt32(this, value, offset, false)
  1362. }
  1363. return offset + 4
  1364. }
  1365. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  1366. value = +value
  1367. offset = offset >>> 0
  1368. if (!noAssert) {
  1369. checkInt(
  1370. this, value, offset, byteLength,
  1371. Math.pow(2, 8 * byteLength - 1) - 1,
  1372. -Math.pow(2, 8 * byteLength - 1)
  1373. )
  1374. }
  1375. var i = 0
  1376. var mul = 1
  1377. var sub = value < 0 ? 1 : 0
  1378. this[offset] = value & 0xFF
  1379. while (++i < byteLength && (mul *= 0x100)) {
  1380. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1381. }
  1382. return offset + byteLength
  1383. }
  1384. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  1385. value = +value
  1386. offset = offset >>> 0
  1387. if (!noAssert) {
  1388. checkInt(
  1389. this, value, offset, byteLength,
  1390. Math.pow(2, 8 * byteLength - 1) - 1,
  1391. -Math.pow(2, 8 * byteLength - 1)
  1392. )
  1393. }
  1394. var i = byteLength - 1
  1395. var mul = 1
  1396. var sub = value < 0 ? 1 : 0
  1397. this[offset + i] = value & 0xFF
  1398. while (--i >= 0 && (mul *= 0x100)) {
  1399. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1400. }
  1401. return offset + byteLength
  1402. }
  1403. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  1404. value = +value
  1405. offset = offset >>> 0
  1406. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  1407. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  1408. if (value < 0) value = 0xff + value + 1
  1409. this[offset] = value
  1410. return offset + 1
  1411. }
  1412. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  1413. value = +value
  1414. offset = offset >>> 0
  1415. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1416. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1417. this[offset] = value
  1418. this[offset + 1] = (value >>> 8)
  1419. } else {
  1420. objectWriteUInt16(this, value, offset, true)
  1421. }
  1422. return offset + 2
  1423. }
  1424. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  1425. value = +value
  1426. offset = offset >>> 0
  1427. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1428. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1429. this[offset] = (value >>> 8)
  1430. this[offset + 1] = value
  1431. } else {
  1432. objectWriteUInt16(this, value, offset, false)
  1433. }
  1434. return offset + 2
  1435. }
  1436. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  1437. value = +value
  1438. offset = offset >>> 0
  1439. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1440. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1441. this[offset] = value
  1442. this[offset + 1] = (value >>> 8)
  1443. this[offset + 2] = (value >>> 16)
  1444. this[offset + 3] = (value >>> 24)
  1445. } else {
  1446. objectWriteUInt32(this, value, offset, true)
  1447. }
  1448. return offset + 4
  1449. }
  1450. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  1451. value = +value
  1452. offset = offset >>> 0
  1453. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1454. if (value < 0) value = 0xffffffff + value + 1
  1455. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1456. this[offset] = (value >>> 24)
  1457. this[offset + 1] = (value >>> 16)
  1458. this[offset + 2] = (value >>> 8)
  1459. this[offset + 3] = value
  1460. } else {
  1461. objectWriteUInt32(this, value, offset, false)
  1462. }
  1463. return offset + 4
  1464. }
  1465. function checkIEEE754 (buf, value, offset, ext, max, min) {
  1466. if (value > max || value < min) throw new RangeError('value is out of bounds')
  1467. if (offset + ext > buf.length) throw new RangeError('index out of range')
  1468. if (offset < 0) throw new RangeError('index out of range')
  1469. }
  1470. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  1471. if (!noAssert) {
  1472. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  1473. }
  1474. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  1475. return offset + 4
  1476. }
  1477. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  1478. return writeFloat(this, value, offset, true, noAssert)
  1479. }
  1480. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  1481. return writeFloat(this, value, offset, false, noAssert)
  1482. }
  1483. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  1484. if (!noAssert) {
  1485. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  1486. }
  1487. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  1488. return offset + 8
  1489. }
  1490. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  1491. return writeDouble(this, value, offset, true, noAssert)
  1492. }
  1493. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  1494. return writeDouble(this, value, offset, false, noAssert)
  1495. }
  1496. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  1497. Buffer.prototype.copy = function copy (target, target_start, start, end) {
  1498. if (!start) start = 0
  1499. if (!end && end !== 0) end = this.length
  1500. if (target_start >= target.length) target_start = target.length
  1501. if (!target_start) target_start = 0
  1502. if (end > 0 && end < start) end = start
  1503. // Copy 0 bytes; we're done
  1504. if (end === start) return 0
  1505. if (target.length === 0 || this.length === 0) return 0
  1506. // Fatal error conditions
  1507. if (target_start < 0) {
  1508. throw new RangeError('targetStart out of bounds')
  1509. }
  1510. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  1511. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  1512. // Are we oob?
  1513. if (end > this.length) end = this.length
  1514. if (target.length - target_start < end - start) {
  1515. end = target.length - target_start + start
  1516. }
  1517. var len = end - start
  1518. if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  1519. for (var i = 0; i < len; i++) {
  1520. target[i + target_start] = this[i + start]
  1521. }
  1522. } else {
  1523. target._set(this.subarray(start, start + len), target_start)
  1524. }
  1525. return len
  1526. }
  1527. // fill(value, start=0, end=buffer.length)
  1528. Buffer.prototype.fill = function fill (value, start, end) {
  1529. if (!value) value = 0
  1530. if (!start) start = 0
  1531. if (!end) end = this.length
  1532. if (end < start) throw new RangeError('end < start')
  1533. // Fill 0 bytes; we're done
  1534. if (end === start) return
  1535. if (this.length === 0) return
  1536. if (start < 0 || start >= this.length) throw new RangeError('start out of bounds')
  1537. if (end < 0 || end > this.length) throw new RangeError('end out of bounds')
  1538. var i
  1539. if (typeof value === 'number') {
  1540. for (i = start; i < end; i++) {
  1541. this[i] = value
  1542. }
  1543. } else {
  1544. var bytes = utf8ToBytes(value.toString())
  1545. var len = bytes.length
  1546. for (i = start; i < end; i++) {
  1547. this[i] = bytes[i % len]
  1548. }
  1549. }
  1550. return this
  1551. }
  1552. /**
  1553. * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.
  1554. * Added in Node 0.12. Only available in browsers that support ArrayBuffer.
  1555. */
  1556. Buffer.prototype.toArrayBuffer = function toArrayBuffer () {
  1557. if (typeof Uint8Array !== 'undefined') {
  1558. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1559. return (new Buffer(this)).buffer
  1560. } else {
  1561. var buf = new Uint8Array(this.length)
  1562. for (var i = 0, len = buf.length; i < len; i += 1) {
  1563. buf[i] = this[i]
  1564. }
  1565. return buf.buffer
  1566. }
  1567. } else {
  1568. throw new TypeError('Buffer.toArrayBuffer not supported in this browser')
  1569. }
  1570. }
  1571. // HELPER FUNCTIONS
  1572. // ================
  1573. var BP = Buffer.prototype
  1574. /**
  1575. * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods
  1576. */
  1577. Buffer._augment = function _augment (arr) {
  1578. arr.constructor = Buffer
  1579. arr._isBuffer = true
  1580. // save reference to original Uint8Array set method before overwriting
  1581. arr._set = arr.set
  1582. // deprecated, will be removed in node 0.13+
  1583. arr.get = BP.get
  1584. arr.set = BP.set
  1585. arr.write = BP.write
  1586. arr.toString = BP.toString
  1587. arr.toLocaleString = BP.toString
  1588. arr.toJSON = BP.toJSON
  1589. arr.equals = BP.equals
  1590. arr.compare = BP.compare
  1591. arr.indexOf = BP.indexOf
  1592. arr.copy = BP.copy
  1593. arr.slice = BP.slice
  1594. arr.readUIntLE = BP.readUIntLE
  1595. arr.readUIntBE = BP.readUIntBE
  1596. arr.readUInt8 = BP.readUInt8
  1597. arr.readUInt16LE = BP.readUInt16LE
  1598. arr.readUInt16BE = BP.readUInt16BE
  1599. arr.readUInt32LE = BP.readUInt32LE
  1600. arr.readUInt32BE = BP.readUInt32BE
  1601. arr.readIntLE = BP.readIntLE
  1602. arr.readIntBE = BP.readIntBE
  1603. arr.readInt8 = BP.readInt8
  1604. arr.readInt16LE = BP.readInt16LE
  1605. arr.readInt16BE = BP.readInt16BE
  1606. arr.readInt32LE = BP.readInt32LE
  1607. arr.readInt32BE = BP.readInt32BE
  1608. arr.readFloatLE = BP.readFloatLE
  1609. arr.readFloatBE = BP.readFloatBE
  1610. arr.readDoubleLE = BP.readDoubleLE
  1611. arr.readDoubleBE = BP.readDoubleBE
  1612. arr.writeUInt8 = BP.writeUInt8
  1613. arr.writeUIntLE = BP.writeUIntLE
  1614. arr.writeUIntBE = BP.writeUIntBE
  1615. arr.writeUInt16LE = BP.writeUInt16LE
  1616. arr.writeUInt16BE = BP.writeUInt16BE
  1617. arr.writeUInt32LE = BP.writeUInt32LE
  1618. arr.writeUInt32BE = BP.writeUInt32BE
  1619. arr.writeIntLE = BP.writeIntLE
  1620. arr.writeIntBE = BP.writeIntBE
  1621. arr.writeInt8 = BP.writeInt8
  1622. arr.writeInt16LE = BP.writeInt16LE
  1623. arr.writeInt16BE = BP.writeInt16BE
  1624. arr.writeInt32LE = BP.writeInt32LE
  1625. arr.writeInt32BE = BP.writeInt32BE
  1626. arr.writeFloatLE = BP.writeFloatLE
  1627. arr.writeFloatBE = BP.writeFloatBE
  1628. arr.writeDoubleLE = BP.writeDoubleLE
  1629. arr.writeDoubleBE = BP.writeDoubleBE
  1630. arr.fill = BP.fill
  1631. arr.inspect = BP.inspect
  1632. arr.toArrayBuffer = BP.toArrayBuffer
  1633. return arr
  1634. }
  1635. var INVALID_BASE64_RE = /[^+\/0-9A-z\-]/g
  1636. function base64clean (str) {
  1637. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  1638. str = stringtrim(str).replace(INVALID_BASE64_RE, '')
  1639. // Node converts strings with length < 2 to ''
  1640. if (str.length < 2) return ''
  1641. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  1642. while (str.length % 4 !== 0) {
  1643. str = str + '='
  1644. }
  1645. return str
  1646. }
  1647. function stringtrim (str) {
  1648. if (str.trim) return str.trim()
  1649. return str.replace(/^\s+|\s+$/g, '')
  1650. }
  1651. function isArrayish (subject) {
  1652. return isArray(subject) || Buffer.isBuffer(subject) ||
  1653. subject && typeof subject === 'object' &&
  1654. typeof subject.length === 'number'
  1655. }
  1656. function toHex (n) {
  1657. if (n < 16) return '0' + n.toString(16)
  1658. return n.toString(16)
  1659. }
  1660. function utf8ToBytes (string, units) {
  1661. units = units || Infinity
  1662. var codePoint
  1663. var length = string.length
  1664. var leadSurrogate = null
  1665. var bytes = []
  1666. var i = 0
  1667. for (; i < length; i++) {
  1668. codePoint = string.charCodeAt(i)
  1669. // is surrogate component
  1670. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  1671. // last char was a lead
  1672. if (leadSurrogate) {
  1673. // 2 leads in a row
  1674. if (codePoint < 0xDC00) {
  1675. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1676. leadSurrogate = codePoint
  1677. continue
  1678. } else {
  1679. // valid surrogate pair
  1680. codePoint = leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00 | 0x10000
  1681. leadSurrogate = null
  1682. }
  1683. } else {
  1684. // no lead yet
  1685. if (codePoint > 0xDBFF) {
  1686. // unexpected trail
  1687. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1688. continue
  1689. } else if (i + 1 === length) {
  1690. // unpaired lead
  1691. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1692. continue
  1693. } else {
  1694. // valid lead
  1695. leadSurrogate = codePoint
  1696. continue
  1697. }
  1698. }
  1699. } else if (leadSurrogate) {
  1700. // valid bmp char, but last char was a lead
  1701. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1702. leadSurrogate = null
  1703. }
  1704. // encode utf8
  1705. if (codePoint < 0x80) {
  1706. if ((units -= 1) < 0) break
  1707. bytes.push(codePoint)
  1708. } else if (codePoint < 0x800) {
  1709. if ((units -= 2) < 0) break
  1710. bytes.push(
  1711. codePoint >> 0x6 | 0xC0,
  1712. codePoint & 0x3F | 0x80
  1713. )
  1714. } else if (codePoint < 0x10000) {
  1715. if ((units -= 3) < 0) break
  1716. bytes.push(
  1717. codePoint >> 0xC | 0xE0,
  1718. codePoint >> 0x6 & 0x3F | 0x80,
  1719. codePoint & 0x3F | 0x80
  1720. )
  1721. } else if (codePoint < 0x200000) {
  1722. if ((units -= 4) < 0) break
  1723. bytes.push(
  1724. codePoint >> 0x12 | 0xF0,
  1725. codePoint >> 0xC & 0x3F | 0x80,
  1726. codePoint >> 0x6 & 0x3F | 0x80,
  1727. codePoint & 0x3F | 0x80
  1728. )
  1729. } else {
  1730. throw new Error('Invalid code point')
  1731. }
  1732. }
  1733. return bytes
  1734. }
  1735. function asciiToBytes (str) {
  1736. var byteArray = []
  1737. for (var i = 0; i < str.length; i++) {
  1738. // Node's code seems to be doing this and not & 0x7F..
  1739. byteArray.push(str.charCodeAt(i) & 0xFF)
  1740. }
  1741. return byteArray
  1742. }
  1743. function utf16leToBytes (str, units) {
  1744. var c, hi, lo
  1745. var byteArray = []
  1746. for (var i = 0; i < str.length; i++) {
  1747. if ((units -= 2) < 0) break
  1748. c = str.charCodeAt(i)
  1749. hi = c >> 8
  1750. lo = c % 256
  1751. byteArray.push(lo)
  1752. byteArray.push(hi)
  1753. }
  1754. return byteArray
  1755. }
  1756. function base64ToBytes (str) {
  1757. return base64.toByteArray(base64clean(str))
  1758. }
  1759. function blitBuffer (src, dst, offset, length) {
  1760. for (var i = 0; i < length; i++) {
  1761. if ((i + offset >= dst.length) || (i >= src.length)) break
  1762. dst[i + offset] = src[i]
  1763. }
  1764. return i
  1765. }
  1766. function decodeUtf8Char (str) {
  1767. try {
  1768. return decodeURIComponent(str)
  1769. } catch (err) {
  1770. return String.fromCharCode(0xFFFD) // UTF 8 invalid char
  1771. }
  1772. }
  1773. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(7).Buffer))
  1774. /***/ },
  1775. /* 8 */
  1776. /***/ function(module, exports, __webpack_require__) {
  1777. 'use strict';
  1778. function isBMP (buffer) {
  1779. return ('BM' === buffer.toString('ascii', 0, 2));
  1780. }
  1781. function calculate (buffer) {
  1782. return {
  1783. 'width': buffer.readUInt32LE(18),
  1784. 'height': buffer.readUInt32LE(22)
  1785. };
  1786. }
  1787. module.exports = {
  1788. 'detect': isBMP,
  1789. 'calculate': calculate
  1790. };
  1791. /***/ },
  1792. /* 9 */
  1793. /***/ function(module, exports, __webpack_require__) {
  1794. 'use strict';
  1795. var gifRegexp = /^GIF8[7,9]a/;
  1796. function isGIF (buffer) {
  1797. var signature = buffer.toString('ascii', 0, 6);
  1798. return (gifRegexp.test(signature));
  1799. }
  1800. function calculate(buffer) {
  1801. return {
  1802. 'width': buffer.readUInt16LE(6),
  1803. 'height': buffer.readUInt16LE(8)
  1804. };
  1805. }
  1806. module.exports = {
  1807. 'detect': isGIF,
  1808. 'calculate': calculate
  1809. };
  1810. /***/ },
  1811. /* 10 */
  1812. /***/ function(module, exports, __webpack_require__) {
  1813. 'use strict';
  1814. // NOTE: we only support baseline and progressive JPGs here
  1815. // due to the structure of the loader class, we only get a buffer
  1816. // with a maximum size of 4096 bytes. so if the SOF marker is outside
  1817. // if this range we can't detect the file size correctly.
  1818. // TO-DO: handle all JFIFs
  1819. var validJFIFMarkers = {
  1820. 'ffdb': '0001010101', // Samsung D807 JPEG
  1821. 'ffe0': '4a46494600', // Standard JPEG
  1822. 'ffe1': '4578696600', // Camera JPEG, with EXIF data
  1823. 'ffe2': '4943435f50', // Canon EOS-1D JPEG
  1824. 'ffe3': '', // Samsung D500 JPEG
  1825. 'ffe8': '5350494646', // SPIFF JPEG
  1826. 'ffec': '4475636b79', // Photoshop JPEG
  1827. 'ffed': '50686f746f', // Adobe JPEG, Photoshop CMYK buffer
  1828. 'ffee': '41646f6265' // Adobe JPEG, Unrecognised (Lightroom??)
  1829. };
  1830. var red = ['\x1B[31m', '\x1B[39m'];
  1831. function isJPG (buffer) { //, filepath
  1832. var SOIMarker = buffer.toString('hex', 0, 2);
  1833. var JFIFMarker = buffer.toString('hex', 2, 4);
  1834. // not a valid jpeg
  1835. if ('ffd8' !== SOIMarker) {
  1836. return false;
  1837. }
  1838. // TO-DO: validate the end-bytes of a jpeg file
  1839. // use filepath, get the last bytes, check for ffd9
  1840. var got = buffer.toString('hex', 6, 11);
  1841. var expected = JFIFMarker && validJFIFMarkers[JFIFMarker];
  1842. if (expected === '') {
  1843. console.warn(
  1844. red[0] +
  1845. 'this looks like a unrecognised jpeg\n' +
  1846. 'please report the issue here\n' +
  1847. red[1],
  1848. '\thttps://github.com/netroy/image-size/issues/new\n'
  1849. );
  1850. return false;
  1851. }
  1852. return (got === expected) || (JFIFMarker === 'ffdb');
  1853. }
  1854. function extractSize (buffer, i) {
  1855. return {
  1856. 'height' : buffer.readUInt16BE(i),
  1857. 'width' : buffer.readUInt16BE(i + 2)
  1858. };
  1859. }
  1860. function validateBuffer (buffer, i) {
  1861. // index should be within buffer limits
  1862. if (i > buffer.length) {
  1863. throw new TypeError('Corrupt JPG, exceeded buffer limits');
  1864. }
  1865. // Every JPEG block must begin with a 0xFF
  1866. if (buffer[i] !== 0xFF) {
  1867. throw new TypeError('Invalid JPG, marker table corrupted');
  1868. }
  1869. }
  1870. function calculate (buffer) {
  1871. // Skip 5 chars, they are for signature
  1872. buffer = buffer.slice(4);
  1873. var i, next;
  1874. while (buffer.length) {
  1875. // read length of the next block
  1876. i = buffer.readUInt16BE(0);
  1877. // ensure correct format
  1878. validateBuffer(buffer, i);
  1879. // 0xFFC0 is baseline(SOF)
  1880. // 0xFFC2 is progressive(SOF2)
  1881. next = buffer[i + 1];
  1882. if (next === 0xC0 || next === 0xC2) {
  1883. return extractSize(buffer, i + 5);
  1884. }
  1885. // move to the next block
  1886. buffer = buffer.slice(i + 2);
  1887. }
  1888. throw new TypeError('Invalid JPG, no size found');
  1889. }
  1890. module.exports = {
  1891. 'detect': isJPG,
  1892. 'calculate': calculate
  1893. };
  1894. /***/ },
  1895. /* 11 */
  1896. /***/ function(module, exports, __webpack_require__) {
  1897. 'use strict';
  1898. var pngSignature = 'PNG\r\n\x1a\n';
  1899. function isPNG (buffer) {
  1900. if (pngSignature === buffer.toString('ascii', 1, 8)) {
  1901. if ('IHDR' !== buffer.toString('ascii', 12, 16)) {
  1902. throw new TypeError('invalid png');
  1903. }
  1904. return true;
  1905. }
  1906. }
  1907. function calculate (buffer) {
  1908. return {
  1909. 'width': buffer.readUInt32BE(16),
  1910. 'height': buffer.readUInt32BE(20)
  1911. };
  1912. }
  1913. module.exports = {
  1914. 'detect': isPNG,
  1915. 'calculate': calculate
  1916. };
  1917. /***/ },
  1918. /* 12 */
  1919. /***/ function(module, exports, __webpack_require__) {
  1920. 'use strict';
  1921. function isPSD (buffer) {
  1922. return ('8BPS' === buffer.toString('ascii', 0, 4));
  1923. }
  1924. function calculate (buffer) {
  1925. return {
  1926. 'width': buffer.readUInt32BE(18),
  1927. 'height': buffer.readUInt32BE(14)
  1928. };
  1929. }
  1930. module.exports = {
  1931. 'detect': isPSD,
  1932. 'calculate': calculate
  1933. };
  1934. /***/ },
  1935. /* 13 */
  1936. /***/ function(module, exports, __webpack_require__) {
  1937. 'use strict';
  1938. var svgReg = /<svg[^>]+[^>]*>/;
  1939. function isSVG (buffer) {
  1940. return svgReg.test(buffer);
  1941. }
  1942. var extractorRegExps = {
  1943. 'root': /<svg [^>]+>/,
  1944. 'width': /(^|\s)width\s*=\s*"(.+?)"/i,
  1945. 'height': /(^|\s)height\s*=\s*"(.+?)"/i,
  1946. 'viewbox': /(^|\s)viewbox\s*=\s*"(.+?)"/i
  1947. };
  1948. function getRatio (viewbox) {
  1949. var ratio = 1;
  1950. if (viewbox && viewbox[2]) {
  1951. var dim = viewbox[2].split(/\s/g);
  1952. if (dim.length === 4) {
  1953. dim = dim.map(function (i) {
  1954. return parseInt(i, 10);
  1955. });
  1956. ratio = (dim[2] - dim[0]) / (dim[3] - dim[1]);
  1957. }
  1958. }
  1959. return ratio;
  1960. }
  1961. function parse (buffer) {
  1962. var body = buffer.toString().replace(/[\r\n\s]+/g, ' ');
  1963. var section = body.match(extractorRegExps.root);
  1964. var root = section && section[0];
  1965. if (root) {
  1966. var width = root.match(extractorRegExps.width);
  1967. var height = root.match(extractorRegExps.height);
  1968. var viewbox = root.match(extractorRegExps.viewbox);
  1969. var ratio = getRatio(viewbox);
  1970. return {
  1971. 'width': parseInt(width && width[2], 10) || 0,
  1972. 'height': parseInt(height && height[2], 10) || 0,
  1973. 'ratio': ratio
  1974. };
  1975. }
  1976. }
  1977. function calculate (buffer) {
  1978. var parsed = parse(buffer);
  1979. var width = parsed.width;
  1980. var height = parsed.height;
  1981. var ratio = parsed.ratio;
  1982. if (width && height) {
  1983. return { 'width': width, 'height': height };
  1984. } else {
  1985. if (width) {
  1986. return { 'width': width, 'height': Math.floor(width / ratio) };
  1987. } else if (height) {
  1988. return { 'width': Math.floor(height * ratio), 'height': height };
  1989. } else {
  1990. throw new TypeError('invalid svg');
  1991. }
  1992. }
  1993. }
  1994. module.exports = {
  1995. 'detect': isSVG,
  1996. 'calculate': calculate
  1997. };
  1998. /***/ },
  1999. /* 14 */
  2000. /***/ function(module, exports, __webpack_require__) {
  2001. /* WEBPACK VAR INJECTION */(function(Buffer) {'use strict';
  2002. // based on http://www.compix.com/fileformattif.htm
  2003. // TO-DO: support big-endian as well
  2004. var fs = __webpack_require__(16);
  2005. var readUInt = __webpack_require__(17);
  2006. function isTIFF (buffer) {
  2007. var hex4 = buffer.toString('hex', 0, 4);
  2008. return ('49492a00' === hex4 || '4d4d002a' === hex4);
  2009. }
  2010. // Read IFD (image-file-directory) into a buffer
  2011. function readIFD (buffer, filepath, isBigEndian) {
  2012. var ifdOffset = readUInt(buffer, 32, 4, isBigEndian);
  2013. // read only till the end of the file
  2014. var bufferSize = 1024;
  2015. var fileSize = fs.statSync(filepath).size;
  2016. if (ifdOffset + bufferSize > fileSize) {
  2017. bufferSize = fileSize - ifdOffset - 10;
  2018. }
  2019. // populate the buffer
  2020. var endBuffer = new Buffer(bufferSize);
  2021. var descriptor = fs.openSync(filepath, 'r');
  2022. fs.readSync(descriptor, endBuffer, 0, bufferSize, ifdOffset);
  2023. // var ifdLength = readUInt(endBuffer, 16, 0, isBigEndian);
  2024. var ifdBuffer = endBuffer.slice(2); //, 2 + 12 * ifdLength);
  2025. return ifdBuffer;
  2026. }
  2027. // TIFF values seem to be messed up on Big-Endian, this helps
  2028. function readValue (buffer, isBigEndian) {
  2029. var low = readUInt(buffer, 16, 8, isBigEndian);
  2030. var high = readUInt(buffer, 16, 10, isBigEndian);
  2031. return (high << 16) + low;
  2032. }
  2033. // move to the next tag
  2034. function nextTag (buffer) {
  2035. if (buffer.length > 24) {
  2036. return buffer.slice(12);
  2037. }
  2038. }
  2039. // Extract IFD tags from TIFF metadata
  2040. function extractTags (buffer, isBigEndian) {
  2041. var tags = {};
  2042. var code, type, length;
  2043. while (buffer && buffer.length) {
  2044. code = readUInt(buffer, 16, 0, isBigEndian);
  2045. type = readUInt(buffer, 16, 2, isBigEndian);
  2046. length = readUInt(buffer, 32, 4, isBigEndian);
  2047. // 0 means end of IFD
  2048. if (code === 0) {
  2049. break;
  2050. } else {
  2051. // 256 is width, 257 is height
  2052. // if (code === 256 || code === 257) {
  2053. if (length === 1 && type === 3) {
  2054. tags[code] = readValue(buffer, isBigEndian);
  2055. }
  2056. // move to the next tag
  2057. buffer = nextTag(buffer);
  2058. }
  2059. }
  2060. return tags;
  2061. }
  2062. // Test if the TIFF is Big Endian or Little Endian
  2063. function determineEndianness (buffer) {
  2064. var signature = buffer.toString('ascii', 0, 2);
  2065. if ('II' === signature) {
  2066. return 'LE';
  2067. } else if ('MM' === signature) {
  2068. return 'BE';
  2069. }
  2070. }
  2071. function calculate (buffer, filepath) {
  2072. if (!filepath) {
  2073. throw new TypeError('Tiff doesn\'t support buffer');
  2074. }
  2075. // Determine BE/LE
  2076. var isBigEndian = determineEndianness(buffer) === 'BE';
  2077. // read the IFD
  2078. var ifdBuffer = readIFD(buffer, filepath, isBigEndian);
  2079. // extract the tags from the IFD
  2080. var tags = extractTags(ifdBuffer, isBigEndian);
  2081. var width = tags[256];
  2082. var height = tags[257];
  2083. if (!width || !height) {
  2084. throw new TypeError('Invalid Tiff, missing tags');
  2085. }
  2086. return {
  2087. 'width': width,
  2088. 'height': height
  2089. };
  2090. }
  2091. module.exports = {
  2092. 'detect': isTIFF,
  2093. 'calculate': calculate
  2094. };
  2095. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(7).Buffer))
  2096. /***/ },
  2097. /* 15 */
  2098. /***/ function(module, exports, __webpack_require__) {
  2099. 'use strict';
  2100. // based on https://developers.google.com/speed/webp/docs/riff_container
  2101. function isWebP (buffer) {
  2102. var riffHeader = 'RIFF' === buffer.toString('ascii', 0, 4);
  2103. var webpHeader = 'WEBP' === buffer.toString('ascii', 8, 12);
  2104. var vp8Header = 'VP8' === buffer.toString('ascii', 12, 15);
  2105. return (riffHeader && webpHeader && vp8Header);
  2106. }
  2107. function calculate (buffer) {
  2108. var chunkHeader = buffer.toString('ascii', 12, 16);
  2109. buffer = buffer.slice(20, 30);
  2110. // Lossless webp stream signature
  2111. if (chunkHeader === 'VP8 ' && buffer[0] !== 0x2f) {
  2112. return calculateLossy(buffer);
  2113. }
  2114. // Lossy webp stream signature
  2115. var signature = buffer.toString('hex', 3, 6);
  2116. if (chunkHeader === 'VP8L' && signature !== '9d012a') {
  2117. return calculateLossless(buffer);
  2118. }
  2119. return false;
  2120. }
  2121. function calculateLossless (buffer) {
  2122. return {
  2123. 'width': 1 + (((buffer[2] & 0x3F) << 8) | buffer[1]),
  2124. 'height': 1 + (((buffer[4] & 0xF) << 10) | (buffer[3] << 2) |
  2125. ((buffer[2] & 0xC0) >> 6))
  2126. };
  2127. }
  2128. function calculateLossy (buffer) {
  2129. // `& 0x3fff` returns the last 14 bits
  2130. // TO-DO: include webp scaling in the calculations
  2131. return {
  2132. 'width': buffer.readInt16LE(6) & 0x3fff,
  2133. 'height': buffer.readInt16LE(8) & 0x3fff
  2134. };
  2135. }
  2136. module.exports = {
  2137. 'detect': isWebP,
  2138. 'calculate': calculate
  2139. };
  2140. /***/ },
  2141. /* 16 */
  2142. /***/ function(module, exports, __webpack_require__) {
  2143. /***/ },
  2144. /* 17 */
  2145. /***/ function(module, exports, __webpack_require__) {
  2146. 'use strict';
  2147. module.exports = function(buffer, bits, offset, isBigEndian) {
  2148. offset = offset || 0;
  2149. var endian = !!isBigEndian ? 'BE' : 'LE';
  2150. var method = buffer['readUInt' + bits + endian];
  2151. return method.call(buffer, offset);
  2152. }
  2153. /***/ },
  2154. /* 18 */
  2155. /***/ function(module, exports, __webpack_require__) {
  2156. // shim for using process in browser
  2157. var process = module.exports = {};
  2158. var queue = [];
  2159. var draining = false;
  2160. function drainQueue() {
  2161. if (draining) {
  2162. return;
  2163. }
  2164. draining = true;
  2165. var currentQueue;
  2166. var len = queue.length;
  2167. while(len) {
  2168. currentQueue = queue;
  2169. queue = [];
  2170. var i = -1;
  2171. while (++i < len) {
  2172. currentQueue[i]();
  2173. }
  2174. len = queue.length;
  2175. }
  2176. draining = false;
  2177. }
  2178. process.nextTick = function (fun) {
  2179. queue.push(fun);
  2180. if (!draining) {
  2181. setTimeout(drainQueue, 0);
  2182. }
  2183. };
  2184. process.title = 'browser';
  2185. process.browser = true;
  2186. process.env = {};
  2187. process.argv = [];
  2188. process.version = ''; // empty string to avoid regexp issues
  2189. process.versions = {};
  2190. function noop() {}
  2191. process.on = noop;
  2192. process.addListener = noop;
  2193. process.once = noop;
  2194. process.off = noop;
  2195. process.removeListener = noop;
  2196. process.removeAllListeners = noop;
  2197. process.emit = noop;
  2198. process.binding = function (name) {
  2199. throw new Error('process.binding is not supported');
  2200. };
  2201. // TODO(shtylman)
  2202. process.cwd = function () { return '/' };
  2203. process.chdir = function (dir) {
  2204. throw new Error('process.chdir is not supported');
  2205. };
  2206. process.umask = function() { return 0; };
  2207. /***/ },
  2208. /* 19 */
  2209. /***/ function(module, exports, __webpack_require__) {
  2210. exports.read = function(buffer, offset, isLE, mLen, nBytes) {
  2211. var e, m,
  2212. eLen = nBytes * 8 - mLen - 1,
  2213. eMax = (1 << eLen) - 1,
  2214. eBias = eMax >> 1,
  2215. nBits = -7,
  2216. i = isLE ? (nBytes - 1) : 0,
  2217. d = isLE ? -1 : 1,
  2218. s = buffer[offset + i];
  2219. i += d;
  2220. e = s & ((1 << (-nBits)) - 1);
  2221. s >>= (-nBits);
  2222. nBits += eLen;
  2223. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
  2224. m = e & ((1 << (-nBits)) - 1);
  2225. e >>= (-nBits);
  2226. nBits += mLen;
  2227. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
  2228. if (e === 0) {
  2229. e = 1 - eBias;
  2230. } else if (e === eMax) {
  2231. return m ? NaN : ((s ? -1 : 1) * Infinity);
  2232. } else {
  2233. m = m + Math.pow(2, mLen);
  2234. e = e - eBias;
  2235. }
  2236. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  2237. };
  2238. exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
  2239. var e, m, c,
  2240. eLen = nBytes * 8 - mLen - 1,
  2241. eMax = (1 << eLen) - 1,
  2242. eBias = eMax >> 1,
  2243. rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
  2244. i = isLE ? 0 : (nBytes - 1),
  2245. d = isLE ? 1 : -1,
  2246. s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
  2247. value = Math.abs(value);
  2248. if (isNaN(value) || value === Infinity) {
  2249. m = isNaN(value) ? 1 : 0;
  2250. e = eMax;
  2251. } else {
  2252. e = Math.floor(Math.log(value) / Math.LN2);
  2253. if (value * (c = Math.pow(2, -e)) < 1) {
  2254. e--;
  2255. c *= 2;
  2256. }
  2257. if (e + eBias >= 1) {
  2258. value += rt / c;
  2259. } else {
  2260. value += rt * Math.pow(2, 1 - eBias);
  2261. }
  2262. if (value * c >= 2) {
  2263. e++;
  2264. c /= 2;
  2265. }
  2266. if (e + eBias >= eMax) {
  2267. m = 0;
  2268. e = eMax;
  2269. } else if (e + eBias >= 1) {
  2270. m = (value * c - 1) * Math.pow(2, mLen);
  2271. e = e + eBias;
  2272. } else {
  2273. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  2274. e = 0;
  2275. }
  2276. }
  2277. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
  2278. e = (e << mLen) | m;
  2279. eLen += mLen;
  2280. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);
  2281. buffer[offset + i - d] |= s * 128;
  2282. };
  2283. /***/ },
  2284. /* 20 */
  2285. /***/ function(module, exports, __webpack_require__) {
  2286. /**
  2287. * isArray
  2288. */
  2289. var isArray = Array.isArray;
  2290. /**
  2291. * toString
  2292. */
  2293. var str = Object.prototype.toString;
  2294. /**
  2295. * Whether or not the given `val`
  2296. * is an array.
  2297. *
  2298. * example:
  2299. *
  2300. * isArray([]);
  2301. * // > true
  2302. * isArray(arguments);
  2303. * // > false
  2304. * isArray('');
  2305. * // > false
  2306. *
  2307. * @param {mixed} val
  2308. * @return {bool}
  2309. */
  2310. module.exports = isArray || function (val) {
  2311. return !! val && '[object Array]' == str.call(val);
  2312. };
  2313. /***/ },
  2314. /* 21 */
  2315. /***/ function(module, exports, __webpack_require__) {
  2316. var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  2317. ;(function (exports) {
  2318. 'use strict';
  2319. var Arr = (typeof Uint8Array !== 'undefined')
  2320. ? Uint8Array
  2321. : Array
  2322. var PLUS = '+'.charCodeAt(0)
  2323. var SLASH = '/'.charCodeAt(0)
  2324. var NUMBER = '0'.charCodeAt(0)
  2325. var LOWER = 'a'.charCodeAt(0)
  2326. var UPPER = 'A'.charCodeAt(0)
  2327. var PLUS_URL_SAFE = '-'.charCodeAt(0)
  2328. var SLASH_URL_SAFE = '_'.charCodeAt(0)
  2329. function decode (elt) {
  2330. var code = elt.charCodeAt(0)
  2331. if (code === PLUS ||
  2332. code === PLUS_URL_SAFE)
  2333. return 62 // '+'
  2334. if (code === SLASH ||
  2335. code === SLASH_URL_SAFE)
  2336. return 63 // '/'
  2337. if (code < NUMBER)
  2338. return -1 //no match
  2339. if (code < NUMBER + 10)
  2340. return code - NUMBER + 26 + 26
  2341. if (code < UPPER + 26)
  2342. return code - UPPER
  2343. if (code < LOWER + 26)
  2344. return code - LOWER + 26
  2345. }
  2346. function b64ToByteArray (b64) {
  2347. var i, j, l, tmp, placeHolders, arr
  2348. if (b64.length % 4 > 0) {
  2349. throw new Error('Invalid string. Length must be a multiple of 4')
  2350. }
  2351. // the number of equal signs (place holders)
  2352. // if there are two placeholders, than the two characters before it
  2353. // represent one byte
  2354. // if there is only one, then the three characters before it represent 2 bytes
  2355. // this is just a cheap hack to not do indexOf twice
  2356. var len = b64.length
  2357. placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0
  2358. // base64 is 4/3 + up to two characters of the original data
  2359. arr = new Arr(b64.length * 3 / 4 - placeHolders)
  2360. // if there are placeholders, only get up to the last complete 4 chars
  2361. l = placeHolders > 0 ? b64.length - 4 : b64.length
  2362. var L = 0
  2363. function push (v) {
  2364. arr[L++] = v
  2365. }
  2366. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  2367. tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))
  2368. push((tmp & 0xFF0000) >> 16)
  2369. push((tmp & 0xFF00) >> 8)
  2370. push(tmp & 0xFF)
  2371. }
  2372. if (placeHolders === 2) {
  2373. tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)
  2374. push(tmp & 0xFF)
  2375. } else if (placeHolders === 1) {
  2376. tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)
  2377. push((tmp >> 8) & 0xFF)
  2378. push(tmp & 0xFF)
  2379. }
  2380. return arr
  2381. }
  2382. function uint8ToBase64 (uint8) {
  2383. var i,
  2384. extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
  2385. output = "",
  2386. temp, length
  2387. function encode (num) {
  2388. return lookup.charAt(num)
  2389. }
  2390. function tripletToBase64 (num) {
  2391. return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)
  2392. }
  2393. // go through the array every three bytes, we'll deal with trailing stuff later
  2394. for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
  2395. temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
  2396. output += tripletToBase64(temp)
  2397. }
  2398. // pad the end with zeros, but make sure to not forget the extra bytes
  2399. switch (extraBytes) {
  2400. case 1:
  2401. temp = uint8[uint8.length - 1]
  2402. output += encode(temp >> 2)
  2403. output += encode((temp << 4) & 0x3F)
  2404. output += '=='
  2405. break
  2406. case 2:
  2407. temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])
  2408. output += encode(temp >> 10)
  2409. output += encode((temp >> 4) & 0x3F)
  2410. output += encode((temp << 2) & 0x3F)
  2411. output += '='
  2412. break
  2413. }
  2414. return output
  2415. }
  2416. exports.toByteArray = b64ToByteArray
  2417. exports.fromByteArray = uint8ToBase64
  2418. }(false ? (this.base64js = {}) : exports))
  2419. /***/ }
  2420. /******/ ])
  2421. });
  2422. ;