netcdfjs.js 98 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923
  1. /**
  2. * netcdfjs - Read and explore NetCDF files
  3. * @version v0.7.0
  4. * @link https://github.com/cheminfo-js/netcdfjs
  5. * @license MIT
  6. */
  7. (function webpackUniversalModuleDefinition(root, factory) {
  8. if(typeof exports === 'object' && typeof module === 'object')
  9. module.exports = factory();
  10. else if(typeof define === 'function' && define.amd)
  11. define([], factory);
  12. else if(typeof exports === 'object')
  13. exports["netcdfjs"] = factory();
  14. else
  15. root["netcdfjs"] = factory();
  16. })(typeof self !== 'undefined' ? self : this, function() {
  17. return /******/ (function(modules) { // webpackBootstrap
  18. /******/ // The module cache
  19. /******/ var installedModules = {};
  20. /******/
  21. /******/ // The require function
  22. /******/ function __webpack_require__(moduleId) {
  23. /******/
  24. /******/ // Check if module is in cache
  25. /******/ if(installedModules[moduleId]) {
  26. /******/ return installedModules[moduleId].exports;
  27. /******/ }
  28. /******/ // Create a new module (and put it into the cache)
  29. /******/ var module = installedModules[moduleId] = {
  30. /******/ i: moduleId,
  31. /******/ l: false,
  32. /******/ exports: {}
  33. /******/ };
  34. /******/
  35. /******/ // Execute the module function
  36. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  37. /******/
  38. /******/ // Flag the module as loaded
  39. /******/ module.l = true;
  40. /******/
  41. /******/ // Return the exports of the module
  42. /******/ return module.exports;
  43. /******/ }
  44. /******/
  45. /******/
  46. /******/ // expose the modules object (__webpack_modules__)
  47. /******/ __webpack_require__.m = modules;
  48. /******/
  49. /******/ // expose the module cache
  50. /******/ __webpack_require__.c = installedModules;
  51. /******/
  52. /******/ // define getter function for harmony exports
  53. /******/ __webpack_require__.d = function(exports, name, getter) {
  54. /******/ if(!__webpack_require__.o(exports, name)) {
  55. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  56. /******/ }
  57. /******/ };
  58. /******/
  59. /******/ // define __esModule on exports
  60. /******/ __webpack_require__.r = function(exports) {
  61. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  62. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  63. /******/ }
  64. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  65. /******/ };
  66. /******/
  67. /******/ // create a fake namespace object
  68. /******/ // mode & 1: value is a module id, require it
  69. /******/ // mode & 2: merge all properties of value into the ns
  70. /******/ // mode & 4: return value when already ns object
  71. /******/ // mode & 8|1: behave like require
  72. /******/ __webpack_require__.t = function(value, mode) {
  73. /******/ if(mode & 1) value = __webpack_require__(value);
  74. /******/ if(mode & 8) return value;
  75. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  76. /******/ var ns = Object.create(null);
  77. /******/ __webpack_require__.r(ns);
  78. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  79. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  80. /******/ return ns;
  81. /******/ };
  82. /******/
  83. /******/ // getDefaultExport function for compatibility with non-harmony modules
  84. /******/ __webpack_require__.n = function(module) {
  85. /******/ var getter = module && module.__esModule ?
  86. /******/ function getDefault() { return module['default']; } :
  87. /******/ function getModuleExports() { return module; };
  88. /******/ __webpack_require__.d(getter, 'a', getter);
  89. /******/ return getter;
  90. /******/ };
  91. /******/
  92. /******/ // Object.prototype.hasOwnProperty.call
  93. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  94. /******/
  95. /******/ // __webpack_public_path__
  96. /******/ __webpack_require__.p = "";
  97. /******/
  98. /******/
  99. /******/ // Load entry module and return exports
  100. /******/ return __webpack_require__(__webpack_require__.s = 3);
  101. /******/ })
  102. /************************************************************************/
  103. /******/ ([
  104. /* 0 */
  105. /***/ (function(module, exports, __webpack_require__) {
  106. "use strict";
  107. /**
  108. * Throws a non-valid NetCDF exception if the statement it's true
  109. * @ignore
  110. * @param {boolean} statement - Throws if true
  111. * @param {string} reason - Reason to throw
  112. */
  113. function notNetcdf(statement, reason) {
  114. if (statement) {
  115. throw new TypeError(`Not a valid NetCDF v3.x file: ${reason}`);
  116. }
  117. }
  118. /**
  119. * Moves 1, 2, or 3 bytes to next 4-byte boundary
  120. * @ignore
  121. * @param {IOBuffer} buffer - Buffer for the file data
  122. */
  123. function padding(buffer) {
  124. if (buffer.offset % 4 !== 0) {
  125. buffer.skip(4 - buffer.offset % 4);
  126. }
  127. }
  128. /**
  129. * Reads the name
  130. * @ignore
  131. * @param {IOBuffer} buffer - Buffer for the file data
  132. * @return {string} - Name
  133. */
  134. function readName(buffer) {
  135. // Read name
  136. var nameLength = buffer.readUint32();
  137. var name = buffer.readChars(nameLength); // validate name
  138. // TODO
  139. // Apply padding
  140. padding(buffer);
  141. return name;
  142. }
  143. module.exports.notNetcdf = notNetcdf;
  144. module.exports.padding = padding;
  145. module.exports.readName = readName;
  146. /***/ }),
  147. /* 1 */
  148. /***/ (function(module, exports) {
  149. var g; // This works in non-strict mode
  150. g = function () {
  151. return this;
  152. }();
  153. try {
  154. // This works if eval is allowed (see CSP)
  155. g = g || Function("return this")() || (1, eval)("this");
  156. } catch (e) {
  157. // This works if the window reference is available
  158. if (typeof window === "object") g = window;
  159. } // g can still be undefined, but nothing to do about it...
  160. // We return undefined, instead of nothing here, so it's
  161. // easier to handle this case. if(!global) { ...}
  162. module.exports = g;
  163. /***/ }),
  164. /* 2 */
  165. /***/ (function(module, exports, __webpack_require__) {
  166. "use strict";
  167. const notNetcdf = __webpack_require__(0).notNetcdf;
  168. const types = {
  169. BYTE: 1,
  170. CHAR: 2,
  171. SHORT: 3,
  172. INT: 4,
  173. FLOAT: 5,
  174. DOUBLE: 6
  175. };
  176. /**
  177. * Parse a number into their respective type
  178. * @ignore
  179. * @param {number} type - integer that represents the type
  180. * @return {string} - parsed value of the type
  181. */
  182. function num2str(type) {
  183. switch (Number(type)) {
  184. case types.BYTE:
  185. return 'byte';
  186. case types.CHAR:
  187. return 'char';
  188. case types.SHORT:
  189. return 'short';
  190. case types.INT:
  191. return 'int';
  192. case types.FLOAT:
  193. return 'float';
  194. case types.DOUBLE:
  195. return 'double';
  196. /* istanbul ignore next */
  197. default:
  198. return 'undefined';
  199. }
  200. }
  201. /**
  202. * Parse a number type identifier to his size in bytes
  203. * @ignore
  204. * @param {number} type - integer that represents the type
  205. * @return {number} -size of the type
  206. */
  207. function num2bytes(type) {
  208. switch (Number(type)) {
  209. case types.BYTE:
  210. return 1;
  211. case types.CHAR:
  212. return 1;
  213. case types.SHORT:
  214. return 2;
  215. case types.INT:
  216. return 4;
  217. case types.FLOAT:
  218. return 4;
  219. case types.DOUBLE:
  220. return 8;
  221. /* istanbul ignore next */
  222. default:
  223. return -1;
  224. }
  225. }
  226. /**
  227. * Reverse search of num2str
  228. * @ignore
  229. * @param {string} type - string that represents the type
  230. * @return {number} - parsed value of the type
  231. */
  232. function str2num(type) {
  233. switch (String(type)) {
  234. case 'byte':
  235. return types.BYTE;
  236. case 'char':
  237. return types.CHAR;
  238. case 'short':
  239. return types.SHORT;
  240. case 'int':
  241. return types.INT;
  242. case 'float':
  243. return types.FLOAT;
  244. case 'double':
  245. return types.DOUBLE;
  246. /* istanbul ignore next */
  247. default:
  248. return -1;
  249. }
  250. }
  251. /**
  252. * Auxiliary function to read numeric data
  253. * @ignore
  254. * @param {number} size - Size of the element to read
  255. * @param {function} bufferReader - Function to read next value
  256. * @return {Array<number>|number}
  257. */
  258. function readNumber(size, bufferReader) {
  259. if (size !== 1) {
  260. var numbers = new Array(size);
  261. for (var i = 0; i < size; i++) {
  262. numbers[i] = bufferReader();
  263. }
  264. return numbers;
  265. } else {
  266. return bufferReader();
  267. }
  268. }
  269. /**
  270. * Given a type and a size reads the next element
  271. * @ignore
  272. * @param {IOBuffer} buffer - Buffer for the file data
  273. * @param {number} type - Type of the data to read
  274. * @param {number} size - Size of the element to read
  275. * @return {string|Array<number>|number}
  276. */
  277. function readType(buffer, type, size) {
  278. switch (type) {
  279. case types.BYTE:
  280. return buffer.readBytes(size);
  281. case types.CHAR:
  282. return trimNull(buffer.readChars(size));
  283. case types.SHORT:
  284. return readNumber(size, buffer.readInt16.bind(buffer));
  285. case types.INT:
  286. return readNumber(size, buffer.readInt32.bind(buffer));
  287. case types.FLOAT:
  288. return readNumber(size, buffer.readFloat32.bind(buffer));
  289. case types.DOUBLE:
  290. return readNumber(size, buffer.readFloat64.bind(buffer));
  291. /* istanbul ignore next */
  292. default:
  293. notNetcdf(true, `non valid type ${type}`);
  294. return undefined;
  295. }
  296. }
  297. /**
  298. * Removes null terminate value
  299. * @ignore
  300. * @param {string} value - String to trim
  301. * @return {string} - Trimmed string
  302. */
  303. function trimNull(value) {
  304. if (value.charCodeAt(value.length - 1) === 0) {
  305. return value.substring(0, value.length - 1);
  306. }
  307. return value;
  308. }
  309. module.exports = types;
  310. module.exports.num2str = num2str;
  311. module.exports.num2bytes = num2bytes;
  312. module.exports.str2num = str2num;
  313. module.exports.readType = readType;
  314. /***/ }),
  315. /* 3 */
  316. /***/ (function(module, exports, __webpack_require__) {
  317. "use strict";
  318. const IOBuffer = __webpack_require__(4);
  319. const utils = __webpack_require__(0);
  320. const data = __webpack_require__(11);
  321. const readHeader = __webpack_require__(12);
  322. const toString = __webpack_require__(13);
  323. /**
  324. * Reads a NetCDF v3.x file
  325. * https://www.unidata.ucar.edu/software/netcdf/docs/file_format_specifications.html
  326. * @param {ArrayBuffer} data - ArrayBuffer or any Typed Array (including Node.js' Buffer from v4) with the data
  327. * @constructor
  328. */
  329. class NetCDFReader {
  330. constructor(data) {
  331. const buffer = new IOBuffer(data);
  332. buffer.setBigEndian(); // Validate that it's a NetCDF file
  333. utils.notNetcdf(buffer.readChars(3) !== 'CDF', 'should start with CDF'); // Check the NetCDF format
  334. const version = buffer.readByte();
  335. utils.notNetcdf(version > 2, 'unknown version'); // Read the header
  336. this.header = readHeader(buffer, version);
  337. this.buffer = buffer;
  338. }
  339. /**
  340. * @return {string} - Version for the NetCDF format
  341. */
  342. get version() {
  343. if (this.header.version === 1) {
  344. return 'classic format';
  345. } else {
  346. return '64-bit offset format';
  347. }
  348. }
  349. /**
  350. * @return {object} - Metadata for the record dimension
  351. * * `length`: Number of elements in the record dimension
  352. * * `id`: Id number in the list of dimensions for the record dimension
  353. * * `name`: String with the name of the record dimension
  354. * * `recordStep`: Number with the record variables step size
  355. */
  356. get recordDimension() {
  357. return this.header.recordDimension;
  358. }
  359. /**
  360. * @return {Array<object>} - List of dimensions with:
  361. * * `name`: String with the name of the dimension
  362. * * `size`: Number with the size of the dimension
  363. */
  364. get dimensions() {
  365. return this.header.dimensions;
  366. }
  367. /**
  368. * @return {Array<object>} - List of global attributes with:
  369. * * `name`: String with the name of the attribute
  370. * * `type`: String with the type of the attribute
  371. * * `value`: A number or string with the value of the attribute
  372. */
  373. get globalAttributes() {
  374. return this.header.globalAttributes;
  375. }
  376. /**
  377. * Returns the value of an attribute
  378. * @param {string} attributeName
  379. * @return {string} Value of the attributeName or undefined
  380. */
  381. getAttribute(attributeName) {
  382. let attribute = this.globalAttributes.find(val => val.name === attributeName);
  383. if (attribute) return attribute.value.trim();
  384. return undefined;
  385. }
  386. /**
  387. * Returns the value of a variable as a string
  388. * @param {string} variableName
  389. * @return {string} Value of the variable as a string or undefined
  390. */
  391. getDataVariableAsString(variableName) {
  392. try {
  393. return this.getDataVariable(variableName).join('').trim();
  394. } catch (e) {
  395. return undefined;
  396. }
  397. }
  398. /**
  399. * @return {Array<object>} - List of variables with:
  400. * * `name`: String with the name of the variable
  401. * * `dimensions`: Array with the dimension IDs of the variable
  402. * * `attributes`: Array with the attributes of the variable
  403. * * `type`: String with the type of the variable
  404. * * `size`: Number with the size of the variable
  405. * * `offset`: Number with the offset where of the variable begins
  406. * * `record`: True if is a record variable, false otherwise
  407. */
  408. get variables() {
  409. return this.header.variables;
  410. }
  411. toString() {
  412. return toString.call(this);
  413. }
  414. /**
  415. * Retrieves the data for a given variable
  416. * @param {string|object} variableName - Name of the variable to search or variable object
  417. * @return {Array} - List with the variable values
  418. */
  419. getDataVariable(variableName) {
  420. var variable;
  421. if (typeof variableName === 'string') {
  422. // search the variable
  423. variable = this.header.variables.find(function (val) {
  424. return val.name === variableName;
  425. });
  426. } else {
  427. variable = variableName;
  428. } // throws if variable not found
  429. utils.notNetcdf(variable === undefined, `variable not found: ${variableName}`); // go to the offset position
  430. this.buffer.seek(variable.offset);
  431. if (variable.record) {
  432. // record variable case
  433. return data.record(this.buffer, variable, this.header.recordDimension);
  434. } else {
  435. // non-record variable case
  436. return data.nonRecord(this.buffer, variable);
  437. }
  438. }
  439. /**
  440. * Check if a dataVariable exists
  441. * @param {string} variableName - Name of the variable to find
  442. * @return {boolean}
  443. */
  444. dataVariableExists(variableName) {
  445. let variable = this.header.variables.find(function (val) {
  446. return val.name === variableName;
  447. });
  448. return variable !== undefined;
  449. }
  450. /**
  451. * Check if an attribute exists
  452. * @param {string} attributeName - Name of the attribute to find
  453. * @return {boolean}
  454. */
  455. attributeExists(attributeName) {
  456. let attribute = this.globalAttributes.find(val => val.name === attributeName);
  457. return attribute !== undefined;
  458. }
  459. }
  460. module.exports = NetCDFReader;
  461. /***/ }),
  462. /* 4 */
  463. /***/ (function(module, exports, __webpack_require__) {
  464. "use strict";
  465. /* WEBPACK VAR INJECTION */(function(Buffer) {
  466. const utf8 = __webpack_require__(9);
  467. const defaultByteLength = 1024 * 8;
  468. const charArray = [];
  469. /**
  470. * IOBuffer
  471. * @constructor
  472. * @param {undefined|number|ArrayBuffer|TypedArray|IOBuffer|Buffer} data - The data to construct the IOBuffer with.
  473. *
  474. * If it's a number, it will initialize the buffer with the number as the buffer's length<br>
  475. * If it's undefined, it will initialize the buffer with a default length of 8 Kb<br>
  476. * If its an ArrayBuffer, a TypedArray, an IOBuffer instance,
  477. * or a Node.js Buffer, it will create a view over the underlying ArrayBuffer.
  478. * @param {object} [options]
  479. * @param {number} [options.offset=0] - Ignore the first n bytes of the ArrayBuffer
  480. * @property {ArrayBuffer} buffer - Reference to the internal ArrayBuffer object
  481. * @property {number} length - Byte length of the internal ArrayBuffer
  482. * @property {number} offset - The current offset of the buffer's pointer
  483. * @property {number} byteLength - Byte length of the internal ArrayBuffer
  484. * @property {number} byteOffset - Byte offset of the internal ArrayBuffer
  485. */
  486. class IOBuffer {
  487. constructor(data, options) {
  488. options = options || {};
  489. var dataIsGiven = false;
  490. if (data === undefined) {
  491. data = defaultByteLength;
  492. }
  493. if (typeof data === 'number') {
  494. data = new ArrayBuffer(data);
  495. } else {
  496. dataIsGiven = true;
  497. this._lastWrittenByte = data.byteLength;
  498. }
  499. const offset = options.offset ? options.offset >>> 0 : 0;
  500. let byteLength = data.byteLength - offset;
  501. let dvOffset = offset;
  502. if (data.buffer) {
  503. if (data.byteLength !== data.buffer.byteLength) {
  504. dvOffset = data.byteOffset + offset;
  505. }
  506. data = data.buffer;
  507. }
  508. if (dataIsGiven) {
  509. this._lastWrittenByte = byteLength;
  510. } else {
  511. this._lastWrittenByte = 0;
  512. }
  513. this.buffer = data;
  514. this.length = byteLength;
  515. this.byteLength = byteLength;
  516. this.byteOffset = dvOffset;
  517. this.offset = 0;
  518. this.littleEndian = true;
  519. this._data = new DataView(this.buffer, dvOffset, byteLength);
  520. this._mark = 0;
  521. this._marks = [];
  522. }
  523. /**
  524. * Checks if the memory allocated to the buffer is sufficient to store more bytes after the offset
  525. * @param {number} [byteLength=1] The needed memory in bytes
  526. * @return {boolean} Returns true if there is sufficient space and false otherwise
  527. */
  528. available(byteLength) {
  529. if (byteLength === undefined) byteLength = 1;
  530. return this.offset + byteLength <= this.length;
  531. }
  532. /**
  533. * Check if little-endian mode is used for reading and writing multi-byte values
  534. * @return {boolean} Returns true if little-endian mode is used, false otherwise
  535. */
  536. isLittleEndian() {
  537. return this.littleEndian;
  538. }
  539. /**
  540. * Set little-endian mode for reading and writing multi-byte values
  541. * @return {IOBuffer}
  542. */
  543. setLittleEndian() {
  544. this.littleEndian = true;
  545. return this;
  546. }
  547. /**
  548. * Check if big-endian mode is used for reading and writing multi-byte values
  549. * @return {boolean} Returns true if big-endian mode is used, false otherwise
  550. */
  551. isBigEndian() {
  552. return !this.littleEndian;
  553. }
  554. /**
  555. * Switches to big-endian mode for reading and writing multi-byte values
  556. * @return {IOBuffer}
  557. */
  558. setBigEndian() {
  559. this.littleEndian = false;
  560. return this;
  561. }
  562. /**
  563. * Move the pointer n bytes forward
  564. * @param {number} n
  565. * @return {IOBuffer}
  566. */
  567. skip(n) {
  568. if (n === undefined) n = 1;
  569. this.offset += n;
  570. return this;
  571. }
  572. /**
  573. * Move the pointer to the given offset
  574. * @param {number} offset
  575. * @return {IOBuffer}
  576. */
  577. seek(offset) {
  578. this.offset = offset;
  579. return this;
  580. }
  581. /**
  582. * Store the current pointer offset.
  583. * @see {@link IOBuffer#reset}
  584. * @return {IOBuffer}
  585. */
  586. mark() {
  587. this._mark = this.offset;
  588. return this;
  589. }
  590. /**
  591. * Move the pointer back to the last pointer offset set by mark
  592. * @see {@link IOBuffer#mark}
  593. * @return {IOBuffer}
  594. */
  595. reset() {
  596. this.offset = this._mark;
  597. return this;
  598. }
  599. /**
  600. * Push the current pointer offset to the mark stack
  601. * @see {@link IOBuffer#popMark}
  602. * @return {IOBuffer}
  603. */
  604. pushMark() {
  605. this._marks.push(this.offset);
  606. return this;
  607. }
  608. /**
  609. * Pop the last pointer offset from the mark stack, and set the current pointer offset to the popped value
  610. * @see {@link IOBuffer#pushMark}
  611. * @return {IOBuffer}
  612. */
  613. popMark() {
  614. const offset = this._marks.pop();
  615. if (offset === undefined) throw new Error('Mark stack empty');
  616. this.seek(offset);
  617. return this;
  618. }
  619. /**
  620. * Move the pointer offset back to 0
  621. * @return {IOBuffer}
  622. */
  623. rewind() {
  624. this.offset = 0;
  625. return this;
  626. }
  627. /**
  628. * Make sure the buffer has sufficient memory to write a given byteLength at the current pointer offset
  629. * If the buffer's memory is insufficient, this method will create a new buffer (a copy) with a length
  630. * that is twice (byteLength + current offset)
  631. * @param {number} [byteLength = 1]
  632. * @return {IOBuffer}
  633. */
  634. ensureAvailable(byteLength) {
  635. if (byteLength === undefined) byteLength = 1;
  636. if (!this.available(byteLength)) {
  637. const lengthNeeded = this.offset + byteLength;
  638. const newLength = lengthNeeded * 2;
  639. const newArray = new Uint8Array(newLength);
  640. newArray.set(new Uint8Array(this.buffer));
  641. this.buffer = newArray.buffer;
  642. this.length = this.byteLength = newLength;
  643. this._data = new DataView(this.buffer);
  644. }
  645. return this;
  646. }
  647. /**
  648. * Read a byte and return false if the byte's value is 0, or true otherwise
  649. * Moves pointer forward
  650. * @return {boolean}
  651. */
  652. readBoolean() {
  653. return this.readUint8() !== 0;
  654. }
  655. /**
  656. * Read a signed 8-bit integer and move pointer forward
  657. * @return {number}
  658. */
  659. readInt8() {
  660. return this._data.getInt8(this.offset++);
  661. }
  662. /**
  663. * Read an unsigned 8-bit integer and move pointer forward
  664. * @return {number}
  665. */
  666. readUint8() {
  667. return this._data.getUint8(this.offset++);
  668. }
  669. /**
  670. * Alias for {@link IOBuffer#readUint8}
  671. * @return {number}
  672. */
  673. readByte() {
  674. return this.readUint8();
  675. }
  676. /**
  677. * Read n bytes and move pointer forward.
  678. * @param {number} n
  679. * @return {Uint8Array}
  680. */
  681. readBytes(n) {
  682. if (n === undefined) n = 1;
  683. var bytes = new Uint8Array(n);
  684. for (var i = 0; i < n; i++) {
  685. bytes[i] = this.readByte();
  686. }
  687. return bytes;
  688. }
  689. /**
  690. * Read a 16-bit signed integer and move pointer forward
  691. * @return {number}
  692. */
  693. readInt16() {
  694. var value = this._data.getInt16(this.offset, this.littleEndian);
  695. this.offset += 2;
  696. return value;
  697. }
  698. /**
  699. * Read a 16-bit unsigned integer and move pointer forward
  700. * @return {number}
  701. */
  702. readUint16() {
  703. var value = this._data.getUint16(this.offset, this.littleEndian);
  704. this.offset += 2;
  705. return value;
  706. }
  707. /**
  708. * Read a 32-bit signed integer and move pointer forward
  709. * @return {number}
  710. */
  711. readInt32() {
  712. var value = this._data.getInt32(this.offset, this.littleEndian);
  713. this.offset += 4;
  714. return value;
  715. }
  716. /**
  717. * Read a 32-bit unsigned integer and move pointer forward
  718. * @return {number}
  719. */
  720. readUint32() {
  721. var value = this._data.getUint32(this.offset, this.littleEndian);
  722. this.offset += 4;
  723. return value;
  724. }
  725. /**
  726. * Read a 32-bit floating number and move pointer forward
  727. * @return {number}
  728. */
  729. readFloat32() {
  730. var value = this._data.getFloat32(this.offset, this.littleEndian);
  731. this.offset += 4;
  732. return value;
  733. }
  734. /**
  735. * Read a 64-bit floating number and move pointer forward
  736. * @return {number}
  737. */
  738. readFloat64() {
  739. var value = this._data.getFloat64(this.offset, this.littleEndian);
  740. this.offset += 8;
  741. return value;
  742. }
  743. /**
  744. * Read 1-byte ascii character and move pointer forward
  745. * @return {string}
  746. */
  747. readChar() {
  748. return String.fromCharCode(this.readInt8());
  749. }
  750. /**
  751. * Read n 1-byte ascii characters and move pointer forward
  752. * @param {number} n
  753. * @return {string}
  754. */
  755. readChars(n) {
  756. if (n === undefined) n = 1;
  757. charArray.length = n;
  758. for (var i = 0; i < n; i++) {
  759. charArray[i] = this.readChar();
  760. }
  761. return charArray.join('');
  762. }
  763. /**
  764. * Read the next n bytes, return a UTF-8 decoded string and move pointer forward
  765. * @param {number} n
  766. * @return {string}
  767. */
  768. readUtf8(n) {
  769. if (n === undefined) n = 1;
  770. const bString = this.readChars(n);
  771. return utf8.decode(bString);
  772. }
  773. /**
  774. * Write 0xff if the passed value is truthy, 0x00 otherwise
  775. * @param {any} value
  776. * @return {IOBuffer}
  777. */
  778. writeBoolean(value) {
  779. this.writeUint8(value ? 0xff : 0x00);
  780. return this;
  781. }
  782. /**
  783. * Write value as an 8-bit signed integer
  784. * @param {number} value
  785. * @return {IOBuffer}
  786. */
  787. writeInt8(value) {
  788. this.ensureAvailable(1);
  789. this._data.setInt8(this.offset++, value);
  790. this._updateLastWrittenByte();
  791. return this;
  792. }
  793. /**
  794. * Write value as a 8-bit unsigned integer
  795. * @param {number} value
  796. * @return {IOBuffer}
  797. */
  798. writeUint8(value) {
  799. this.ensureAvailable(1);
  800. this._data.setUint8(this.offset++, value);
  801. this._updateLastWrittenByte();
  802. return this;
  803. }
  804. /**
  805. * An alias for {@link IOBuffer#writeUint8}
  806. * @param {number} value
  807. * @return {IOBuffer}
  808. */
  809. writeByte(value) {
  810. return this.writeUint8(value);
  811. }
  812. /**
  813. * Write bytes
  814. * @param {Array|Uint8Array} bytes
  815. * @return {IOBuffer}
  816. */
  817. writeBytes(bytes) {
  818. this.ensureAvailable(bytes.length);
  819. for (var i = 0; i < bytes.length; i++) {
  820. this._data.setUint8(this.offset++, bytes[i]);
  821. }
  822. this._updateLastWrittenByte();
  823. return this;
  824. }
  825. /**
  826. * Write value as an 16-bit signed integer
  827. * @param {number} value
  828. * @return {IOBuffer}
  829. */
  830. writeInt16(value) {
  831. this.ensureAvailable(2);
  832. this._data.setInt16(this.offset, value, this.littleEndian);
  833. this.offset += 2;
  834. this._updateLastWrittenByte();
  835. return this;
  836. }
  837. /**
  838. * Write value as a 16-bit unsigned integer
  839. * @param {number} value
  840. * @return {IOBuffer}
  841. */
  842. writeUint16(value) {
  843. this.ensureAvailable(2);
  844. this._data.setUint16(this.offset, value, this.littleEndian);
  845. this.offset += 2;
  846. this._updateLastWrittenByte();
  847. return this;
  848. }
  849. /**
  850. * Write a 32-bit signed integer at the current pointer offset
  851. * @param {number} value
  852. * @return {IOBuffer}
  853. */
  854. writeInt32(value) {
  855. this.ensureAvailable(4);
  856. this._data.setInt32(this.offset, value, this.littleEndian);
  857. this.offset += 4;
  858. this._updateLastWrittenByte();
  859. return this;
  860. }
  861. /**
  862. * Write a 32-bit unsigned integer at the current pointer offset
  863. * @param {number} value - The value to set
  864. * @return {IOBuffer}
  865. */
  866. writeUint32(value) {
  867. this.ensureAvailable(4);
  868. this._data.setUint32(this.offset, value, this.littleEndian);
  869. this.offset += 4;
  870. this._updateLastWrittenByte();
  871. return this;
  872. }
  873. /**
  874. * Write a 32-bit floating number at the current pointer offset
  875. * @param {number} value - The value to set
  876. * @return {IOBuffer}
  877. */
  878. writeFloat32(value) {
  879. this.ensureAvailable(4);
  880. this._data.setFloat32(this.offset, value, this.littleEndian);
  881. this.offset += 4;
  882. this._updateLastWrittenByte();
  883. return this;
  884. }
  885. /**
  886. * Write a 64-bit floating number at the current pointer offset
  887. * @param {number} value
  888. * @return {IOBuffer}
  889. */
  890. writeFloat64(value) {
  891. this.ensureAvailable(8);
  892. this._data.setFloat64(this.offset, value, this.littleEndian);
  893. this.offset += 8;
  894. this._updateLastWrittenByte();
  895. return this;
  896. }
  897. /**
  898. * Write the charCode of the passed string's first character to the current pointer offset
  899. * @param {string} str - The character to set
  900. * @return {IOBuffer}
  901. */
  902. writeChar(str) {
  903. return this.writeUint8(str.charCodeAt(0));
  904. }
  905. /**
  906. * Write the charCodes of the passed string's characters to the current pointer offset
  907. * @param {string} str
  908. * @return {IOBuffer}
  909. */
  910. writeChars(str) {
  911. for (var i = 0; i < str.length; i++) {
  912. this.writeUint8(str.charCodeAt(i));
  913. }
  914. return this;
  915. }
  916. /**
  917. * UTF-8 encode and write the passed string to the current pointer offset
  918. * @param {string} str
  919. * @return {IOBuffer}
  920. */
  921. writeUtf8(str) {
  922. const bString = utf8.encode(str);
  923. return this.writeChars(bString);
  924. }
  925. /**
  926. * Export a Uint8Array view of the internal buffer.
  927. * The view starts at the byte offset and its length
  928. * is calculated to stop at the last written byte or the original length.
  929. * @return {Uint8Array}
  930. */
  931. toArray() {
  932. return new Uint8Array(this.buffer, this.byteOffset, this._lastWrittenByte);
  933. }
  934. /**
  935. * Same as {@link IOBuffer#toArray} but returns a Buffer if possible. Otherwise returns a Uint8Array.
  936. * @return {Buffer|Uint8Array}
  937. */
  938. getBuffer() {
  939. if (typeof Buffer !== 'undefined') {
  940. return Buffer.from(this.toArray());
  941. } else {
  942. return this.toArray();
  943. }
  944. }
  945. /**
  946. * Update the last written byte offset
  947. * @private
  948. */
  949. _updateLastWrittenByte() {
  950. if (this.offset > this._lastWrittenByte) {
  951. this._lastWrittenByte = this.offset;
  952. }
  953. }
  954. }
  955. module.exports = IOBuffer;
  956. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(5).Buffer))
  957. /***/ }),
  958. /* 5 */
  959. /***/ (function(module, exports, __webpack_require__) {
  960. "use strict";
  961. /* WEBPACK VAR INJECTION */(function(global) {/*!
  962. * The buffer module from node.js, for the browser.
  963. *
  964. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  965. * @license MIT
  966. */
  967. /* eslint-disable no-proto */
  968. var base64 = __webpack_require__(6);
  969. var ieee754 = __webpack_require__(7);
  970. var isArray = __webpack_require__(8);
  971. exports.Buffer = Buffer;
  972. exports.SlowBuffer = SlowBuffer;
  973. exports.INSPECT_MAX_BYTES = 50;
  974. /**
  975. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  976. * === true Use Uint8Array implementation (fastest)
  977. * === false Use Object implementation (most compatible, even IE6)
  978. *
  979. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  980. * Opera 11.6+, iOS 4.2+.
  981. *
  982. * Due to various browser bugs, sometimes the Object implementation will be used even
  983. * when the browser supports typed arrays.
  984. *
  985. * Note:
  986. *
  987. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  988. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  989. *
  990. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  991. *
  992. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  993. * incorrect length in some situations.
  994. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  995. * get the Object implementation, which is slower but behaves correctly.
  996. */
  997. Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined ? global.TYPED_ARRAY_SUPPORT : typedArraySupport();
  998. /*
  999. * Export kMaxLength after typed array support is determined.
  1000. */
  1001. exports.kMaxLength = kMaxLength();
  1002. function typedArraySupport() {
  1003. try {
  1004. var arr = new Uint8Array(1);
  1005. arr.__proto__ = {
  1006. __proto__: Uint8Array.prototype,
  1007. foo: function foo() {
  1008. return 42;
  1009. }
  1010. };
  1011. return arr.foo() === 42 && // typed array instances can be augmented
  1012. typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
  1013. arr.subarray(1, 1).byteLength === 0; // ie10 has broken `subarray`
  1014. } catch (e) {
  1015. return false;
  1016. }
  1017. }
  1018. function kMaxLength() {
  1019. return Buffer.TYPED_ARRAY_SUPPORT ? 0x7fffffff : 0x3fffffff;
  1020. }
  1021. function createBuffer(that, length) {
  1022. if (kMaxLength() < length) {
  1023. throw new RangeError('Invalid typed array length');
  1024. }
  1025. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1026. // Return an augmented `Uint8Array` instance, for best performance
  1027. that = new Uint8Array(length);
  1028. that.__proto__ = Buffer.prototype;
  1029. } else {
  1030. // Fallback: Return an object instance of the Buffer class
  1031. if (that === null) {
  1032. that = new Buffer(length);
  1033. }
  1034. that.length = length;
  1035. }
  1036. return that;
  1037. }
  1038. /**
  1039. * The Buffer constructor returns instances of `Uint8Array` that have their
  1040. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  1041. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  1042. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  1043. * returns a single octet.
  1044. *
  1045. * The `Uint8Array` prototype remains unmodified.
  1046. */
  1047. function Buffer(arg, encodingOrOffset, length) {
  1048. if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
  1049. return new Buffer(arg, encodingOrOffset, length);
  1050. } // Common case.
  1051. if (typeof arg === 'number') {
  1052. if (typeof encodingOrOffset === 'string') {
  1053. throw new Error('If encoding is specified then the first argument must be a string');
  1054. }
  1055. return allocUnsafe(this, arg);
  1056. }
  1057. return from(this, arg, encodingOrOffset, length);
  1058. }
  1059. Buffer.poolSize = 8192; // not used by this implementation
  1060. // TODO: Legacy, not needed anymore. Remove in next major version.
  1061. Buffer._augment = function (arr) {
  1062. arr.__proto__ = Buffer.prototype;
  1063. return arr;
  1064. };
  1065. function from(that, value, encodingOrOffset, length) {
  1066. if (typeof value === 'number') {
  1067. throw new TypeError('"value" argument must not be a number');
  1068. }
  1069. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  1070. return fromArrayBuffer(that, value, encodingOrOffset, length);
  1071. }
  1072. if (typeof value === 'string') {
  1073. return fromString(that, value, encodingOrOffset);
  1074. }
  1075. return fromObject(that, value);
  1076. }
  1077. /**
  1078. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  1079. * if value is a number.
  1080. * Buffer.from(str[, encoding])
  1081. * Buffer.from(array)
  1082. * Buffer.from(buffer)
  1083. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  1084. **/
  1085. Buffer.from = function (value, encodingOrOffset, length) {
  1086. return from(null, value, encodingOrOffset, length);
  1087. };
  1088. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1089. Buffer.prototype.__proto__ = Uint8Array.prototype;
  1090. Buffer.__proto__ = Uint8Array;
  1091. if (typeof Symbol !== 'undefined' && Symbol.species && Buffer[Symbol.species] === Buffer) {
  1092. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  1093. Object.defineProperty(Buffer, Symbol.species, {
  1094. value: null,
  1095. configurable: true
  1096. });
  1097. }
  1098. }
  1099. function assertSize(size) {
  1100. if (typeof size !== 'number') {
  1101. throw new TypeError('"size" argument must be a number');
  1102. } else if (size < 0) {
  1103. throw new RangeError('"size" argument must not be negative');
  1104. }
  1105. }
  1106. function alloc(that, size, fill, encoding) {
  1107. assertSize(size);
  1108. if (size <= 0) {
  1109. return createBuffer(that, size);
  1110. }
  1111. if (fill !== undefined) {
  1112. // Only pay attention to encoding if it's a string. This
  1113. // prevents accidentally sending in a number that would
  1114. // be interpretted as a start offset.
  1115. return typeof encoding === 'string' ? createBuffer(that, size).fill(fill, encoding) : createBuffer(that, size).fill(fill);
  1116. }
  1117. return createBuffer(that, size);
  1118. }
  1119. /**
  1120. * Creates a new filled Buffer instance.
  1121. * alloc(size[, fill[, encoding]])
  1122. **/
  1123. Buffer.alloc = function (size, fill, encoding) {
  1124. return alloc(null, size, fill, encoding);
  1125. };
  1126. function allocUnsafe(that, size) {
  1127. assertSize(size);
  1128. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
  1129. if (!Buffer.TYPED_ARRAY_SUPPORT) {
  1130. for (var i = 0; i < size; ++i) {
  1131. that[i] = 0;
  1132. }
  1133. }
  1134. return that;
  1135. }
  1136. /**
  1137. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  1138. * */
  1139. Buffer.allocUnsafe = function (size) {
  1140. return allocUnsafe(null, size);
  1141. };
  1142. /**
  1143. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  1144. */
  1145. Buffer.allocUnsafeSlow = function (size) {
  1146. return allocUnsafe(null, size);
  1147. };
  1148. function fromString(that, string, encoding) {
  1149. if (typeof encoding !== 'string' || encoding === '') {
  1150. encoding = 'utf8';
  1151. }
  1152. if (!Buffer.isEncoding(encoding)) {
  1153. throw new TypeError('"encoding" must be a valid string encoding');
  1154. }
  1155. var length = byteLength(string, encoding) | 0;
  1156. that = createBuffer(that, length);
  1157. var actual = that.write(string, encoding);
  1158. if (actual !== length) {
  1159. // Writing a hex string, for example, that contains invalid characters will
  1160. // cause everything after the first invalid character to be ignored. (e.g.
  1161. // 'abxxcd' will be treated as 'ab')
  1162. that = that.slice(0, actual);
  1163. }
  1164. return that;
  1165. }
  1166. function fromArrayLike(that, array) {
  1167. var length = array.length < 0 ? 0 : checked(array.length) | 0;
  1168. that = createBuffer(that, length);
  1169. for (var i = 0; i < length; i += 1) {
  1170. that[i] = array[i] & 255;
  1171. }
  1172. return that;
  1173. }
  1174. function fromArrayBuffer(that, array, byteOffset, length) {
  1175. array.byteLength; // this throws if `array` is not a valid ArrayBuffer
  1176. if (byteOffset < 0 || array.byteLength < byteOffset) {
  1177. throw new RangeError('\'offset\' is out of bounds');
  1178. }
  1179. if (array.byteLength < byteOffset + (length || 0)) {
  1180. throw new RangeError('\'length\' is out of bounds');
  1181. }
  1182. if (byteOffset === undefined && length === undefined) {
  1183. array = new Uint8Array(array);
  1184. } else if (length === undefined) {
  1185. array = new Uint8Array(array, byteOffset);
  1186. } else {
  1187. array = new Uint8Array(array, byteOffset, length);
  1188. }
  1189. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1190. // Return an augmented `Uint8Array` instance, for best performance
  1191. that = array;
  1192. that.__proto__ = Buffer.prototype;
  1193. } else {
  1194. // Fallback: Return an object instance of the Buffer class
  1195. that = fromArrayLike(that, array);
  1196. }
  1197. return that;
  1198. }
  1199. function fromObject(that, obj) {
  1200. if (Buffer.isBuffer(obj)) {
  1201. var len = checked(obj.length) | 0;
  1202. that = createBuffer(that, len);
  1203. if (that.length === 0) {
  1204. return that;
  1205. }
  1206. obj.copy(that, 0, 0, len);
  1207. return that;
  1208. }
  1209. if (obj) {
  1210. if (typeof ArrayBuffer !== 'undefined' && obj.buffer instanceof ArrayBuffer || 'length' in obj) {
  1211. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  1212. return createBuffer(that, 0);
  1213. }
  1214. return fromArrayLike(that, obj);
  1215. }
  1216. if (obj.type === 'Buffer' && isArray(obj.data)) {
  1217. return fromArrayLike(that, obj.data);
  1218. }
  1219. }
  1220. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.');
  1221. }
  1222. function checked(length) {
  1223. // Note: cannot use `length < kMaxLength()` here because that fails when
  1224. // length is NaN (which is otherwise coerced to zero.)
  1225. if (length >= kMaxLength()) {
  1226. throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + kMaxLength().toString(16) + ' bytes');
  1227. }
  1228. return length | 0;
  1229. }
  1230. function SlowBuffer(length) {
  1231. if (+length != length) {
  1232. // eslint-disable-line eqeqeq
  1233. length = 0;
  1234. }
  1235. return Buffer.alloc(+length);
  1236. }
  1237. Buffer.isBuffer = function isBuffer(b) {
  1238. return !!(b != null && b._isBuffer);
  1239. };
  1240. Buffer.compare = function compare(a, b) {
  1241. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  1242. throw new TypeError('Arguments must be Buffers');
  1243. }
  1244. if (a === b) return 0;
  1245. var x = a.length;
  1246. var y = b.length;
  1247. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  1248. if (a[i] !== b[i]) {
  1249. x = a[i];
  1250. y = b[i];
  1251. break;
  1252. }
  1253. }
  1254. if (x < y) return -1;
  1255. if (y < x) return 1;
  1256. return 0;
  1257. };
  1258. Buffer.isEncoding = function isEncoding(encoding) {
  1259. switch (String(encoding).toLowerCase()) {
  1260. case 'hex':
  1261. case 'utf8':
  1262. case 'utf-8':
  1263. case 'ascii':
  1264. case 'latin1':
  1265. case 'binary':
  1266. case 'base64':
  1267. case 'ucs2':
  1268. case 'ucs-2':
  1269. case 'utf16le':
  1270. case 'utf-16le':
  1271. return true;
  1272. default:
  1273. return false;
  1274. }
  1275. };
  1276. Buffer.concat = function concat(list, length) {
  1277. if (!isArray(list)) {
  1278. throw new TypeError('"list" argument must be an Array of Buffers');
  1279. }
  1280. if (list.length === 0) {
  1281. return Buffer.alloc(0);
  1282. }
  1283. var i;
  1284. if (length === undefined) {
  1285. length = 0;
  1286. for (i = 0; i < list.length; ++i) {
  1287. length += list[i].length;
  1288. }
  1289. }
  1290. var buffer = Buffer.allocUnsafe(length);
  1291. var pos = 0;
  1292. for (i = 0; i < list.length; ++i) {
  1293. var buf = list[i];
  1294. if (!Buffer.isBuffer(buf)) {
  1295. throw new TypeError('"list" argument must be an Array of Buffers');
  1296. }
  1297. buf.copy(buffer, pos);
  1298. pos += buf.length;
  1299. }
  1300. return buffer;
  1301. };
  1302. function byteLength(string, encoding) {
  1303. if (Buffer.isBuffer(string)) {
  1304. return string.length;
  1305. }
  1306. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  1307. return string.byteLength;
  1308. }
  1309. if (typeof string !== 'string') {
  1310. string = '' + string;
  1311. }
  1312. var len = string.length;
  1313. if (len === 0) return 0; // Use a for loop to avoid recursion
  1314. var loweredCase = false;
  1315. for (;;) {
  1316. switch (encoding) {
  1317. case 'ascii':
  1318. case 'latin1':
  1319. case 'binary':
  1320. return len;
  1321. case 'utf8':
  1322. case 'utf-8':
  1323. case undefined:
  1324. return utf8ToBytes(string).length;
  1325. case 'ucs2':
  1326. case 'ucs-2':
  1327. case 'utf16le':
  1328. case 'utf-16le':
  1329. return len * 2;
  1330. case 'hex':
  1331. return len >>> 1;
  1332. case 'base64':
  1333. return base64ToBytes(string).length;
  1334. default:
  1335. if (loweredCase) return utf8ToBytes(string).length; // assume utf8
  1336. encoding = ('' + encoding).toLowerCase();
  1337. loweredCase = true;
  1338. }
  1339. }
  1340. }
  1341. Buffer.byteLength = byteLength;
  1342. function slowToString(encoding, start, end) {
  1343. var loweredCase = false; // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  1344. // property of a typed array.
  1345. // This behaves neither like String nor Uint8Array in that we set start/end
  1346. // to their upper/lower bounds if the value passed is out of range.
  1347. // undefined is handled specially as per ECMA-262 6th Edition,
  1348. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  1349. if (start === undefined || start < 0) {
  1350. start = 0;
  1351. } // Return early if start > this.length. Done here to prevent potential uint32
  1352. // coercion fail below.
  1353. if (start > this.length) {
  1354. return '';
  1355. }
  1356. if (end === undefined || end > this.length) {
  1357. end = this.length;
  1358. }
  1359. if (end <= 0) {
  1360. return '';
  1361. } // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  1362. end >>>= 0;
  1363. start >>>= 0;
  1364. if (end <= start) {
  1365. return '';
  1366. }
  1367. if (!encoding) encoding = 'utf8';
  1368. while (true) {
  1369. switch (encoding) {
  1370. case 'hex':
  1371. return hexSlice(this, start, end);
  1372. case 'utf8':
  1373. case 'utf-8':
  1374. return utf8Slice(this, start, end);
  1375. case 'ascii':
  1376. return asciiSlice(this, start, end);
  1377. case 'latin1':
  1378. case 'binary':
  1379. return latin1Slice(this, start, end);
  1380. case 'base64':
  1381. return base64Slice(this, start, end);
  1382. case 'ucs2':
  1383. case 'ucs-2':
  1384. case 'utf16le':
  1385. case 'utf-16le':
  1386. return utf16leSlice(this, start, end);
  1387. default:
  1388. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  1389. encoding = (encoding + '').toLowerCase();
  1390. loweredCase = true;
  1391. }
  1392. }
  1393. } // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  1394. // Buffer instances.
  1395. Buffer.prototype._isBuffer = true;
  1396. function swap(b, n, m) {
  1397. var i = b[n];
  1398. b[n] = b[m];
  1399. b[m] = i;
  1400. }
  1401. Buffer.prototype.swap16 = function swap16() {
  1402. var len = this.length;
  1403. if (len % 2 !== 0) {
  1404. throw new RangeError('Buffer size must be a multiple of 16-bits');
  1405. }
  1406. for (var i = 0; i < len; i += 2) {
  1407. swap(this, i, i + 1);
  1408. }
  1409. return this;
  1410. };
  1411. Buffer.prototype.swap32 = function swap32() {
  1412. var len = this.length;
  1413. if (len % 4 !== 0) {
  1414. throw new RangeError('Buffer size must be a multiple of 32-bits');
  1415. }
  1416. for (var i = 0; i < len; i += 4) {
  1417. swap(this, i, i + 3);
  1418. swap(this, i + 1, i + 2);
  1419. }
  1420. return this;
  1421. };
  1422. Buffer.prototype.swap64 = function swap64() {
  1423. var len = this.length;
  1424. if (len % 8 !== 0) {
  1425. throw new RangeError('Buffer size must be a multiple of 64-bits');
  1426. }
  1427. for (var i = 0; i < len; i += 8) {
  1428. swap(this, i, i + 7);
  1429. swap(this, i + 1, i + 6);
  1430. swap(this, i + 2, i + 5);
  1431. swap(this, i + 3, i + 4);
  1432. }
  1433. return this;
  1434. };
  1435. Buffer.prototype.toString = function toString() {
  1436. var length = this.length | 0;
  1437. if (length === 0) return '';
  1438. if (arguments.length === 0) return utf8Slice(this, 0, length);
  1439. return slowToString.apply(this, arguments);
  1440. };
  1441. Buffer.prototype.equals = function equals(b) {
  1442. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer');
  1443. if (this === b) return true;
  1444. return Buffer.compare(this, b) === 0;
  1445. };
  1446. Buffer.prototype.inspect = function inspect() {
  1447. var str = '';
  1448. var max = exports.INSPECT_MAX_BYTES;
  1449. if (this.length > 0) {
  1450. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
  1451. if (this.length > max) str += ' ... ';
  1452. }
  1453. return '<Buffer ' + str + '>';
  1454. };
  1455. Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
  1456. if (!Buffer.isBuffer(target)) {
  1457. throw new TypeError('Argument must be a Buffer');
  1458. }
  1459. if (start === undefined) {
  1460. start = 0;
  1461. }
  1462. if (end === undefined) {
  1463. end = target ? target.length : 0;
  1464. }
  1465. if (thisStart === undefined) {
  1466. thisStart = 0;
  1467. }
  1468. if (thisEnd === undefined) {
  1469. thisEnd = this.length;
  1470. }
  1471. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  1472. throw new RangeError('out of range index');
  1473. }
  1474. if (thisStart >= thisEnd && start >= end) {
  1475. return 0;
  1476. }
  1477. if (thisStart >= thisEnd) {
  1478. return -1;
  1479. }
  1480. if (start >= end) {
  1481. return 1;
  1482. }
  1483. start >>>= 0;
  1484. end >>>= 0;
  1485. thisStart >>>= 0;
  1486. thisEnd >>>= 0;
  1487. if (this === target) return 0;
  1488. var x = thisEnd - thisStart;
  1489. var y = end - start;
  1490. var len = Math.min(x, y);
  1491. var thisCopy = this.slice(thisStart, thisEnd);
  1492. var targetCopy = target.slice(start, end);
  1493. for (var i = 0; i < len; ++i) {
  1494. if (thisCopy[i] !== targetCopy[i]) {
  1495. x = thisCopy[i];
  1496. y = targetCopy[i];
  1497. break;
  1498. }
  1499. }
  1500. if (x < y) return -1;
  1501. if (y < x) return 1;
  1502. return 0;
  1503. }; // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  1504. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  1505. //
  1506. // Arguments:
  1507. // - buffer - a Buffer to search
  1508. // - val - a string, Buffer, or number
  1509. // - byteOffset - an index into `buffer`; will be clamped to an int32
  1510. // - encoding - an optional encoding, relevant is val is a string
  1511. // - dir - true for indexOf, false for lastIndexOf
  1512. function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
  1513. // Empty buffer means no match
  1514. if (buffer.length === 0) return -1; // Normalize byteOffset
  1515. if (typeof byteOffset === 'string') {
  1516. encoding = byteOffset;
  1517. byteOffset = 0;
  1518. } else if (byteOffset > 0x7fffffff) {
  1519. byteOffset = 0x7fffffff;
  1520. } else if (byteOffset < -0x80000000) {
  1521. byteOffset = -0x80000000;
  1522. }
  1523. byteOffset = +byteOffset; // Coerce to Number.
  1524. if (isNaN(byteOffset)) {
  1525. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  1526. byteOffset = dir ? 0 : buffer.length - 1;
  1527. } // Normalize byteOffset: negative offsets start from the end of the buffer
  1528. if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
  1529. if (byteOffset >= buffer.length) {
  1530. if (dir) return -1;else byteOffset = buffer.length - 1;
  1531. } else if (byteOffset < 0) {
  1532. if (dir) byteOffset = 0;else return -1;
  1533. } // Normalize val
  1534. if (typeof val === 'string') {
  1535. val = Buffer.from(val, encoding);
  1536. } // Finally, search either indexOf (if dir is true) or lastIndexOf
  1537. if (Buffer.isBuffer(val)) {
  1538. // Special case: looking for empty string/buffer always fails
  1539. if (val.length === 0) {
  1540. return -1;
  1541. }
  1542. return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
  1543. } else if (typeof val === 'number') {
  1544. val = val & 0xFF; // Search for a byte value [0-255]
  1545. if (Buffer.TYPED_ARRAY_SUPPORT && typeof Uint8Array.prototype.indexOf === 'function') {
  1546. if (dir) {
  1547. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
  1548. } else {
  1549. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
  1550. }
  1551. }
  1552. return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
  1553. }
  1554. throw new TypeError('val must be string, number or Buffer');
  1555. }
  1556. function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
  1557. var indexSize = 1;
  1558. var arrLength = arr.length;
  1559. var valLength = val.length;
  1560. if (encoding !== undefined) {
  1561. encoding = String(encoding).toLowerCase();
  1562. if (encoding === 'ucs2' || encoding === 'ucs-2' || encoding === 'utf16le' || encoding === 'utf-16le') {
  1563. if (arr.length < 2 || val.length < 2) {
  1564. return -1;
  1565. }
  1566. indexSize = 2;
  1567. arrLength /= 2;
  1568. valLength /= 2;
  1569. byteOffset /= 2;
  1570. }
  1571. }
  1572. function read(buf, i) {
  1573. if (indexSize === 1) {
  1574. return buf[i];
  1575. } else {
  1576. return buf.readUInt16BE(i * indexSize);
  1577. }
  1578. }
  1579. var i;
  1580. if (dir) {
  1581. var foundIndex = -1;
  1582. for (i = byteOffset; i < arrLength; i++) {
  1583. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  1584. if (foundIndex === -1) foundIndex = i;
  1585. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
  1586. } else {
  1587. if (foundIndex !== -1) i -= i - foundIndex;
  1588. foundIndex = -1;
  1589. }
  1590. }
  1591. } else {
  1592. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
  1593. for (i = byteOffset; i >= 0; i--) {
  1594. var found = true;
  1595. for (var j = 0; j < valLength; j++) {
  1596. if (read(arr, i + j) !== read(val, j)) {
  1597. found = false;
  1598. break;
  1599. }
  1600. }
  1601. if (found) return i;
  1602. }
  1603. }
  1604. return -1;
  1605. }
  1606. Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
  1607. return this.indexOf(val, byteOffset, encoding) !== -1;
  1608. };
  1609. Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
  1610. return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
  1611. };
  1612. Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
  1613. return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
  1614. };
  1615. function hexWrite(buf, string, offset, length) {
  1616. offset = Number(offset) || 0;
  1617. var remaining = buf.length - offset;
  1618. if (!length) {
  1619. length = remaining;
  1620. } else {
  1621. length = Number(length);
  1622. if (length > remaining) {
  1623. length = remaining;
  1624. }
  1625. } // must be an even number of digits
  1626. var strLen = string.length;
  1627. if (strLen % 2 !== 0) throw new TypeError('Invalid hex string');
  1628. if (length > strLen / 2) {
  1629. length = strLen / 2;
  1630. }
  1631. for (var i = 0; i < length; ++i) {
  1632. var parsed = parseInt(string.substr(i * 2, 2), 16);
  1633. if (isNaN(parsed)) return i;
  1634. buf[offset + i] = parsed;
  1635. }
  1636. return i;
  1637. }
  1638. function utf8Write(buf, string, offset, length) {
  1639. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
  1640. }
  1641. function asciiWrite(buf, string, offset, length) {
  1642. return blitBuffer(asciiToBytes(string), buf, offset, length);
  1643. }
  1644. function latin1Write(buf, string, offset, length) {
  1645. return asciiWrite(buf, string, offset, length);
  1646. }
  1647. function base64Write(buf, string, offset, length) {
  1648. return blitBuffer(base64ToBytes(string), buf, offset, length);
  1649. }
  1650. function ucs2Write(buf, string, offset, length) {
  1651. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
  1652. }
  1653. Buffer.prototype.write = function write(string, offset, length, encoding) {
  1654. // Buffer#write(string)
  1655. if (offset === undefined) {
  1656. encoding = 'utf8';
  1657. length = this.length;
  1658. offset = 0; // Buffer#write(string, encoding)
  1659. } else if (length === undefined && typeof offset === 'string') {
  1660. encoding = offset;
  1661. length = this.length;
  1662. offset = 0; // Buffer#write(string, offset[, length][, encoding])
  1663. } else if (isFinite(offset)) {
  1664. offset = offset | 0;
  1665. if (isFinite(length)) {
  1666. length = length | 0;
  1667. if (encoding === undefined) encoding = 'utf8';
  1668. } else {
  1669. encoding = length;
  1670. length = undefined;
  1671. } // legacy write(string, encoding, offset, length) - remove in v0.13
  1672. } else {
  1673. throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported');
  1674. }
  1675. var remaining = this.length - offset;
  1676. if (length === undefined || length > remaining) length = remaining;
  1677. if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
  1678. throw new RangeError('Attempt to write outside buffer bounds');
  1679. }
  1680. if (!encoding) encoding = 'utf8';
  1681. var loweredCase = false;
  1682. for (;;) {
  1683. switch (encoding) {
  1684. case 'hex':
  1685. return hexWrite(this, string, offset, length);
  1686. case 'utf8':
  1687. case 'utf-8':
  1688. return utf8Write(this, string, offset, length);
  1689. case 'ascii':
  1690. return asciiWrite(this, string, offset, length);
  1691. case 'latin1':
  1692. case 'binary':
  1693. return latin1Write(this, string, offset, length);
  1694. case 'base64':
  1695. // Warning: maxLength not taken into account in base64Write
  1696. return base64Write(this, string, offset, length);
  1697. case 'ucs2':
  1698. case 'ucs-2':
  1699. case 'utf16le':
  1700. case 'utf-16le':
  1701. return ucs2Write(this, string, offset, length);
  1702. default:
  1703. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  1704. encoding = ('' + encoding).toLowerCase();
  1705. loweredCase = true;
  1706. }
  1707. }
  1708. };
  1709. Buffer.prototype.toJSON = function toJSON() {
  1710. return {
  1711. type: 'Buffer',
  1712. data: Array.prototype.slice.call(this._arr || this, 0)
  1713. };
  1714. };
  1715. function base64Slice(buf, start, end) {
  1716. if (start === 0 && end === buf.length) {
  1717. return base64.fromByteArray(buf);
  1718. } else {
  1719. return base64.fromByteArray(buf.slice(start, end));
  1720. }
  1721. }
  1722. function utf8Slice(buf, start, end) {
  1723. end = Math.min(buf.length, end);
  1724. var res = [];
  1725. var i = start;
  1726. while (i < end) {
  1727. var firstByte = buf[i];
  1728. var codePoint = null;
  1729. var bytesPerSequence = firstByte > 0xEF ? 4 : firstByte > 0xDF ? 3 : firstByte > 0xBF ? 2 : 1;
  1730. if (i + bytesPerSequence <= end) {
  1731. var secondByte, thirdByte, fourthByte, tempCodePoint;
  1732. switch (bytesPerSequence) {
  1733. case 1:
  1734. if (firstByte < 0x80) {
  1735. codePoint = firstByte;
  1736. }
  1737. break;
  1738. case 2:
  1739. secondByte = buf[i + 1];
  1740. if ((secondByte & 0xC0) === 0x80) {
  1741. tempCodePoint = (firstByte & 0x1F) << 0x6 | secondByte & 0x3F;
  1742. if (tempCodePoint > 0x7F) {
  1743. codePoint = tempCodePoint;
  1744. }
  1745. }
  1746. break;
  1747. case 3:
  1748. secondByte = buf[i + 1];
  1749. thirdByte = buf[i + 2];
  1750. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  1751. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | thirdByte & 0x3F;
  1752. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  1753. codePoint = tempCodePoint;
  1754. }
  1755. }
  1756. break;
  1757. case 4:
  1758. secondByte = buf[i + 1];
  1759. thirdByte = buf[i + 2];
  1760. fourthByte = buf[i + 3];
  1761. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  1762. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | fourthByte & 0x3F;
  1763. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  1764. codePoint = tempCodePoint;
  1765. }
  1766. }
  1767. }
  1768. }
  1769. if (codePoint === null) {
  1770. // we did not generate a valid codePoint so insert a
  1771. // replacement char (U+FFFD) and advance only 1 byte
  1772. codePoint = 0xFFFD;
  1773. bytesPerSequence = 1;
  1774. } else if (codePoint > 0xFFFF) {
  1775. // encode to utf16 (surrogate pair dance)
  1776. codePoint -= 0x10000;
  1777. res.push(codePoint >>> 10 & 0x3FF | 0xD800);
  1778. codePoint = 0xDC00 | codePoint & 0x3FF;
  1779. }
  1780. res.push(codePoint);
  1781. i += bytesPerSequence;
  1782. }
  1783. return decodeCodePointsArray(res);
  1784. } // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  1785. // the lowest limit is Chrome, with 0x10000 args.
  1786. // We go 1 magnitude less, for safety
  1787. var MAX_ARGUMENTS_LENGTH = 0x1000;
  1788. function decodeCodePointsArray(codePoints) {
  1789. var len = codePoints.length;
  1790. if (len <= MAX_ARGUMENTS_LENGTH) {
  1791. return String.fromCharCode.apply(String, codePoints); // avoid extra slice()
  1792. } // Decode in chunks to avoid "call stack size exceeded".
  1793. var res = '';
  1794. var i = 0;
  1795. while (i < len) {
  1796. res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
  1797. }
  1798. return res;
  1799. }
  1800. function asciiSlice(buf, start, end) {
  1801. var ret = '';
  1802. end = Math.min(buf.length, end);
  1803. for (var i = start; i < end; ++i) {
  1804. ret += String.fromCharCode(buf[i] & 0x7F);
  1805. }
  1806. return ret;
  1807. }
  1808. function latin1Slice(buf, start, end) {
  1809. var ret = '';
  1810. end = Math.min(buf.length, end);
  1811. for (var i = start; i < end; ++i) {
  1812. ret += String.fromCharCode(buf[i]);
  1813. }
  1814. return ret;
  1815. }
  1816. function hexSlice(buf, start, end) {
  1817. var len = buf.length;
  1818. if (!start || start < 0) start = 0;
  1819. if (!end || end < 0 || end > len) end = len;
  1820. var out = '';
  1821. for (var i = start; i < end; ++i) {
  1822. out += toHex(buf[i]);
  1823. }
  1824. return out;
  1825. }
  1826. function utf16leSlice(buf, start, end) {
  1827. var bytes = buf.slice(start, end);
  1828. var res = '';
  1829. for (var i = 0; i < bytes.length; i += 2) {
  1830. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
  1831. }
  1832. return res;
  1833. }
  1834. Buffer.prototype.slice = function slice(start, end) {
  1835. var len = this.length;
  1836. start = ~~start;
  1837. end = end === undefined ? len : ~~end;
  1838. if (start < 0) {
  1839. start += len;
  1840. if (start < 0) start = 0;
  1841. } else if (start > len) {
  1842. start = len;
  1843. }
  1844. if (end < 0) {
  1845. end += len;
  1846. if (end < 0) end = 0;
  1847. } else if (end > len) {
  1848. end = len;
  1849. }
  1850. if (end < start) end = start;
  1851. var newBuf;
  1852. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1853. newBuf = this.subarray(start, end);
  1854. newBuf.__proto__ = Buffer.prototype;
  1855. } else {
  1856. var sliceLen = end - start;
  1857. newBuf = new Buffer(sliceLen, undefined);
  1858. for (var i = 0; i < sliceLen; ++i) {
  1859. newBuf[i] = this[i + start];
  1860. }
  1861. }
  1862. return newBuf;
  1863. };
  1864. /*
  1865. * Need to make sure that buffer isn't trying to write out of bounds.
  1866. */
  1867. function checkOffset(offset, ext, length) {
  1868. if (offset % 1 !== 0 || offset < 0) throw new RangeError('offset is not uint');
  1869. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length');
  1870. }
  1871. Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {
  1872. offset = offset | 0;
  1873. byteLength = byteLength | 0;
  1874. if (!noAssert) checkOffset(offset, byteLength, this.length);
  1875. var val = this[offset];
  1876. var mul = 1;
  1877. var i = 0;
  1878. while (++i < byteLength && (mul *= 0x100)) {
  1879. val += this[offset + i] * mul;
  1880. }
  1881. return val;
  1882. };
  1883. Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {
  1884. offset = offset | 0;
  1885. byteLength = byteLength | 0;
  1886. if (!noAssert) {
  1887. checkOffset(offset, byteLength, this.length);
  1888. }
  1889. var val = this[offset + --byteLength];
  1890. var mul = 1;
  1891. while (byteLength > 0 && (mul *= 0x100)) {
  1892. val += this[offset + --byteLength] * mul;
  1893. }
  1894. return val;
  1895. };
  1896. Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
  1897. if (!noAssert) checkOffset(offset, 1, this.length);
  1898. return this[offset];
  1899. };
  1900. Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
  1901. if (!noAssert) checkOffset(offset, 2, this.length);
  1902. return this[offset] | this[offset + 1] << 8;
  1903. };
  1904. Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
  1905. if (!noAssert) checkOffset(offset, 2, this.length);
  1906. return this[offset] << 8 | this[offset + 1];
  1907. };
  1908. Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
  1909. if (!noAssert) checkOffset(offset, 4, this.length);
  1910. return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 0x1000000;
  1911. };
  1912. Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
  1913. if (!noAssert) checkOffset(offset, 4, this.length);
  1914. return this[offset] * 0x1000000 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
  1915. };
  1916. Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {
  1917. offset = offset | 0;
  1918. byteLength = byteLength | 0;
  1919. if (!noAssert) checkOffset(offset, byteLength, this.length);
  1920. var val = this[offset];
  1921. var mul = 1;
  1922. var i = 0;
  1923. while (++i < byteLength && (mul *= 0x100)) {
  1924. val += this[offset + i] * mul;
  1925. }
  1926. mul *= 0x80;
  1927. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  1928. return val;
  1929. };
  1930. Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {
  1931. offset = offset | 0;
  1932. byteLength = byteLength | 0;
  1933. if (!noAssert) checkOffset(offset, byteLength, this.length);
  1934. var i = byteLength;
  1935. var mul = 1;
  1936. var val = this[offset + --i];
  1937. while (i > 0 && (mul *= 0x100)) {
  1938. val += this[offset + --i] * mul;
  1939. }
  1940. mul *= 0x80;
  1941. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  1942. return val;
  1943. };
  1944. Buffer.prototype.readInt8 = function readInt8(offset, noAssert) {
  1945. if (!noAssert) checkOffset(offset, 1, this.length);
  1946. if (!(this[offset] & 0x80)) return this[offset];
  1947. return (0xff - this[offset] + 1) * -1;
  1948. };
  1949. Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
  1950. if (!noAssert) checkOffset(offset, 2, this.length);
  1951. var val = this[offset] | this[offset + 1] << 8;
  1952. return val & 0x8000 ? val | 0xFFFF0000 : val;
  1953. };
  1954. Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
  1955. if (!noAssert) checkOffset(offset, 2, this.length);
  1956. var val = this[offset + 1] | this[offset] << 8;
  1957. return val & 0x8000 ? val | 0xFFFF0000 : val;
  1958. };
  1959. Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
  1960. if (!noAssert) checkOffset(offset, 4, this.length);
  1961. return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
  1962. };
  1963. Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
  1964. if (!noAssert) checkOffset(offset, 4, this.length);
  1965. return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
  1966. };
  1967. Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
  1968. if (!noAssert) checkOffset(offset, 4, this.length);
  1969. return ieee754.read(this, offset, true, 23, 4);
  1970. };
  1971. Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
  1972. if (!noAssert) checkOffset(offset, 4, this.length);
  1973. return ieee754.read(this, offset, false, 23, 4);
  1974. };
  1975. Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
  1976. if (!noAssert) checkOffset(offset, 8, this.length);
  1977. return ieee754.read(this, offset, true, 52, 8);
  1978. };
  1979. Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
  1980. if (!noAssert) checkOffset(offset, 8, this.length);
  1981. return ieee754.read(this, offset, false, 52, 8);
  1982. };
  1983. function checkInt(buf, value, offset, ext, max, min) {
  1984. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance');
  1985. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds');
  1986. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  1987. }
  1988. Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {
  1989. value = +value;
  1990. offset = offset | 0;
  1991. byteLength = byteLength | 0;
  1992. if (!noAssert) {
  1993. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  1994. checkInt(this, value, offset, byteLength, maxBytes, 0);
  1995. }
  1996. var mul = 1;
  1997. var i = 0;
  1998. this[offset] = value & 0xFF;
  1999. while (++i < byteLength && (mul *= 0x100)) {
  2000. this[offset + i] = value / mul & 0xFF;
  2001. }
  2002. return offset + byteLength;
  2003. };
  2004. Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {
  2005. value = +value;
  2006. offset = offset | 0;
  2007. byteLength = byteLength | 0;
  2008. if (!noAssert) {
  2009. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  2010. checkInt(this, value, offset, byteLength, maxBytes, 0);
  2011. }
  2012. var i = byteLength - 1;
  2013. var mul = 1;
  2014. this[offset + i] = value & 0xFF;
  2015. while (--i >= 0 && (mul *= 0x100)) {
  2016. this[offset + i] = value / mul & 0xFF;
  2017. }
  2018. return offset + byteLength;
  2019. };
  2020. Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
  2021. value = +value;
  2022. offset = offset | 0;
  2023. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
  2024. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
  2025. this[offset] = value & 0xff;
  2026. return offset + 1;
  2027. };
  2028. function objectWriteUInt16(buf, value, offset, littleEndian) {
  2029. if (value < 0) value = 0xffff + value + 1;
  2030. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
  2031. buf[offset + i] = (value & 0xff << 8 * (littleEndian ? i : 1 - i)) >>> (littleEndian ? i : 1 - i) * 8;
  2032. }
  2033. }
  2034. Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
  2035. value = +value;
  2036. offset = offset | 0;
  2037. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  2038. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2039. this[offset] = value & 0xff;
  2040. this[offset + 1] = value >>> 8;
  2041. } else {
  2042. objectWriteUInt16(this, value, offset, true);
  2043. }
  2044. return offset + 2;
  2045. };
  2046. Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
  2047. value = +value;
  2048. offset = offset | 0;
  2049. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  2050. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2051. this[offset] = value >>> 8;
  2052. this[offset + 1] = value & 0xff;
  2053. } else {
  2054. objectWriteUInt16(this, value, offset, false);
  2055. }
  2056. return offset + 2;
  2057. };
  2058. function objectWriteUInt32(buf, value, offset, littleEndian) {
  2059. if (value < 0) value = 0xffffffff + value + 1;
  2060. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
  2061. buf[offset + i] = value >>> (littleEndian ? i : 3 - i) * 8 & 0xff;
  2062. }
  2063. }
  2064. Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
  2065. value = +value;
  2066. offset = offset | 0;
  2067. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  2068. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2069. this[offset + 3] = value >>> 24;
  2070. this[offset + 2] = value >>> 16;
  2071. this[offset + 1] = value >>> 8;
  2072. this[offset] = value & 0xff;
  2073. } else {
  2074. objectWriteUInt32(this, value, offset, true);
  2075. }
  2076. return offset + 4;
  2077. };
  2078. Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
  2079. value = +value;
  2080. offset = offset | 0;
  2081. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  2082. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2083. this[offset] = value >>> 24;
  2084. this[offset + 1] = value >>> 16;
  2085. this[offset + 2] = value >>> 8;
  2086. this[offset + 3] = value & 0xff;
  2087. } else {
  2088. objectWriteUInt32(this, value, offset, false);
  2089. }
  2090. return offset + 4;
  2091. };
  2092. Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) {
  2093. value = +value;
  2094. offset = offset | 0;
  2095. if (!noAssert) {
  2096. var limit = Math.pow(2, 8 * byteLength - 1);
  2097. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  2098. }
  2099. var i = 0;
  2100. var mul = 1;
  2101. var sub = 0;
  2102. this[offset] = value & 0xFF;
  2103. while (++i < byteLength && (mul *= 0x100)) {
  2104. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  2105. sub = 1;
  2106. }
  2107. this[offset + i] = (value / mul >> 0) - sub & 0xFF;
  2108. }
  2109. return offset + byteLength;
  2110. };
  2111. Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) {
  2112. value = +value;
  2113. offset = offset | 0;
  2114. if (!noAssert) {
  2115. var limit = Math.pow(2, 8 * byteLength - 1);
  2116. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  2117. }
  2118. var i = byteLength - 1;
  2119. var mul = 1;
  2120. var sub = 0;
  2121. this[offset + i] = value & 0xFF;
  2122. while (--i >= 0 && (mul *= 0x100)) {
  2123. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  2124. sub = 1;
  2125. }
  2126. this[offset + i] = (value / mul >> 0) - sub & 0xFF;
  2127. }
  2128. return offset + byteLength;
  2129. };
  2130. Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
  2131. value = +value;
  2132. offset = offset | 0;
  2133. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
  2134. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
  2135. if (value < 0) value = 0xff + value + 1;
  2136. this[offset] = value & 0xff;
  2137. return offset + 1;
  2138. };
  2139. Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
  2140. value = +value;
  2141. offset = offset | 0;
  2142. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  2143. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2144. this[offset] = value & 0xff;
  2145. this[offset + 1] = value >>> 8;
  2146. } else {
  2147. objectWriteUInt16(this, value, offset, true);
  2148. }
  2149. return offset + 2;
  2150. };
  2151. Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
  2152. value = +value;
  2153. offset = offset | 0;
  2154. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  2155. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2156. this[offset] = value >>> 8;
  2157. this[offset + 1] = value & 0xff;
  2158. } else {
  2159. objectWriteUInt16(this, value, offset, false);
  2160. }
  2161. return offset + 2;
  2162. };
  2163. Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
  2164. value = +value;
  2165. offset = offset | 0;
  2166. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  2167. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2168. this[offset] = value & 0xff;
  2169. this[offset + 1] = value >>> 8;
  2170. this[offset + 2] = value >>> 16;
  2171. this[offset + 3] = value >>> 24;
  2172. } else {
  2173. objectWriteUInt32(this, value, offset, true);
  2174. }
  2175. return offset + 4;
  2176. };
  2177. Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
  2178. value = +value;
  2179. offset = offset | 0;
  2180. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  2181. if (value < 0) value = 0xffffffff + value + 1;
  2182. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2183. this[offset] = value >>> 24;
  2184. this[offset + 1] = value >>> 16;
  2185. this[offset + 2] = value >>> 8;
  2186. this[offset + 3] = value & 0xff;
  2187. } else {
  2188. objectWriteUInt32(this, value, offset, false);
  2189. }
  2190. return offset + 4;
  2191. };
  2192. function checkIEEE754(buf, value, offset, ext, max, min) {
  2193. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  2194. if (offset < 0) throw new RangeError('Index out of range');
  2195. }
  2196. function writeFloat(buf, value, offset, littleEndian, noAssert) {
  2197. if (!noAssert) {
  2198. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38);
  2199. }
  2200. ieee754.write(buf, value, offset, littleEndian, 23, 4);
  2201. return offset + 4;
  2202. }
  2203. Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
  2204. return writeFloat(this, value, offset, true, noAssert);
  2205. };
  2206. Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
  2207. return writeFloat(this, value, offset, false, noAssert);
  2208. };
  2209. function writeDouble(buf, value, offset, littleEndian, noAssert) {
  2210. if (!noAssert) {
  2211. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308);
  2212. }
  2213. ieee754.write(buf, value, offset, littleEndian, 52, 8);
  2214. return offset + 8;
  2215. }
  2216. Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
  2217. return writeDouble(this, value, offset, true, noAssert);
  2218. };
  2219. Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
  2220. return writeDouble(this, value, offset, false, noAssert);
  2221. }; // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  2222. Buffer.prototype.copy = function copy(target, targetStart, start, end) {
  2223. if (!start) start = 0;
  2224. if (!end && end !== 0) end = this.length;
  2225. if (targetStart >= target.length) targetStart = target.length;
  2226. if (!targetStart) targetStart = 0;
  2227. if (end > 0 && end < start) end = start; // Copy 0 bytes; we're done
  2228. if (end === start) return 0;
  2229. if (target.length === 0 || this.length === 0) return 0; // Fatal error conditions
  2230. if (targetStart < 0) {
  2231. throw new RangeError('targetStart out of bounds');
  2232. }
  2233. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds');
  2234. if (end < 0) throw new RangeError('sourceEnd out of bounds'); // Are we oob?
  2235. if (end > this.length) end = this.length;
  2236. if (target.length - targetStart < end - start) {
  2237. end = target.length - targetStart + start;
  2238. }
  2239. var len = end - start;
  2240. var i;
  2241. if (this === target && start < targetStart && targetStart < end) {
  2242. // descending copy from end
  2243. for (i = len - 1; i >= 0; --i) {
  2244. target[i + targetStart] = this[i + start];
  2245. }
  2246. } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  2247. // ascending copy from start
  2248. for (i = 0; i < len; ++i) {
  2249. target[i + targetStart] = this[i + start];
  2250. }
  2251. } else {
  2252. Uint8Array.prototype.set.call(target, this.subarray(start, start + len), targetStart);
  2253. }
  2254. return len;
  2255. }; // Usage:
  2256. // buffer.fill(number[, offset[, end]])
  2257. // buffer.fill(buffer[, offset[, end]])
  2258. // buffer.fill(string[, offset[, end]][, encoding])
  2259. Buffer.prototype.fill = function fill(val, start, end, encoding) {
  2260. // Handle string cases:
  2261. if (typeof val === 'string') {
  2262. if (typeof start === 'string') {
  2263. encoding = start;
  2264. start = 0;
  2265. end = this.length;
  2266. } else if (typeof end === 'string') {
  2267. encoding = end;
  2268. end = this.length;
  2269. }
  2270. if (val.length === 1) {
  2271. var code = val.charCodeAt(0);
  2272. if (code < 256) {
  2273. val = code;
  2274. }
  2275. }
  2276. if (encoding !== undefined && typeof encoding !== 'string') {
  2277. throw new TypeError('encoding must be a string');
  2278. }
  2279. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  2280. throw new TypeError('Unknown encoding: ' + encoding);
  2281. }
  2282. } else if (typeof val === 'number') {
  2283. val = val & 255;
  2284. } // Invalid ranges are not set to a default, so can range check early.
  2285. if (start < 0 || this.length < start || this.length < end) {
  2286. throw new RangeError('Out of range index');
  2287. }
  2288. if (end <= start) {
  2289. return this;
  2290. }
  2291. start = start >>> 0;
  2292. end = end === undefined ? this.length : end >>> 0;
  2293. if (!val) val = 0;
  2294. var i;
  2295. if (typeof val === 'number') {
  2296. for (i = start; i < end; ++i) {
  2297. this[i] = val;
  2298. }
  2299. } else {
  2300. var bytes = Buffer.isBuffer(val) ? val : utf8ToBytes(new Buffer(val, encoding).toString());
  2301. var len = bytes.length;
  2302. for (i = 0; i < end - start; ++i) {
  2303. this[i + start] = bytes[i % len];
  2304. }
  2305. }
  2306. return this;
  2307. }; // HELPER FUNCTIONS
  2308. // ================
  2309. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
  2310. function base64clean(str) {
  2311. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  2312. str = stringtrim(str).replace(INVALID_BASE64_RE, ''); // Node converts strings with length < 2 to ''
  2313. if (str.length < 2) return ''; // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  2314. while (str.length % 4 !== 0) {
  2315. str = str + '=';
  2316. }
  2317. return str;
  2318. }
  2319. function stringtrim(str) {
  2320. if (str.trim) return str.trim();
  2321. return str.replace(/^\s+|\s+$/g, '');
  2322. }
  2323. function toHex(n) {
  2324. if (n < 16) return '0' + n.toString(16);
  2325. return n.toString(16);
  2326. }
  2327. function utf8ToBytes(string, units) {
  2328. units = units || Infinity;
  2329. var codePoint;
  2330. var length = string.length;
  2331. var leadSurrogate = null;
  2332. var bytes = [];
  2333. for (var i = 0; i < length; ++i) {
  2334. codePoint = string.charCodeAt(i); // is surrogate component
  2335. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  2336. // last char was a lead
  2337. if (!leadSurrogate) {
  2338. // no lead yet
  2339. if (codePoint > 0xDBFF) {
  2340. // unexpected trail
  2341. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  2342. continue;
  2343. } else if (i + 1 === length) {
  2344. // unpaired lead
  2345. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  2346. continue;
  2347. } // valid lead
  2348. leadSurrogate = codePoint;
  2349. continue;
  2350. } // 2 leads in a row
  2351. if (codePoint < 0xDC00) {
  2352. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  2353. leadSurrogate = codePoint;
  2354. continue;
  2355. } // valid surrogate pair
  2356. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
  2357. } else if (leadSurrogate) {
  2358. // valid bmp char, but last char was a lead
  2359. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  2360. }
  2361. leadSurrogate = null; // encode utf8
  2362. if (codePoint < 0x80) {
  2363. if ((units -= 1) < 0) break;
  2364. bytes.push(codePoint);
  2365. } else if (codePoint < 0x800) {
  2366. if ((units -= 2) < 0) break;
  2367. bytes.push(codePoint >> 0x6 | 0xC0, codePoint & 0x3F | 0x80);
  2368. } else if (codePoint < 0x10000) {
  2369. if ((units -= 3) < 0) break;
  2370. bytes.push(codePoint >> 0xC | 0xE0, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
  2371. } else if (codePoint < 0x110000) {
  2372. if ((units -= 4) < 0) break;
  2373. bytes.push(codePoint >> 0x12 | 0xF0, codePoint >> 0xC & 0x3F | 0x80, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
  2374. } else {
  2375. throw new Error('Invalid code point');
  2376. }
  2377. }
  2378. return bytes;
  2379. }
  2380. function asciiToBytes(str) {
  2381. var byteArray = [];
  2382. for (var i = 0; i < str.length; ++i) {
  2383. // Node's code seems to be doing this and not & 0x7F..
  2384. byteArray.push(str.charCodeAt(i) & 0xFF);
  2385. }
  2386. return byteArray;
  2387. }
  2388. function utf16leToBytes(str, units) {
  2389. var c, hi, lo;
  2390. var byteArray = [];
  2391. for (var i = 0; i < str.length; ++i) {
  2392. if ((units -= 2) < 0) break;
  2393. c = str.charCodeAt(i);
  2394. hi = c >> 8;
  2395. lo = c % 256;
  2396. byteArray.push(lo);
  2397. byteArray.push(hi);
  2398. }
  2399. return byteArray;
  2400. }
  2401. function base64ToBytes(str) {
  2402. return base64.toByteArray(base64clean(str));
  2403. }
  2404. function blitBuffer(src, dst, offset, length) {
  2405. for (var i = 0; i < length; ++i) {
  2406. if (i + offset >= dst.length || i >= src.length) break;
  2407. dst[i + offset] = src[i];
  2408. }
  2409. return i;
  2410. }
  2411. function isnan(val) {
  2412. return val !== val; // eslint-disable-line no-self-compare
  2413. }
  2414. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(1)))
  2415. /***/ }),
  2416. /* 6 */
  2417. /***/ (function(module, exports, __webpack_require__) {
  2418. "use strict";
  2419. exports.byteLength = byteLength;
  2420. exports.toByteArray = toByteArray;
  2421. exports.fromByteArray = fromByteArray;
  2422. var lookup = [];
  2423. var revLookup = [];
  2424. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
  2425. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  2426. for (var i = 0, len = code.length; i < len; ++i) {
  2427. lookup[i] = code[i];
  2428. revLookup[code.charCodeAt(i)] = i;
  2429. } // Support decoding URL-safe base64 strings, as Node.js does.
  2430. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  2431. revLookup['-'.charCodeAt(0)] = 62;
  2432. revLookup['_'.charCodeAt(0)] = 63;
  2433. function getLens(b64) {
  2434. var len = b64.length;
  2435. if (len % 4 > 0) {
  2436. throw new Error('Invalid string. Length must be a multiple of 4');
  2437. } // Trim off extra bytes after placeholder bytes are found
  2438. // See: https://github.com/beatgammit/base64-js/issues/42
  2439. var validLen = b64.indexOf('=');
  2440. if (validLen === -1) validLen = len;
  2441. var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
  2442. return [validLen, placeHoldersLen];
  2443. } // base64 is 4/3 + up to two characters of the original data
  2444. function byteLength(b64) {
  2445. var lens = getLens(b64);
  2446. var validLen = lens[0];
  2447. var placeHoldersLen = lens[1];
  2448. return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
  2449. }
  2450. function _byteLength(b64, validLen, placeHoldersLen) {
  2451. return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
  2452. }
  2453. function toByteArray(b64) {
  2454. var tmp;
  2455. var lens = getLens(b64);
  2456. var validLen = lens[0];
  2457. var placeHoldersLen = lens[1];
  2458. var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
  2459. var curByte = 0; // if there are placeholders, only get up to the last complete 4 chars
  2460. var len = placeHoldersLen > 0 ? validLen - 4 : validLen;
  2461. for (var i = 0; i < len; i += 4) {
  2462. tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];
  2463. arr[curByte++] = tmp >> 16 & 0xFF;
  2464. arr[curByte++] = tmp >> 8 & 0xFF;
  2465. arr[curByte++] = tmp & 0xFF;
  2466. }
  2467. if (placeHoldersLen === 2) {
  2468. tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;
  2469. arr[curByte++] = tmp & 0xFF;
  2470. }
  2471. if (placeHoldersLen === 1) {
  2472. tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;
  2473. arr[curByte++] = tmp >> 8 & 0xFF;
  2474. arr[curByte++] = tmp & 0xFF;
  2475. }
  2476. return arr;
  2477. }
  2478. function tripletToBase64(num) {
  2479. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
  2480. }
  2481. function encodeChunk(uint8, start, end) {
  2482. var tmp;
  2483. var output = [];
  2484. for (var i = start; i < end; i += 3) {
  2485. tmp = (uint8[i] << 16 & 0xFF0000) + (uint8[i + 1] << 8 & 0xFF00) + (uint8[i + 2] & 0xFF);
  2486. output.push(tripletToBase64(tmp));
  2487. }
  2488. return output.join('');
  2489. }
  2490. function fromByteArray(uint8) {
  2491. var tmp;
  2492. var len = uint8.length;
  2493. var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
  2494. var parts = [];
  2495. var maxChunkLength = 16383; // must be multiple of 3
  2496. // go through the array every three bytes, we'll deal with trailing stuff later
  2497. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  2498. parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));
  2499. } // pad the end with zeros, but make sure to not forget the extra bytes
  2500. if (extraBytes === 1) {
  2501. tmp = uint8[len - 1];
  2502. parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 0x3F] + '==');
  2503. } else if (extraBytes === 2) {
  2504. tmp = (uint8[len - 2] << 8) + uint8[len - 1];
  2505. parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 0x3F] + lookup[tmp << 2 & 0x3F] + '=');
  2506. }
  2507. return parts.join('');
  2508. }
  2509. /***/ }),
  2510. /* 7 */
  2511. /***/ (function(module, exports) {
  2512. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  2513. var e, m;
  2514. var eLen = nBytes * 8 - mLen - 1;
  2515. var eMax = (1 << eLen) - 1;
  2516. var eBias = eMax >> 1;
  2517. var nBits = -7;
  2518. var i = isLE ? nBytes - 1 : 0;
  2519. var d = isLE ? -1 : 1;
  2520. var s = buffer[offset + i];
  2521. i += d;
  2522. e = s & (1 << -nBits) - 1;
  2523. s >>= -nBits;
  2524. nBits += eLen;
  2525. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  2526. m = e & (1 << -nBits) - 1;
  2527. e >>= -nBits;
  2528. nBits += mLen;
  2529. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  2530. if (e === 0) {
  2531. e = 1 - eBias;
  2532. } else if (e === eMax) {
  2533. return m ? NaN : (s ? -1 : 1) * Infinity;
  2534. } else {
  2535. m = m + Math.pow(2, mLen);
  2536. e = e - eBias;
  2537. }
  2538. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  2539. };
  2540. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  2541. var e, m, c;
  2542. var eLen = nBytes * 8 - mLen - 1;
  2543. var eMax = (1 << eLen) - 1;
  2544. var eBias = eMax >> 1;
  2545. var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
  2546. var i = isLE ? 0 : nBytes - 1;
  2547. var d = isLE ? 1 : -1;
  2548. var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
  2549. value = Math.abs(value);
  2550. if (isNaN(value) || value === Infinity) {
  2551. m = isNaN(value) ? 1 : 0;
  2552. e = eMax;
  2553. } else {
  2554. e = Math.floor(Math.log(value) / Math.LN2);
  2555. if (value * (c = Math.pow(2, -e)) < 1) {
  2556. e--;
  2557. c *= 2;
  2558. }
  2559. if (e + eBias >= 1) {
  2560. value += rt / c;
  2561. } else {
  2562. value += rt * Math.pow(2, 1 - eBias);
  2563. }
  2564. if (value * c >= 2) {
  2565. e++;
  2566. c /= 2;
  2567. }
  2568. if (e + eBias >= eMax) {
  2569. m = 0;
  2570. e = eMax;
  2571. } else if (e + eBias >= 1) {
  2572. m = (value * c - 1) * Math.pow(2, mLen);
  2573. e = e + eBias;
  2574. } else {
  2575. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  2576. e = 0;
  2577. }
  2578. }
  2579. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  2580. e = e << mLen | m;
  2581. eLen += mLen;
  2582. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  2583. buffer[offset + i - d] |= s * 128;
  2584. };
  2585. /***/ }),
  2586. /* 8 */
  2587. /***/ (function(module, exports) {
  2588. var toString = {}.toString;
  2589. module.exports = Array.isArray || function (arr) {
  2590. return toString.call(arr) == '[object Array]';
  2591. };
  2592. /***/ }),
  2593. /* 9 */
  2594. /***/ (function(module, exports, __webpack_require__) {
  2595. /* WEBPACK VAR INJECTION */(function(module, global) {var __WEBPACK_AMD_DEFINE_RESULT__;/*! https://mths.be/utf8js v2.1.2 by @mathias */
  2596. ;
  2597. (function (root) {
  2598. // Detect free variables `exports`
  2599. var freeExports = true && exports; // Detect free variable `module`
  2600. var freeModule = true && module && module.exports == freeExports && module; // Detect free variable `global`, from Node.js or Browserified code,
  2601. // and use it as `root`
  2602. var freeGlobal = typeof global == 'object' && global;
  2603. if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
  2604. root = freeGlobal;
  2605. }
  2606. /*--------------------------------------------------------------------------*/
  2607. var stringFromCharCode = String.fromCharCode; // Taken from https://mths.be/punycode
  2608. function ucs2decode(string) {
  2609. var output = [];
  2610. var counter = 0;
  2611. var length = string.length;
  2612. var value;
  2613. var extra;
  2614. while (counter < length) {
  2615. value = string.charCodeAt(counter++);
  2616. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  2617. // high surrogate, and there is a next character
  2618. extra = string.charCodeAt(counter++);
  2619. if ((extra & 0xFC00) == 0xDC00) {
  2620. // low surrogate
  2621. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  2622. } else {
  2623. // unmatched surrogate; only append this code unit, in case the next
  2624. // code unit is the high surrogate of a surrogate pair
  2625. output.push(value);
  2626. counter--;
  2627. }
  2628. } else {
  2629. output.push(value);
  2630. }
  2631. }
  2632. return output;
  2633. } // Taken from https://mths.be/punycode
  2634. function ucs2encode(array) {
  2635. var length = array.length;
  2636. var index = -1;
  2637. var value;
  2638. var output = '';
  2639. while (++index < length) {
  2640. value = array[index];
  2641. if (value > 0xFFFF) {
  2642. value -= 0x10000;
  2643. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  2644. value = 0xDC00 | value & 0x3FF;
  2645. }
  2646. output += stringFromCharCode(value);
  2647. }
  2648. return output;
  2649. }
  2650. function checkScalarValue(codePoint) {
  2651. if (codePoint >= 0xD800 && codePoint <= 0xDFFF) {
  2652. throw Error('Lone surrogate U+' + codePoint.toString(16).toUpperCase() + ' is not a scalar value');
  2653. }
  2654. }
  2655. /*--------------------------------------------------------------------------*/
  2656. function createByte(codePoint, shift) {
  2657. return stringFromCharCode(codePoint >> shift & 0x3F | 0x80);
  2658. }
  2659. function encodeCodePoint(codePoint) {
  2660. if ((codePoint & 0xFFFFFF80) == 0) {
  2661. // 1-byte sequence
  2662. return stringFromCharCode(codePoint);
  2663. }
  2664. var symbol = '';
  2665. if ((codePoint & 0xFFFFF800) == 0) {
  2666. // 2-byte sequence
  2667. symbol = stringFromCharCode(codePoint >> 6 & 0x1F | 0xC0);
  2668. } else if ((codePoint & 0xFFFF0000) == 0) {
  2669. // 3-byte sequence
  2670. checkScalarValue(codePoint);
  2671. symbol = stringFromCharCode(codePoint >> 12 & 0x0F | 0xE0);
  2672. symbol += createByte(codePoint, 6);
  2673. } else if ((codePoint & 0xFFE00000) == 0) {
  2674. // 4-byte sequence
  2675. symbol = stringFromCharCode(codePoint >> 18 & 0x07 | 0xF0);
  2676. symbol += createByte(codePoint, 12);
  2677. symbol += createByte(codePoint, 6);
  2678. }
  2679. symbol += stringFromCharCode(codePoint & 0x3F | 0x80);
  2680. return symbol;
  2681. }
  2682. function utf8encode(string) {
  2683. var codePoints = ucs2decode(string);
  2684. var length = codePoints.length;
  2685. var index = -1;
  2686. var codePoint;
  2687. var byteString = '';
  2688. while (++index < length) {
  2689. codePoint = codePoints[index];
  2690. byteString += encodeCodePoint(codePoint);
  2691. }
  2692. return byteString;
  2693. }
  2694. /*--------------------------------------------------------------------------*/
  2695. function readContinuationByte() {
  2696. if (byteIndex >= byteCount) {
  2697. throw Error('Invalid byte index');
  2698. }
  2699. var continuationByte = byteArray[byteIndex] & 0xFF;
  2700. byteIndex++;
  2701. if ((continuationByte & 0xC0) == 0x80) {
  2702. return continuationByte & 0x3F;
  2703. } // If we end up here, it’s not a continuation byte
  2704. throw Error('Invalid continuation byte');
  2705. }
  2706. function decodeSymbol() {
  2707. var byte1;
  2708. var byte2;
  2709. var byte3;
  2710. var byte4;
  2711. var codePoint;
  2712. if (byteIndex > byteCount) {
  2713. throw Error('Invalid byte index');
  2714. }
  2715. if (byteIndex == byteCount) {
  2716. return false;
  2717. } // Read first byte
  2718. byte1 = byteArray[byteIndex] & 0xFF;
  2719. byteIndex++; // 1-byte sequence (no continuation bytes)
  2720. if ((byte1 & 0x80) == 0) {
  2721. return byte1;
  2722. } // 2-byte sequence
  2723. if ((byte1 & 0xE0) == 0xC0) {
  2724. byte2 = readContinuationByte();
  2725. codePoint = (byte1 & 0x1F) << 6 | byte2;
  2726. if (codePoint >= 0x80) {
  2727. return codePoint;
  2728. } else {
  2729. throw Error('Invalid continuation byte');
  2730. }
  2731. } // 3-byte sequence (may include unpaired surrogates)
  2732. if ((byte1 & 0xF0) == 0xE0) {
  2733. byte2 = readContinuationByte();
  2734. byte3 = readContinuationByte();
  2735. codePoint = (byte1 & 0x0F) << 12 | byte2 << 6 | byte3;
  2736. if (codePoint >= 0x0800) {
  2737. checkScalarValue(codePoint);
  2738. return codePoint;
  2739. } else {
  2740. throw Error('Invalid continuation byte');
  2741. }
  2742. } // 4-byte sequence
  2743. if ((byte1 & 0xF8) == 0xF0) {
  2744. byte2 = readContinuationByte();
  2745. byte3 = readContinuationByte();
  2746. byte4 = readContinuationByte();
  2747. codePoint = (byte1 & 0x07) << 0x12 | byte2 << 0x0C | byte3 << 0x06 | byte4;
  2748. if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) {
  2749. return codePoint;
  2750. }
  2751. }
  2752. throw Error('Invalid UTF-8 detected');
  2753. }
  2754. var byteArray;
  2755. var byteCount;
  2756. var byteIndex;
  2757. function utf8decode(byteString) {
  2758. byteArray = ucs2decode(byteString);
  2759. byteCount = byteArray.length;
  2760. byteIndex = 0;
  2761. var codePoints = [];
  2762. var tmp;
  2763. while ((tmp = decodeSymbol()) !== false) {
  2764. codePoints.push(tmp);
  2765. }
  2766. return ucs2encode(codePoints);
  2767. }
  2768. /*--------------------------------------------------------------------------*/
  2769. var utf8 = {
  2770. 'version': '2.1.2',
  2771. 'encode': utf8encode,
  2772. 'decode': utf8decode
  2773. }; // Some AMD build optimizers, like r.js, check for specific condition patterns
  2774. // like the following:
  2775. if (true) {
  2776. !(__WEBPACK_AMD_DEFINE_RESULT__ = (function () {
  2777. return utf8;
  2778. }).call(exports, __webpack_require__, exports, module),
  2779. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  2780. } else { var key, hasOwnProperty, object; }
  2781. })(this);
  2782. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(10)(module), __webpack_require__(1)))
  2783. /***/ }),
  2784. /* 10 */
  2785. /***/ (function(module, exports) {
  2786. module.exports = function (module) {
  2787. if (!module.webpackPolyfill) {
  2788. module.deprecate = function () {};
  2789. module.paths = []; // module.parent = undefined by default
  2790. if (!module.children) module.children = [];
  2791. Object.defineProperty(module, "loaded", {
  2792. enumerable: true,
  2793. get: function get() {
  2794. return module.l;
  2795. }
  2796. });
  2797. Object.defineProperty(module, "id", {
  2798. enumerable: true,
  2799. get: function get() {
  2800. return module.i;
  2801. }
  2802. });
  2803. module.webpackPolyfill = 1;
  2804. }
  2805. return module;
  2806. };
  2807. /***/ }),
  2808. /* 11 */
  2809. /***/ (function(module, exports, __webpack_require__) {
  2810. "use strict";
  2811. const types = __webpack_require__(2); // const STREAMING = 4294967295;
  2812. /**
  2813. * Read data for the given non-record variable
  2814. * @ignore
  2815. * @param {IOBuffer} buffer - Buffer for the file data
  2816. * @param {object} variable - Variable metadata
  2817. * @return {Array} - Data of the element
  2818. */
  2819. function nonRecord(buffer, variable) {
  2820. // variable type
  2821. const type = types.str2num(variable.type); // size of the data
  2822. var size = variable.size / types.num2bytes(type); // iterates over the data
  2823. var data = new Array(size);
  2824. for (var i = 0; i < size; i++) {
  2825. data[i] = types.readType(buffer, type, 1);
  2826. }
  2827. return data;
  2828. }
  2829. /**
  2830. * Read data for the given record variable
  2831. * @ignore
  2832. * @param {IOBuffer} buffer - Buffer for the file data
  2833. * @param {object} variable - Variable metadata
  2834. * @param {object} recordDimension - Record dimension metadata
  2835. * @return {Array} - Data of the element
  2836. */
  2837. function record(buffer, variable, recordDimension) {
  2838. // variable type
  2839. const type = types.str2num(variable.type);
  2840. const width = variable.size ? variable.size / types.num2bytes(type) : 1; // size of the data
  2841. // TODO streaming data
  2842. var size = recordDimension.length; // iterates over the data
  2843. var data = new Array(size);
  2844. const step = recordDimension.recordStep;
  2845. for (var i = 0; i < size; i++) {
  2846. var currentOffset = buffer.offset;
  2847. data[i] = types.readType(buffer, type, width);
  2848. buffer.seek(currentOffset + step);
  2849. }
  2850. return data;
  2851. }
  2852. module.exports.nonRecord = nonRecord;
  2853. module.exports.record = record;
  2854. /***/ }),
  2855. /* 12 */
  2856. /***/ (function(module, exports, __webpack_require__) {
  2857. "use strict";
  2858. const utils = __webpack_require__(0);
  2859. const types = __webpack_require__(2); // Grammar constants
  2860. const ZERO = 0;
  2861. const NC_DIMENSION = 10;
  2862. const NC_VARIABLE = 11;
  2863. const NC_ATTRIBUTE = 12;
  2864. /**
  2865. * Read the header of the file
  2866. * @ignore
  2867. * @param {IOBuffer} buffer - Buffer for the file data
  2868. * @param {number} version - Version of the file
  2869. * @return {object} - Object with the fields:
  2870. * * `recordDimension`: Number with the length of record dimension
  2871. * * `dimensions`: List of dimensions
  2872. * * `globalAttributes`: List of global attributes
  2873. * * `variables`: List of variables
  2874. */
  2875. function header(buffer, version) {
  2876. // Length of record dimension
  2877. // sum of the varSize's of all the record variables.
  2878. var header = {
  2879. recordDimension: {
  2880. length: buffer.readUint32()
  2881. }
  2882. }; // Version
  2883. header.version = version; // List of dimensions
  2884. var dimList = dimensionsList(buffer);
  2885. header.recordDimension.id = dimList.recordId; // id of the unlimited dimension
  2886. header.recordDimension.name = dimList.recordName; // name of the unlimited dimension
  2887. header.dimensions = dimList.dimensions; // List of global attributes
  2888. header.globalAttributes = attributesList(buffer); // List of variables
  2889. var variables = variablesList(buffer, dimList.recordId, version);
  2890. header.variables = variables.variables;
  2891. header.recordDimension.recordStep = variables.recordStep;
  2892. return header;
  2893. }
  2894. const NC_UNLIMITED = 0;
  2895. /**
  2896. * List of dimensions
  2897. * @ignore
  2898. * @param {IOBuffer} buffer - Buffer for the file data
  2899. * @return {object} - Ojbect containing the following properties:
  2900. * * `dimensions` that is an array of dimension object:
  2901. * * `name`: String with the name of the dimension
  2902. * * `size`: Number with the size of the dimension dimensions: dimensions
  2903. * * `recordId`: the id of the dimension that has unlimited size or undefined,
  2904. * * `recordName`: name of the dimension that has unlimited size
  2905. */
  2906. function dimensionsList(buffer) {
  2907. var recordId, recordName;
  2908. const dimList = buffer.readUint32();
  2909. if (dimList === ZERO) {
  2910. utils.notNetcdf(buffer.readUint32() !== ZERO, 'wrong empty tag for list of dimensions');
  2911. return [];
  2912. } else {
  2913. utils.notNetcdf(dimList !== NC_DIMENSION, 'wrong tag for list of dimensions'); // Length of dimensions
  2914. const dimensionSize = buffer.readUint32();
  2915. var dimensions = new Array(dimensionSize);
  2916. for (var dim = 0; dim < dimensionSize; dim++) {
  2917. // Read name
  2918. var name = utils.readName(buffer); // Read dimension size
  2919. const size = buffer.readUint32();
  2920. if (size === NC_UNLIMITED) {
  2921. // in netcdf 3 one field can be of size unlimmited
  2922. recordId = dim;
  2923. recordName = name;
  2924. }
  2925. dimensions[dim] = {
  2926. name: name,
  2927. size: size
  2928. };
  2929. }
  2930. }
  2931. return {
  2932. dimensions: dimensions,
  2933. recordId: recordId,
  2934. recordName: recordName
  2935. };
  2936. }
  2937. /**
  2938. * List of attributes
  2939. * @ignore
  2940. * @param {IOBuffer} buffer - Buffer for the file data
  2941. * @return {Array<object>} - List of attributes with:
  2942. * * `name`: String with the name of the attribute
  2943. * * `type`: String with the type of the attribute
  2944. * * `value`: A number or string with the value of the attribute
  2945. */
  2946. function attributesList(buffer) {
  2947. const gAttList = buffer.readUint32();
  2948. if (gAttList === ZERO) {
  2949. utils.notNetcdf(buffer.readUint32() !== ZERO, 'wrong empty tag for list of attributes');
  2950. return [];
  2951. } else {
  2952. utils.notNetcdf(gAttList !== NC_ATTRIBUTE, 'wrong tag for list of attributes'); // Length of attributes
  2953. const attributeSize = buffer.readUint32();
  2954. var attributes = new Array(attributeSize);
  2955. for (var gAtt = 0; gAtt < attributeSize; gAtt++) {
  2956. // Read name
  2957. var name = utils.readName(buffer); // Read type
  2958. var type = buffer.readUint32();
  2959. utils.notNetcdf(type < 1 || type > 6, `non valid type ${type}`); // Read attribute
  2960. var size = buffer.readUint32();
  2961. var value = types.readType(buffer, type, size); // Apply padding
  2962. utils.padding(buffer);
  2963. attributes[gAtt] = {
  2964. name: name,
  2965. type: types.num2str(type),
  2966. value: value
  2967. };
  2968. }
  2969. }
  2970. return attributes;
  2971. }
  2972. /**
  2973. * List of variables
  2974. * @ignore
  2975. * @param {IOBuffer} buffer - Buffer for the file data
  2976. * @param {number} recordId - Id of the unlimited dimension (also called record dimension)
  2977. * This value may be undefined if there is no unlimited dimension
  2978. * @param {number} version - Version of the file
  2979. * @return {object} - Number of recordStep and list of variables with:
  2980. * * `name`: String with the name of the variable
  2981. * * `dimensions`: Array with the dimension IDs of the variable
  2982. * * `attributes`: Array with the attributes of the variable
  2983. * * `type`: String with the type of the variable
  2984. * * `size`: Number with the size of the variable
  2985. * * `offset`: Number with the offset where of the variable begins
  2986. * * `record`: True if is a record variable, false otherwise (unlimited size)
  2987. */
  2988. function variablesList(buffer, recordId, version) {
  2989. const varList = buffer.readUint32();
  2990. var recordStep = 0;
  2991. if (varList === ZERO) {
  2992. utils.notNetcdf(buffer.readUint32() !== ZERO, 'wrong empty tag for list of variables');
  2993. return [];
  2994. } else {
  2995. utils.notNetcdf(varList !== NC_VARIABLE, 'wrong tag for list of variables'); // Length of variables
  2996. const variableSize = buffer.readUint32();
  2997. var variables = new Array(variableSize);
  2998. for (var v = 0; v < variableSize; v++) {
  2999. // Read name
  3000. var name = utils.readName(buffer); // Read dimensionality of the variable
  3001. const dimensionality = buffer.readUint32(); // Index into the list of dimensions
  3002. var dimensionsIds = new Array(dimensionality);
  3003. for (var dim = 0; dim < dimensionality; dim++) {
  3004. dimensionsIds[dim] = buffer.readUint32();
  3005. } // Read variables size
  3006. var attributes = attributesList(buffer); // Read type
  3007. var type = buffer.readUint32();
  3008. utils.notNetcdf(type < 1 && type > 6, `non valid type ${type}`); // Read variable size
  3009. // The 32-bit varSize field is not large enough to contain the size of variables that require
  3010. // more than 2^32 - 4 bytes, so 2^32 - 1 is used in the varSize field for such variables.
  3011. const varSize = buffer.readUint32(); // Read offset
  3012. var offset = buffer.readUint32();
  3013. if (version === 2) {
  3014. utils.notNetcdf(offset > 0, 'offsets larger than 4GB not supported');
  3015. offset = buffer.readUint32();
  3016. }
  3017. let record = false; // Count amount of record variables
  3018. if (typeof recordId !== 'undefined' && dimensionsIds[0] === recordId) {
  3019. recordStep += varSize;
  3020. record = true;
  3021. }
  3022. variables[v] = {
  3023. name: name,
  3024. dimensions: dimensionsIds,
  3025. attributes,
  3026. type: types.num2str(type),
  3027. size: varSize,
  3028. offset,
  3029. record
  3030. };
  3031. }
  3032. }
  3033. return {
  3034. variables: variables,
  3035. recordStep: recordStep
  3036. };
  3037. }
  3038. module.exports = header;
  3039. /***/ }),
  3040. /* 13 */
  3041. /***/ (function(module, exports, __webpack_require__) {
  3042. "use strict";
  3043. function toString() {
  3044. let result = [];
  3045. result.push('DIMENSIONS');
  3046. for (let dimension of this.dimensions) {
  3047. result.push(` ${dimension.name.padEnd(30)} = size: ${dimension.size}`);
  3048. }
  3049. result.push('');
  3050. result.push('GLOBAL ATTRIBUTES');
  3051. for (let attribute of this.globalAttributes) {
  3052. result.push(` ${attribute.name.padEnd(30)} = ${attribute.value}`);
  3053. }
  3054. let variables = JSON.parse(JSON.stringify(this.variables));
  3055. result.push('');
  3056. result.push('VARIABLES:');
  3057. for (let variable of variables) {
  3058. variable.value = this.getDataVariable(variable);
  3059. let stringify = JSON.stringify(variable.value);
  3060. if (stringify.length > 50) stringify = stringify.substring(0, 50);
  3061. if (!isNaN(variable.value.length)) {
  3062. stringify += ` (length: ${variable.value.length})`;
  3063. }
  3064. result.push(` ${variable.name.padEnd(30)} = ${stringify}`);
  3065. }
  3066. return result.join('\n');
  3067. }
  3068. module.exports = toString;
  3069. /***/ })
  3070. /******/ ]);
  3071. });