· 5 years ago · Nov 13, 2020, 08:40 PM
1 self.props = {
2 title: 'WeFlix',
3 default_root_id: '0AKtg8161XjbdUk9PVA',
4 client_id: '202264815644.apps.googleusercontent.com',
5 client_secret: 'X4Z3ca8xfWDb1Voo-F9a7ZxJ',
6 refresh_token: '1//04Sp83j8EhB6ECgYIARAAGAQSNwF-L9IrR37sUSAuTrwUyAffdiAx3OvlC3httWVKnYKLLYUcwcodS2Hfx9p8QgzcVgFmsPYUcco',
7 service_account: false,
8 service_account_json: {},
9 auth: true,
10 user: 'Weflix',
11 pass: 'Internetshub',
12 upload: true,
13 lite: false
14 };
15(function () {
16 'use strict';
17
18 /**
19 * @param typeMap [Object] Map of MIME type -> Array[extensions]
20 * @param ...
21 */
22 function Mime() {
23 this._types = Object.create(null);
24 this._extensions = Object.create(null);
25
26 for (var i = 0; i < arguments.length; i++) {
27 this.define(arguments[i]);
28 }
29
30 this.define = this.define.bind(this);
31 this.getType = this.getType.bind(this);
32 this.getExtension = this.getExtension.bind(this);
33 }
34
35 /**
36 * Define mimetype -> extension mappings. Each key is a mime-type that maps
37 * to an array of extensions associated with the type. The first extension is
38 * used as the default extension for the type.
39 *
40 * e.g. mime.define({'audio/ogg', ['oga', 'ogg', 'spx']});
41 *
42 * If a type declares an extension that has already been defined, an error will
43 * be thrown. To suppress this error and force the extension to be associated
44 * with the new type, pass `force`=true. Alternatively, you may prefix the
45 * extension with "*" to map the type to extension, without mapping the
46 * extension to the type.
47 *
48 * e.g. mime.define({'audio/wav', ['wav']}, {'audio/x-wav', ['*wav']});
49 *
50 *
51 * @param map (Object) type definitions
52 * @param force (Boolean) if true, force overriding of existing definitions
53 */
54 Mime.prototype.define = function(typeMap, force) {
55 for (var type in typeMap) {
56 var extensions = typeMap[type].map(function(t) {return t.toLowerCase()});
57 type = type.toLowerCase();
58
59 for (var i = 0; i < extensions.length; i++) {
60 var ext = extensions[i];
61
62 // '*' prefix = not the preferred type for this extension. So fixup the
63 // extension, and skip it.
64 if (ext[0] == '*') {
65 continue;
66 }
67
68 if (!force && (ext in this._types)) {
69 throw new Error(
70 'Attempt to change mapping for "' + ext +
71 '" extension from "' + this._types[ext] + '" to "' + type +
72 '". Pass `force=true` to allow this, otherwise remove "' + ext +
73 '" from the list of extensions for "' + type + '".'
74 );
75 }
76
77 this._types[ext] = type;
78 }
79
80 // Use first extension as default
81 if (force || !this._extensions[type]) {
82 var ext = extensions[0];
83 this._extensions[type] = (ext[0] != '*') ? ext : ext.substr(1);
84 }
85 }
86 };
87
88 /**
89 * Lookup a mime type based on extension
90 */
91 Mime.prototype.getType = function(path) {
92 path = String(path);
93 var last = path.replace(/^.*[/\\]/, '').toLowerCase();
94 var ext = last.replace(/^.*\./, '').toLowerCase();
95
96 var hasPath = last.length < path.length;
97 var hasDot = ext.length < last.length - 1;
98
99 return (hasDot || !hasPath) && this._types[ext] || null;
100 };
101
102 /**
103 * Return file extension associated with a mime type
104 */
105 Mime.prototype.getExtension = function(type) {
106 type = /^\s*([^;\s]*)/.test(type) && RegExp.$1;
107 return type && this._extensions[type.toLowerCase()] || null;
108 };
109
110 var Mime_1 = Mime;
111
112 var standard = {"application/andrew-inset":["ez"],"application/applixware":["aw"],"application/atom+xml":["atom"],"application/atomcat+xml":["atomcat"],"application/atomdeleted+xml":["atomdeleted"],"application/atomsvc+xml":["atomsvc"],"application/atsc-dwd+xml":["dwd"],"application/atsc-held+xml":["held"],"application/atsc-rsat+xml":["rsat"],"application/bdoc":["bdoc"],"application/calendar+xml":["xcs"],"application/ccxml+xml":["ccxml"],"application/cdfx+xml":["cdfx"],"application/cdmi-capability":["cdmia"],"application/cdmi-container":["cdmic"],"application/cdmi-domain":["cdmid"],"application/cdmi-object":["cdmio"],"application/cdmi-queue":["cdmiq"],"application/cu-seeme":["cu"],"application/dash+xml":["mpd"],"application/davmount+xml":["davmount"],"application/docbook+xml":["dbk"],"application/dssc+der":["dssc"],"application/dssc+xml":["xdssc"],"application/ecmascript":["ecma","es"],"application/emma+xml":["emma"],"application/emotionml+xml":["emotionml"],"application/epub+zip":["epub"],"application/exi":["exi"],"application/fdt+xml":["fdt"],"application/font-tdpfr":["pfr"],"application/geo+json":["geojson"],"application/gml+xml":["gml"],"application/gpx+xml":["gpx"],"application/gxf":["gxf"],"application/gzip":["gz"],"application/hjson":["hjson"],"application/hyperstudio":["stk"],"application/inkml+xml":["ink","inkml"],"application/ipfix":["ipfix"],"application/its+xml":["its"],"application/java-archive":["jar","war","ear"],"application/java-serialized-object":["ser"],"application/java-vm":["class"],"application/javascript":["js","mjs"],"application/json":["json","map"],"application/json5":["json5"],"application/jsonml+json":["jsonml"],"application/ld+json":["jsonld"],"application/lgr+xml":["lgr"],"application/lost+xml":["lostxml"],"application/mac-binhex40":["hqx"],"application/mac-compactpro":["cpt"],"application/mads+xml":["mads"],"application/manifest+json":["webmanifest"],"application/marc":["mrc"],"application/marcxml+xml":["mrcx"],"application/mathematica":["ma","nb","mb"],"application/mathml+xml":["mathml"],"application/mbox":["mbox"],"application/mediaservercontrol+xml":["mscml"],"application/metalink+xml":["metalink"],"application/metalink4+xml":["meta4"],"application/mets+xml":["mets"],"application/mmt-aei+xml":["maei"],"application/mmt-usd+xml":["musd"],"application/mods+xml":["mods"],"application/mp21":["m21","mp21"],"application/mp4":["mp4s","m4p"],"application/mrb-consumer+xml":["*xdf"],"application/mrb-publish+xml":["*xdf"],"application/msword":["doc","dot"],"application/mxf":["mxf"],"application/n-quads":["nq"],"application/n-triples":["nt"],"application/node":["cjs"],"application/octet-stream":["bin","dms","lrf","mar","so","dist","distz","pkg","bpk","dump","elc","deploy","exe","dll","deb","dmg","iso","img","msi","msp","msm","buffer"],"application/oda":["oda"],"application/oebps-package+xml":["opf"],"application/ogg":["ogx"],"application/omdoc+xml":["omdoc"],"application/onenote":["onetoc","onetoc2","onetmp","onepkg"],"application/oxps":["oxps"],"application/p2p-overlay+xml":["relo"],"application/patch-ops-error+xml":["*xer"],"application/pdf":["pdf"],"application/pgp-encrypted":["pgp"],"application/pgp-signature":["asc","sig"],"application/pics-rules":["prf"],"application/pkcs10":["p10"],"application/pkcs7-mime":["p7m","p7c"],"application/pkcs7-signature":["p7s"],"application/pkcs8":["p8"],"application/pkix-attr-cert":["ac"],"application/pkix-cert":["cer"],"application/pkix-crl":["crl"],"application/pkix-pkipath":["pkipath"],"application/pkixcmp":["pki"],"application/pls+xml":["pls"],"application/postscript":["ai","eps","ps"],"application/provenance+xml":["provx"],"application/pskc+xml":["pskcxml"],"application/raml+yaml":["raml"],"application/rdf+xml":["rdf","owl"],"application/reginfo+xml":["rif"],"application/relax-ng-compact-syntax":["rnc"],"application/resource-lists+xml":["rl"],"application/resource-lists-diff+xml":["rld"],"application/rls-services+xml":["rs"],"application/route-apd+xml":["rapd"],"application/route-s-tsid+xml":["sls"],"application/route-usd+xml":["rusd"],"application/rpki-ghostbusters":["gbr"],"application/rpki-manifest":["mft"],"application/rpki-roa":["roa"],"application/rsd+xml":["rsd"],"application/rss+xml":["rss"],"application/rtf":["rtf"],"application/sbml+xml":["sbml"],"application/scvp-cv-request":["scq"],"application/scvp-cv-response":["scs"],"application/scvp-vp-request":["spq"],"application/scvp-vp-response":["spp"],"application/sdp":["sdp"],"application/senml+xml":["senmlx"],"application/sensml+xml":["sensmlx"],"application/set-payment-initiation":["setpay"],"application/set-registration-initiation":["setreg"],"application/shf+xml":["shf"],"application/sieve":["siv","sieve"],"application/smil+xml":["smi","smil"],"application/sparql-query":["rq"],"application/sparql-results+xml":["srx"],"application/srgs":["gram"],"application/srgs+xml":["grxml"],"application/sru+xml":["sru"],"application/ssdl+xml":["ssdl"],"application/ssml+xml":["ssml"],"application/swid+xml":["swidtag"],"application/tei+xml":["tei","teicorpus"],"application/thraud+xml":["tfi"],"application/timestamped-data":["tsd"],"application/toml":["toml"],"application/ttml+xml":["ttml"],"application/urc-ressheet+xml":["rsheet"],"application/voicexml+xml":["vxml"],"application/wasm":["wasm"],"application/widget":["wgt"],"application/winhlp":["hlp"],"application/wsdl+xml":["wsdl"],"application/wspolicy+xml":["wspolicy"],"application/xaml+xml":["xaml"],"application/xcap-att+xml":["xav"],"application/xcap-caps+xml":["xca"],"application/xcap-diff+xml":["xdf"],"application/xcap-el+xml":["xel"],"application/xcap-error+xml":["xer"],"application/xcap-ns+xml":["xns"],"application/xenc+xml":["xenc"],"application/xhtml+xml":["xhtml","xht"],"application/xliff+xml":["xlf"],"application/xml":["xml","xsl","xsd","rng"],"application/xml-dtd":["dtd"],"application/xop+xml":["xop"],"application/xproc+xml":["xpl"],"application/xslt+xml":["xslt"],"application/xspf+xml":["xspf"],"application/xv+xml":["mxml","xhvml","xvml","xvm"],"application/yang":["yang"],"application/yin+xml":["yin"],"application/zip":["zip"],"audio/3gpp":["*3gpp"],"audio/adpcm":["adp"],"audio/basic":["au","snd"],"audio/midi":["mid","midi","kar","rmi"],"audio/mobile-xmf":["mxmf"],"audio/mp3":["*mp3"],"audio/mp4":["m4a","mp4a"],"audio/mpeg":["mpga","mp2","mp2a","mp3","m2a","m3a"],"audio/ogg":["oga","ogg","spx"],"audio/s3m":["s3m"],"audio/silk":["sil"],"audio/wav":["wav"],"audio/wave":["*wav"],"audio/webm":["weba"],"audio/xm":["xm"],"font/collection":["ttc"],"font/otf":["otf"],"font/ttf":["ttf"],"font/woff":["woff"],"font/woff2":["woff2"],"image/aces":["exr"],"image/apng":["apng"],"image/bmp":["bmp"],"image/cgm":["cgm"],"image/dicom-rle":["drle"],"image/emf":["emf"],"image/fits":["fits"],"image/g3fax":["g3"],"image/gif":["gif"],"image/heic":["heic"],"image/heic-sequence":["heics"],"image/heif":["heif"],"image/heif-sequence":["heifs"],"image/hej2k":["hej2"],"image/hsj2":["hsj2"],"image/ief":["ief"],"image/jls":["jls"],"image/jp2":["jp2","jpg2"],"image/jpeg":["jpeg","jpg","jpe"],"image/jph":["jph"],"image/jphc":["jhc"],"image/jpm":["jpm"],"image/jpx":["jpx","jpf"],"image/jxr":["jxr"],"image/jxra":["jxra"],"image/jxrs":["jxrs"],"image/jxs":["jxs"],"image/jxsc":["jxsc"],"image/jxsi":["jxsi"],"image/jxss":["jxss"],"image/ktx":["ktx"],"image/png":["png"],"image/sgi":["sgi"],"image/svg+xml":["svg","svgz"],"image/t38":["t38"],"image/tiff":["tif","tiff"],"image/tiff-fx":["tfx"],"image/webp":["webp"],"image/wmf":["wmf"],"message/disposition-notification":["disposition-notification"],"message/global":["u8msg"],"message/global-delivery-status":["u8dsn"],"message/global-disposition-notification":["u8mdn"],"message/global-headers":["u8hdr"],"message/rfc822":["eml","mime"],"model/3mf":["3mf"],"model/gltf+json":["gltf"],"model/gltf-binary":["glb"],"model/iges":["igs","iges"],"model/mesh":["msh","mesh","silo"],"model/mtl":["mtl"],"model/obj":["obj"],"model/stl":["stl"],"model/vrml":["wrl","vrml"],"model/x3d+binary":["*x3db","x3dbz"],"model/x3d+fastinfoset":["x3db"],"model/x3d+vrml":["*x3dv","x3dvz"],"model/x3d+xml":["x3d","x3dz"],"model/x3d-vrml":["x3dv"],"text/cache-manifest":["appcache","manifest"],"text/calendar":["ics","ifb"],"text/coffeescript":["coffee","litcoffee"],"text/css":["css"],"text/csv":["csv"],"text/html":["html","htm","shtml"],"text/jade":["jade"],"text/jsx":["jsx"],"text/less":["less"],"text/markdown":["markdown","md"],"text/mathml":["mml"],"text/mdx":["mdx"],"text/n3":["n3"],"text/plain":["txt","text","conf","def","list","log","in","ini"],"text/richtext":["rtx"],"text/rtf":["*rtf"],"text/sgml":["sgml","sgm"],"text/shex":["shex"],"text/slim":["slim","slm"],"text/stylus":["stylus","styl"],"text/tab-separated-values":["tsv"],"text/troff":["t","tr","roff","man","me","ms"],"text/turtle":["ttl"],"text/uri-list":["uri","uris","urls"],"text/vcard":["vcard"],"text/vtt":["vtt"],"text/xml":["*xml"],"text/yaml":["yaml","yml"],"video/3gpp":["3gp","3gpp"],"video/3gpp2":["3g2"],"video/h261":["h261"],"video/h263":["h263"],"video/h264":["h264"],"video/jpeg":["jpgv"],"video/jpm":["*jpm","jpgm"],"video/mj2":["mj2","mjp2"],"video/mp2t":["ts"],"video/mp4":["mp4","mp4v","mpg4"],"video/mpeg":["mpeg","mpg","mpe","m1v","m2v"],"video/ogg":["ogv"],"video/quicktime":["qt","mov"],"video/webm":["webm"]};
113
114 var other = {"application/prs.cww":["cww"],"application/vnd.1000minds.decision-model+xml":["1km"],"application/vnd.3gpp.pic-bw-large":["plb"],"application/vnd.3gpp.pic-bw-small":["psb"],"application/vnd.3gpp.pic-bw-var":["pvb"],"application/vnd.3gpp2.tcap":["tcap"],"application/vnd.3m.post-it-notes":["pwn"],"application/vnd.accpac.simply.aso":["aso"],"application/vnd.accpac.simply.imp":["imp"],"application/vnd.acucobol":["acu"],"application/vnd.acucorp":["atc","acutc"],"application/vnd.adobe.air-application-installer-package+zip":["air"],"application/vnd.adobe.formscentral.fcdt":["fcdt"],"application/vnd.adobe.fxp":["fxp","fxpl"],"application/vnd.adobe.xdp+xml":["xdp"],"application/vnd.adobe.xfdf":["xfdf"],"application/vnd.ahead.space":["ahead"],"application/vnd.airzip.filesecure.azf":["azf"],"application/vnd.airzip.filesecure.azs":["azs"],"application/vnd.amazon.ebook":["azw"],"application/vnd.americandynamics.acc":["acc"],"application/vnd.amiga.ami":["ami"],"application/vnd.android.package-archive":["apk"],"application/vnd.anser-web-certificate-issue-initiation":["cii"],"application/vnd.anser-web-funds-transfer-initiation":["fti"],"application/vnd.antix.game-component":["atx"],"application/vnd.apple.installer+xml":["mpkg"],"application/vnd.apple.keynote":["keynote"],"application/vnd.apple.mpegurl":["m3u8"],"application/vnd.apple.numbers":["numbers"],"application/vnd.apple.pages":["pages"],"application/vnd.apple.pkpass":["pkpass"],"application/vnd.aristanetworks.swi":["swi"],"application/vnd.astraea-software.iota":["iota"],"application/vnd.audiograph":["aep"],"application/vnd.balsamiq.bmml+xml":["bmml"],"application/vnd.blueice.multipass":["mpm"],"application/vnd.bmi":["bmi"],"application/vnd.businessobjects":["rep"],"application/vnd.chemdraw+xml":["cdxml"],"application/vnd.chipnuts.karaoke-mmd":["mmd"],"application/vnd.cinderella":["cdy"],"application/vnd.citationstyles.style+xml":["csl"],"application/vnd.claymore":["cla"],"application/vnd.cloanto.rp9":["rp9"],"application/vnd.clonk.c4group":["c4g","c4d","c4f","c4p","c4u"],"application/vnd.cluetrust.cartomobile-config":["c11amc"],"application/vnd.cluetrust.cartomobile-config-pkg":["c11amz"],"application/vnd.commonspace":["csp"],"application/vnd.contact.cmsg":["cdbcmsg"],"application/vnd.cosmocaller":["cmc"],"application/vnd.crick.clicker":["clkx"],"application/vnd.crick.clicker.keyboard":["clkk"],"application/vnd.crick.clicker.palette":["clkp"],"application/vnd.crick.clicker.template":["clkt"],"application/vnd.crick.clicker.wordbank":["clkw"],"application/vnd.criticaltools.wbs+xml":["wbs"],"application/vnd.ctc-posml":["pml"],"application/vnd.cups-ppd":["ppd"],"application/vnd.curl.car":["car"],"application/vnd.curl.pcurl":["pcurl"],"application/vnd.dart":["dart"],"application/vnd.data-vision.rdz":["rdz"],"application/vnd.dece.data":["uvf","uvvf","uvd","uvvd"],"application/vnd.dece.ttml+xml":["uvt","uvvt"],"application/vnd.dece.unspecified":["uvx","uvvx"],"application/vnd.dece.zip":["uvz","uvvz"],"application/vnd.denovo.fcselayout-link":["fe_launch"],"application/vnd.dna":["dna"],"application/vnd.dolby.mlp":["mlp"],"application/vnd.dpgraph":["dpg"],"application/vnd.dreamfactory":["dfac"],"application/vnd.ds-keypoint":["kpxx"],"application/vnd.dvb.ait":["ait"],"application/vnd.dvb.service":["svc"],"application/vnd.dynageo":["geo"],"application/vnd.ecowin.chart":["mag"],"application/vnd.enliven":["nml"],"application/vnd.epson.esf":["esf"],"application/vnd.epson.msf":["msf"],"application/vnd.epson.quickanime":["qam"],"application/vnd.epson.salt":["slt"],"application/vnd.epson.ssf":["ssf"],"application/vnd.eszigno3+xml":["es3","et3"],"application/vnd.ezpix-album":["ez2"],"application/vnd.ezpix-package":["ez3"],"application/vnd.fdf":["fdf"],"application/vnd.fdsn.mseed":["mseed"],"application/vnd.fdsn.seed":["seed","dataless"],"application/vnd.flographit":["gph"],"application/vnd.fluxtime.clip":["ftc"],"application/vnd.framemaker":["fm","frame","maker","book"],"application/vnd.frogans.fnc":["fnc"],"application/vnd.frogans.ltf":["ltf"],"application/vnd.fsc.weblaunch":["fsc"],"application/vnd.fujitsu.oasys":["oas"],"application/vnd.fujitsu.oasys2":["oa2"],"application/vnd.fujitsu.oasys3":["oa3"],"application/vnd.fujitsu.oasysgp":["fg5"],"application/vnd.fujitsu.oasysprs":["bh2"],"application/vnd.fujixerox.ddd":["ddd"],"application/vnd.fujixerox.docuworks":["xdw"],"application/vnd.fujixerox.docuworks.binder":["xbd"],"application/vnd.fuzzysheet":["fzs"],"application/vnd.genomatix.tuxedo":["txd"],"application/vnd.geogebra.file":["ggb"],"application/vnd.geogebra.tool":["ggt"],"application/vnd.geometry-explorer":["gex","gre"],"application/vnd.geonext":["gxt"],"application/vnd.geoplan":["g2w"],"application/vnd.geospace":["g3w"],"application/vnd.gmx":["gmx"],"application/vnd.google-apps.document":["gdoc"],"application/vnd.google-apps.presentation":["gslides"],"application/vnd.google-apps.spreadsheet":["gsheet"],"application/vnd.google-earth.kml+xml":["kml"],"application/vnd.google-earth.kmz":["kmz"],"application/vnd.grafeq":["gqf","gqs"],"application/vnd.groove-account":["gac"],"application/vnd.groove-help":["ghf"],"application/vnd.groove-identity-message":["gim"],"application/vnd.groove-injector":["grv"],"application/vnd.groove-tool-message":["gtm"],"application/vnd.groove-tool-template":["tpl"],"application/vnd.groove-vcard":["vcg"],"application/vnd.hal+xml":["hal"],"application/vnd.handheld-entertainment+xml":["zmm"],"application/vnd.hbci":["hbci"],"application/vnd.hhe.lesson-player":["les"],"application/vnd.hp-hpgl":["hpgl"],"application/vnd.hp-hpid":["hpid"],"application/vnd.hp-hps":["hps"],"application/vnd.hp-jlyt":["jlt"],"application/vnd.hp-pcl":["pcl"],"application/vnd.hp-pclxl":["pclxl"],"application/vnd.hydrostatix.sof-data":["sfd-hdstx"],"application/vnd.ibm.minipay":["mpy"],"application/vnd.ibm.modcap":["afp","listafp","list3820"],"application/vnd.ibm.rights-management":["irm"],"application/vnd.ibm.secure-container":["sc"],"application/vnd.iccprofile":["icc","icm"],"application/vnd.igloader":["igl"],"application/vnd.immervision-ivp":["ivp"],"application/vnd.immervision-ivu":["ivu"],"application/vnd.insors.igm":["igm"],"application/vnd.intercon.formnet":["xpw","xpx"],"application/vnd.intergeo":["i2g"],"application/vnd.intu.qbo":["qbo"],"application/vnd.intu.qfx":["qfx"],"application/vnd.ipunplugged.rcprofile":["rcprofile"],"application/vnd.irepository.package+xml":["irp"],"application/vnd.is-xpr":["xpr"],"application/vnd.isac.fcs":["fcs"],"application/vnd.jam":["jam"],"application/vnd.jcp.javame.midlet-rms":["rms"],"application/vnd.jisp":["jisp"],"application/vnd.joost.joda-archive":["joda"],"application/vnd.kahootz":["ktz","ktr"],"application/vnd.kde.karbon":["karbon"],"application/vnd.kde.kchart":["chrt"],"application/vnd.kde.kformula":["kfo"],"application/vnd.kde.kivio":["flw"],"application/vnd.kde.kontour":["kon"],"application/vnd.kde.kpresenter":["kpr","kpt"],"application/vnd.kde.kspread":["ksp"],"application/vnd.kde.kword":["kwd","kwt"],"application/vnd.kenameaapp":["htke"],"application/vnd.kidspiration":["kia"],"application/vnd.kinar":["kne","knp"],"application/vnd.koan":["skp","skd","skt","skm"],"application/vnd.kodak-descriptor":["sse"],"application/vnd.las.las+xml":["lasxml"],"application/vnd.llamagraphics.life-balance.desktop":["lbd"],"application/vnd.llamagraphics.life-balance.exchange+xml":["lbe"],"application/vnd.lotus-1-2-3":["123"],"application/vnd.lotus-approach":["apr"],"application/vnd.lotus-freelance":["pre"],"application/vnd.lotus-notes":["nsf"],"application/vnd.lotus-organizer":["org"],"application/vnd.lotus-screencam":["scm"],"application/vnd.lotus-wordpro":["lwp"],"application/vnd.macports.portpkg":["portpkg"],"application/vnd.mcd":["mcd"],"application/vnd.medcalcdata":["mc1"],"application/vnd.mediastation.cdkey":["cdkey"],"application/vnd.mfer":["mwf"],"application/vnd.mfmp":["mfm"],"application/vnd.micrografx.flo":["flo"],"application/vnd.micrografx.igx":["igx"],"application/vnd.mif":["mif"],"application/vnd.mobius.daf":["daf"],"application/vnd.mobius.dis":["dis"],"application/vnd.mobius.mbk":["mbk"],"application/vnd.mobius.mqy":["mqy"],"application/vnd.mobius.msl":["msl"],"application/vnd.mobius.plc":["plc"],"application/vnd.mobius.txf":["txf"],"application/vnd.mophun.application":["mpn"],"application/vnd.mophun.certificate":["mpc"],"application/vnd.mozilla.xul+xml":["xul"],"application/vnd.ms-artgalry":["cil"],"application/vnd.ms-cab-compressed":["cab"],"application/vnd.ms-excel":["xls","xlm","xla","xlc","xlt","xlw"],"application/vnd.ms-excel.addin.macroenabled.12":["xlam"],"application/vnd.ms-excel.sheet.binary.macroenabled.12":["xlsb"],"application/vnd.ms-excel.sheet.macroenabled.12":["xlsm"],"application/vnd.ms-excel.template.macroenabled.12":["xltm"],"application/vnd.ms-fontobject":["eot"],"application/vnd.ms-htmlhelp":["chm"],"application/vnd.ms-ims":["ims"],"application/vnd.ms-lrm":["lrm"],"application/vnd.ms-officetheme":["thmx"],"application/vnd.ms-outlook":["msg"],"application/vnd.ms-pki.seccat":["cat"],"application/vnd.ms-pki.stl":["*stl"],"application/vnd.ms-powerpoint":["ppt","pps","pot"],"application/vnd.ms-powerpoint.addin.macroenabled.12":["ppam"],"application/vnd.ms-powerpoint.presentation.macroenabled.12":["pptm"],"application/vnd.ms-powerpoint.slide.macroenabled.12":["sldm"],"application/vnd.ms-powerpoint.slideshow.macroenabled.12":["ppsm"],"application/vnd.ms-powerpoint.template.macroenabled.12":["potm"],"application/vnd.ms-project":["mpp","mpt"],"application/vnd.ms-word.document.macroenabled.12":["docm"],"application/vnd.ms-word.template.macroenabled.12":["dotm"],"application/vnd.ms-works":["wps","wks","wcm","wdb"],"application/vnd.ms-wpl":["wpl"],"application/vnd.ms-xpsdocument":["xps"],"application/vnd.mseq":["mseq"],"application/vnd.musician":["mus"],"application/vnd.muvee.style":["msty"],"application/vnd.mynfc":["taglet"],"application/vnd.neurolanguage.nlu":["nlu"],"application/vnd.nitf":["ntf","nitf"],"application/vnd.noblenet-directory":["nnd"],"application/vnd.noblenet-sealer":["nns"],"application/vnd.noblenet-web":["nnw"],"application/vnd.nokia.n-gage.ac+xml":["*ac"],"application/vnd.nokia.n-gage.data":["ngdat"],"application/vnd.nokia.n-gage.symbian.install":["n-gage"],"application/vnd.nokia.radio-preset":["rpst"],"application/vnd.nokia.radio-presets":["rpss"],"application/vnd.novadigm.edm":["edm"],"application/vnd.novadigm.edx":["edx"],"application/vnd.novadigm.ext":["ext"],"application/vnd.oasis.opendocument.chart":["odc"],"application/vnd.oasis.opendocument.chart-template":["otc"],"application/vnd.oasis.opendocument.database":["odb"],"application/vnd.oasis.opendocument.formula":["odf"],"application/vnd.oasis.opendocument.formula-template":["odft"],"application/vnd.oasis.opendocument.graphics":["odg"],"application/vnd.oasis.opendocument.graphics-template":["otg"],"application/vnd.oasis.opendocument.image":["odi"],"application/vnd.oasis.opendocument.image-template":["oti"],"application/vnd.oasis.opendocument.presentation":["odp"],"application/vnd.oasis.opendocument.presentation-template":["otp"],"application/vnd.oasis.opendocument.spreadsheet":["ods"],"application/vnd.oasis.opendocument.spreadsheet-template":["ots"],"application/vnd.oasis.opendocument.text":["odt"],"application/vnd.oasis.opendocument.text-master":["odm"],"application/vnd.oasis.opendocument.text-template":["ott"],"application/vnd.oasis.opendocument.text-web":["oth"],"application/vnd.olpc-sugar":["xo"],"application/vnd.oma.dd2+xml":["dd2"],"application/vnd.openblox.game+xml":["obgx"],"application/vnd.openofficeorg.extension":["oxt"],"application/vnd.openstreetmap.data+xml":["osm"],"application/vnd.openxmlformats-officedocument.presentationml.presentation":["pptx"],"application/vnd.openxmlformats-officedocument.presentationml.slide":["sldx"],"application/vnd.openxmlformats-officedocument.presentationml.slideshow":["ppsx"],"application/vnd.openxmlformats-officedocument.presentationml.template":["potx"],"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":["xlsx"],"application/vnd.openxmlformats-officedocument.spreadsheetml.template":["xltx"],"application/vnd.openxmlformats-officedocument.wordprocessingml.document":["docx"],"application/vnd.openxmlformats-officedocument.wordprocessingml.template":["dotx"],"application/vnd.osgeo.mapguide.package":["mgp"],"application/vnd.osgi.dp":["dp"],"application/vnd.osgi.subsystem":["esa"],"application/vnd.palm":["pdb","pqa","oprc"],"application/vnd.pawaafile":["paw"],"application/vnd.pg.format":["str"],"application/vnd.pg.osasli":["ei6"],"application/vnd.picsel":["efif"],"application/vnd.pmi.widget":["wg"],"application/vnd.pocketlearn":["plf"],"application/vnd.powerbuilder6":["pbd"],"application/vnd.previewsystems.box":["box"],"application/vnd.proteus.magazine":["mgz"],"application/vnd.publishare-delta-tree":["qps"],"application/vnd.pvi.ptid1":["ptid"],"application/vnd.quark.quarkxpress":["qxd","qxt","qwd","qwt","qxl","qxb"],"application/vnd.realvnc.bed":["bed"],"application/vnd.recordare.musicxml":["mxl"],"application/vnd.recordare.musicxml+xml":["musicxml"],"application/vnd.rig.cryptonote":["cryptonote"],"application/vnd.rim.cod":["cod"],"application/vnd.rn-realmedia":["rm"],"application/vnd.rn-realmedia-vbr":["rmvb"],"application/vnd.route66.link66+xml":["link66"],"application/vnd.sailingtracker.track":["st"],"application/vnd.seemail":["see"],"application/vnd.sema":["sema"],"application/vnd.semd":["semd"],"application/vnd.semf":["semf"],"application/vnd.shana.informed.formdata":["ifm"],"application/vnd.shana.informed.formtemplate":["itp"],"application/vnd.shana.informed.interchange":["iif"],"application/vnd.shana.informed.package":["ipk"],"application/vnd.simtech-mindmapper":["twd","twds"],"application/vnd.smaf":["mmf"],"application/vnd.smart.teacher":["teacher"],"application/vnd.software602.filler.form+xml":["fo"],"application/vnd.solent.sdkm+xml":["sdkm","sdkd"],"application/vnd.spotfire.dxp":["dxp"],"application/vnd.spotfire.sfs":["sfs"],"application/vnd.stardivision.calc":["sdc"],"application/vnd.stardivision.draw":["sda"],"application/vnd.stardivision.impress":["sdd"],"application/vnd.stardivision.math":["smf"],"application/vnd.stardivision.writer":["sdw","vor"],"application/vnd.stardivision.writer-global":["sgl"],"application/vnd.stepmania.package":["smzip"],"application/vnd.stepmania.stepchart":["sm"],"application/vnd.sun.wadl+xml":["wadl"],"application/vnd.sun.xml.calc":["sxc"],"application/vnd.sun.xml.calc.template":["stc"],"application/vnd.sun.xml.draw":["sxd"],"application/vnd.sun.xml.draw.template":["std"],"application/vnd.sun.xml.impress":["sxi"],"application/vnd.sun.xml.impress.template":["sti"],"application/vnd.sun.xml.math":["sxm"],"application/vnd.sun.xml.writer":["sxw"],"application/vnd.sun.xml.writer.global":["sxg"],"application/vnd.sun.xml.writer.template":["stw"],"application/vnd.sus-calendar":["sus","susp"],"application/vnd.svd":["svd"],"application/vnd.symbian.install":["sis","sisx"],"application/vnd.syncml+xml":["xsm"],"application/vnd.syncml.dm+wbxml":["bdm"],"application/vnd.syncml.dm+xml":["xdm"],"application/vnd.syncml.dmddf+xml":["ddf"],"application/vnd.tao.intent-module-archive":["tao"],"application/vnd.tcpdump.pcap":["pcap","cap","dmp"],"application/vnd.tmobile-livetv":["tmo"],"application/vnd.trid.tpt":["tpt"],"application/vnd.triscape.mxs":["mxs"],"application/vnd.trueapp":["tra"],"application/vnd.ufdl":["ufd","ufdl"],"application/vnd.uiq.theme":["utz"],"application/vnd.umajin":["umj"],"application/vnd.unity":["unityweb"],"application/vnd.uoml+xml":["uoml"],"application/vnd.vcx":["vcx"],"application/vnd.visio":["vsd","vst","vss","vsw"],"application/vnd.visionary":["vis"],"application/vnd.vsf":["vsf"],"application/vnd.wap.wbxml":["wbxml"],"application/vnd.wap.wmlc":["wmlc"],"application/vnd.wap.wmlscriptc":["wmlsc"],"application/vnd.webturbo":["wtb"],"application/vnd.wolfram.player":["nbp"],"application/vnd.wordperfect":["wpd"],"application/vnd.wqd":["wqd"],"application/vnd.wt.stf":["stf"],"application/vnd.xara":["xar"],"application/vnd.xfdl":["xfdl"],"application/vnd.yamaha.hv-dic":["hvd"],"application/vnd.yamaha.hv-script":["hvs"],"application/vnd.yamaha.hv-voice":["hvp"],"application/vnd.yamaha.openscoreformat":["osf"],"application/vnd.yamaha.openscoreformat.osfpvg+xml":["osfpvg"],"application/vnd.yamaha.smaf-audio":["saf"],"application/vnd.yamaha.smaf-phrase":["spf"],"application/vnd.yellowriver-custom-menu":["cmp"],"application/vnd.zul":["zir","zirz"],"application/vnd.zzazz.deck+xml":["zaz"],"application/x-7z-compressed":["7z"],"application/x-abiword":["abw"],"application/x-ace-compressed":["ace"],"application/x-apple-diskimage":["*dmg"],"application/x-arj":["arj"],"application/x-authorware-bin":["aab","x32","u32","vox"],"application/x-authorware-map":["aam"],"application/x-authorware-seg":["aas"],"application/x-bcpio":["bcpio"],"application/x-bdoc":["*bdoc"],"application/x-bittorrent":["torrent"],"application/x-blorb":["blb","blorb"],"application/x-bzip":["bz"],"application/x-bzip2":["bz2","boz"],"application/x-cbr":["cbr","cba","cbt","cbz","cb7"],"application/x-cdlink":["vcd"],"application/x-cfs-compressed":["cfs"],"application/x-chat":["chat"],"application/x-chess-pgn":["pgn"],"application/x-chrome-extension":["crx"],"application/x-cocoa":["cco"],"application/x-conference":["nsc"],"application/x-cpio":["cpio"],"application/x-csh":["csh"],"application/x-debian-package":["*deb","udeb"],"application/x-dgc-compressed":["dgc"],"application/x-director":["dir","dcr","dxr","cst","cct","cxt","w3d","fgd","swa"],"application/x-doom":["wad"],"application/x-dtbncx+xml":["ncx"],"application/x-dtbook+xml":["dtb"],"application/x-dtbresource+xml":["res"],"application/x-dvi":["dvi"],"application/x-envoy":["evy"],"application/x-eva":["eva"],"application/x-font-bdf":["bdf"],"application/x-font-ghostscript":["gsf"],"application/x-font-linux-psf":["psf"],"application/x-font-pcf":["pcf"],"application/x-font-snf":["snf"],"application/x-font-type1":["pfa","pfb","pfm","afm"],"application/x-freearc":["arc"],"application/x-futuresplash":["spl"],"application/x-gca-compressed":["gca"],"application/x-glulx":["ulx"],"application/x-gnumeric":["gnumeric"],"application/x-gramps-xml":["gramps"],"application/x-gtar":["gtar"],"application/x-hdf":["hdf"],"application/x-httpd-php":["php"],"application/x-install-instructions":["install"],"application/x-iso9660-image":["*iso"],"application/x-java-archive-diff":["jardiff"],"application/x-java-jnlp-file":["jnlp"],"application/x-keepass2":["kdbx"],"application/x-latex":["latex"],"application/x-lua-bytecode":["luac"],"application/x-lzh-compressed":["lzh","lha"],"application/x-makeself":["run"],"application/x-mie":["mie"],"application/x-mobipocket-ebook":["prc","mobi"],"application/x-ms-application":["application"],"application/x-ms-shortcut":["lnk"],"application/x-ms-wmd":["wmd"],"application/x-ms-wmz":["wmz"],"application/x-ms-xbap":["xbap"],"application/x-msaccess":["mdb"],"application/x-msbinder":["obd"],"application/x-mscardfile":["crd"],"application/x-msclip":["clp"],"application/x-msdos-program":["*exe"],"application/x-msdownload":["*exe","*dll","com","bat","*msi"],"application/x-msmediaview":["mvb","m13","m14"],"application/x-msmetafile":["*wmf","*wmz","*emf","emz"],"application/x-msmoney":["mny"],"application/x-mspublisher":["pub"],"application/x-msschedule":["scd"],"application/x-msterminal":["trm"],"application/x-mswrite":["wri"],"application/x-netcdf":["nc","cdf"],"application/x-ns-proxy-autoconfig":["pac"],"application/x-nzb":["nzb"],"application/x-perl":["pl","pm"],"application/x-pilot":["*prc","*pdb"],"application/x-pkcs12":["p12","pfx"],"application/x-pkcs7-certificates":["p7b","spc"],"application/x-pkcs7-certreqresp":["p7r"],"application/x-rar-compressed":["rar"],"application/x-redhat-package-manager":["rpm"],"application/x-research-info-systems":["ris"],"application/x-sea":["sea"],"application/x-sh":["sh"],"application/x-shar":["shar"],"application/x-shockwave-flash":["swf"],"application/x-silverlight-app":["xap"],"application/x-sql":["sql"],"application/x-stuffit":["sit"],"application/x-stuffitx":["sitx"],"application/x-subrip":["srt"],"application/x-sv4cpio":["sv4cpio"],"application/x-sv4crc":["sv4crc"],"application/x-t3vm-image":["t3"],"application/x-tads":["gam"],"application/x-tar":["tar"],"application/x-tcl":["tcl","tk"],"application/x-tex":["tex"],"application/x-tex-tfm":["tfm"],"application/x-texinfo":["texinfo","texi"],"application/x-tgif":["*obj"],"application/x-ustar":["ustar"],"application/x-virtualbox-hdd":["hdd"],"application/x-virtualbox-ova":["ova"],"application/x-virtualbox-ovf":["ovf"],"application/x-virtualbox-vbox":["vbox"],"application/x-virtualbox-vbox-extpack":["vbox-extpack"],"application/x-virtualbox-vdi":["vdi"],"application/x-virtualbox-vhd":["vhd"],"application/x-virtualbox-vmdk":["vmdk"],"application/x-wais-source":["src"],"application/x-web-app-manifest+json":["webapp"],"application/x-x509-ca-cert":["der","crt","pem"],"application/x-xfig":["fig"],"application/x-xliff+xml":["*xlf"],"application/x-xpinstall":["xpi"],"application/x-xz":["xz"],"application/x-zmachine":["z1","z2","z3","z4","z5","z6","z7","z8"],"audio/vnd.dece.audio":["uva","uvva"],"audio/vnd.digital-winds":["eol"],"audio/vnd.dra":["dra"],"audio/vnd.dts":["dts"],"audio/vnd.dts.hd":["dtshd"],"audio/vnd.lucent.voice":["lvp"],"audio/vnd.ms-playready.media.pya":["pya"],"audio/vnd.nuera.ecelp4800":["ecelp4800"],"audio/vnd.nuera.ecelp7470":["ecelp7470"],"audio/vnd.nuera.ecelp9600":["ecelp9600"],"audio/vnd.rip":["rip"],"audio/x-aac":["aac"],"audio/x-aiff":["aif","aiff","aifc"],"audio/x-caf":["caf"],"audio/x-flac":["flac"],"audio/x-m4a":["*m4a"],"audio/x-matroska":["mka"],"audio/x-mpegurl":["m3u"],"audio/x-ms-wax":["wax"],"audio/x-ms-wma":["wma"],"audio/x-pn-realaudio":["ram","ra"],"audio/x-pn-realaudio-plugin":["rmp"],"audio/x-realaudio":["*ra"],"audio/x-wav":["*wav"],"chemical/x-cdx":["cdx"],"chemical/x-cif":["cif"],"chemical/x-cmdf":["cmdf"],"chemical/x-cml":["cml"],"chemical/x-csml":["csml"],"chemical/x-xyz":["xyz"],"image/prs.btif":["btif"],"image/prs.pti":["pti"],"image/vnd.adobe.photoshop":["psd"],"image/vnd.airzip.accelerator.azv":["azv"],"image/vnd.dece.graphic":["uvi","uvvi","uvg","uvvg"],"image/vnd.djvu":["djvu","djv"],"image/vnd.dvb.subtitle":["*sub"],"image/vnd.dwg":["dwg"],"image/vnd.dxf":["dxf"],"image/vnd.fastbidsheet":["fbs"],"image/vnd.fpx":["fpx"],"image/vnd.fst":["fst"],"image/vnd.fujixerox.edmics-mmr":["mmr"],"image/vnd.fujixerox.edmics-rlc":["rlc"],"image/vnd.microsoft.icon":["ico"],"image/vnd.ms-dds":["dds"],"image/vnd.ms-modi":["mdi"],"image/vnd.ms-photo":["wdp"],"image/vnd.net-fpx":["npx"],"image/vnd.tencent.tap":["tap"],"image/vnd.valve.source.texture":["vtf"],"image/vnd.wap.wbmp":["wbmp"],"image/vnd.xiff":["xif"],"image/vnd.zbrush.pcx":["pcx"],"image/x-3ds":["3ds"],"image/x-cmu-raster":["ras"],"image/x-cmx":["cmx"],"image/x-freehand":["fh","fhc","fh4","fh5","fh7"],"image/x-icon":["*ico"],"image/x-jng":["jng"],"image/x-mrsid-image":["sid"],"image/x-ms-bmp":["*bmp"],"image/x-pcx":["*pcx"],"image/x-pict":["pic","pct"],"image/x-portable-anymap":["pnm"],"image/x-portable-bitmap":["pbm"],"image/x-portable-graymap":["pgm"],"image/x-portable-pixmap":["ppm"],"image/x-rgb":["rgb"],"image/x-tga":["tga"],"image/x-xbitmap":["xbm"],"image/x-xpixmap":["xpm"],"image/x-xwindowdump":["xwd"],"message/vnd.wfa.wsc":["wsc"],"model/vnd.collada+xml":["dae"],"model/vnd.dwf":["dwf"],"model/vnd.gdl":["gdl"],"model/vnd.gtw":["gtw"],"model/vnd.mts":["mts"],"model/vnd.opengex":["ogex"],"model/vnd.parasolid.transmit.binary":["x_b"],"model/vnd.parasolid.transmit.text":["x_t"],"model/vnd.usdz+zip":["usdz"],"model/vnd.valve.source.compiled-map":["bsp"],"model/vnd.vtu":["vtu"],"text/prs.lines.tag":["dsc"],"text/vnd.curl":["curl"],"text/vnd.curl.dcurl":["dcurl"],"text/vnd.curl.mcurl":["mcurl"],"text/vnd.curl.scurl":["scurl"],"text/vnd.dvb.subtitle":["sub"],"text/vnd.fly":["fly"],"text/vnd.fmi.flexstor":["flx"],"text/vnd.graphviz":["gv"],"text/vnd.in3d.3dml":["3dml"],"text/vnd.in3d.spot":["spot"],"text/vnd.sun.j2me.app-descriptor":["jad"],"text/vnd.wap.wml":["wml"],"text/vnd.wap.wmlscript":["wmls"],"text/x-asm":["s","asm"],"text/x-c":["c","cc","cxx","cpp","h","hh","dic"],"text/x-component":["htc"],"text/x-fortran":["f","for","f77","f90"],"text/x-handlebars-template":["hbs"],"text/x-java-source":["java"],"text/x-lua":["lua"],"text/x-markdown":["mkd"],"text/x-nfo":["nfo"],"text/x-opml":["opml"],"text/x-org":["*org"],"text/x-pascal":["p","pas"],"text/x-processing":["pde"],"text/x-sass":["sass"],"text/x-scss":["scss"],"text/x-setext":["etx"],"text/x-sfv":["sfv"],"text/x-suse-ymp":["ymp"],"text/x-uuencode":["uu"],"text/x-vcalendar":["vcs"],"text/x-vcard":["vcf"],"video/vnd.dece.hd":["uvh","uvvh"],"video/vnd.dece.mobile":["uvm","uvvm"],"video/vnd.dece.pd":["uvp","uvvp"],"video/vnd.dece.sd":["uvs","uvvs"],"video/vnd.dece.video":["uvv","uvvv"],"video/vnd.dvb.file":["dvb"],"video/vnd.fvt":["fvt"],"video/vnd.mpegurl":["mxu","m4u"],"video/vnd.ms-playready.media.pyv":["pyv"],"video/vnd.uvvu.mp4":["uvu","uvvu"],"video/vnd.vivo":["viv"],"video/x-f4v":["f4v"],"video/x-fli":["fli"],"video/x-flv":["flv"],"video/x-m4v":["m4v"],"video/x-matroska":["mkv","mk3d","mks"],"video/x-mng":["mng"],"video/x-ms-asf":["asf","asx"],"video/x-ms-vob":["vob"],"video/x-ms-wm":["wm"],"video/x-ms-wmv":["wmv"],"video/x-ms-wmx":["wmx"],"video/x-ms-wvx":["wvx"],"video/x-msvideo":["avi"],"video/x-sgi-movie":["movie"],"video/x-smv":["smv"],"x-conference/x-cooltalk":["ice"]};
115
116 var mime = new Mime_1(standard, other);
117
118 /*
119 * XFetch.js modified
120 * A extremely simple fetch extension inspired by sindresorhus/ky.
121 */
122 const xf = (() => {
123 const METHODS = ['get', 'post', 'put', 'patch', 'delete', 'head'];
124
125 class HTTPError extends Error {
126 constructor(res) {
127 super(res.statusText);
128 this.name = 'HTTPError';
129 this.response = res;
130 }
131
132 }
133
134 class XResponsePromise extends Promise {}
135
136 for (const alias of ['arrayBuffer', 'blob', 'formData', 'json', 'text']) {
137 // alias for .json() .text() etc...
138 XResponsePromise.prototype[alias] = function (fn) {
139 return this.then(res => res[alias]()).then(fn || (x => x));
140 };
141 }
142
143 const {
144 assign
145 } = Object;
146
147 function mergeDeep(target, source) {
148 const isObject = obj => obj && typeof obj === 'object';
149
150 if (!isObject(target) || !isObject(source)) {
151 return source;
152 }
153
154 Object.keys(source).forEach(key => {
155 const targetValue = target[key];
156 const sourceValue = source[key];
157
158 if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
159 target[key] = targetValue.concat(sourceValue);
160 } else if (isObject(targetValue) && isObject(sourceValue)) {
161 target[key] = mergeDeep(Object.assign({}, targetValue), sourceValue);
162 } else {
163 target[key] = sourceValue;
164 }
165 });
166 return target;
167 }
168
169 const fromEntries = ent => ent.reduce((acc, [k, v]) => (acc[k] = v, acc), {});
170
171 const typeis = (...types) => val => types.some(type => typeof type === 'string' ? typeof val === type : val instanceof type);
172
173 const isstr = typeis('string');
174 const isobj = typeis('object');
175
176 const isstrorobj = v => isstr(v) || isobj(v);
177
178 const responseErrorThrower = res => {
179 if (!res.ok) throw new HTTPError(res);
180 return res;
181 };
182
183 const extend = (defaultInit = {}) => {
184 const xfetch = (input, init = {}) => {
185 mergeDeep(init, defaultInit);
186
187 const createQueryString = o => new init.URLSearchParams(o).toString();
188
189 const parseQueryString = s => fromEntries([...new init.URLSearchParams(s).entries()]);
190
191 const url = new init.URL(input, init.baseURI || undefined);
192
193 if (!init.headers) {
194 init.headers = {};
195 } else if (typeis(init.Headers)(init.headers)) {
196 // Transform into object if it is `Headers`
197 init.headers = fromEntries([...init.headers.entries()]);
198 } // Add json or form on body
199
200
201 if (init.json) {
202 init.body = JSON.stringify(init.json);
203 init.headers['Content-Type'] = 'application/json';
204 } else if (isstrorobj(init.urlencoded)) {
205 init.body = isstr(init.urlencoded) ? init.urlencoded : createQueryString(init.urlencoded);
206 init.headers['Content-Type'] = 'application/x-www-form-urlencoded';
207 } else if (typeis(init.FormData, 'object')(init.formData)) {
208 // init.formData is data passed by user, init.FormData is FormData constructor
209 if (!typeis(init.FormData)(init.formData)) {
210 const fd = new init.FormData();
211
212 for (const [k, v] of Object.entries(init.formData)) {
213 fd.append(k, v);
214 }
215
216 init.formData = fd;
217 }
218
219 init.body = init.formData;
220 } // Querystring
221
222
223 if (init.qs) {
224 if (isstr(init.qs)) init.qs = parseQueryString(init.qs);
225 url.search = createQueryString(assign(fromEntries([...url.searchParams.entries()]), init.qs));
226 }
227
228 return XResponsePromise.resolve(init.fetch(url, init).then(responseErrorThrower));
229 };
230
231 for (const method of METHODS) {
232 xfetch[method] = (input, init = {}) => {
233 init.method = method.toUpperCase();
234 return xfetch(input, init);
235 };
236 } // Extra methods and classes
237
238
239 xfetch.extend = newDefaultInit => extend(assign({}, defaultInit, newDefaultInit));
240
241 xfetch.HTTPError = HTTPError;
242 return xfetch;
243 };
244
245 const isWindow = typeof document !== 'undefined';
246 const isBrowser = typeof self !== 'undefined'; // works in both window & worker scope
247
248 return isBrowser ? extend({
249 fetch: fetch.bind(self),
250 URL,
251 Response,
252 URLSearchParams,
253 Headers,
254 FormData,
255 baseURI: isWindow ? document.baseURI : '' // since there is no document in webworkers
256
257 }) : extend();
258 })();
259
260 function unwrapExports (x) {
261 return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
262 }
263
264 function createCommonjsModule(fn, module) {
265 return module = { exports: {} }, fn(module, module.exports), module.exports;
266 }
267
268 var global$1 = (typeof global !== "undefined" ? global :
269 typeof self !== "undefined" ? self :
270 typeof window !== "undefined" ? window : {});
271
272 var lookup = [];
273 var revLookup = [];
274 var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
275 var inited = false;
276 function init () {
277 inited = true;
278 var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
279 for (var i = 0, len = code.length; i < len; ++i) {
280 lookup[i] = code[i];
281 revLookup[code.charCodeAt(i)] = i;
282 }
283
284 revLookup['-'.charCodeAt(0)] = 62;
285 revLookup['_'.charCodeAt(0)] = 63;
286 }
287
288 function toByteArray (b64) {
289 if (!inited) {
290 init();
291 }
292 var i, j, l, tmp, placeHolders, arr;
293 var len = b64.length;
294
295 if (len % 4 > 0) {
296 throw new Error('Invalid string. Length must be a multiple of 4')
297 }
298
299 // the number of equal signs (place holders)
300 // if there are two placeholders, than the two characters before it
301 // represent one byte
302 // if there is only one, then the three characters before it represent 2 bytes
303 // this is just a cheap hack to not do indexOf twice
304 placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0;
305
306 // base64 is 4/3 + up to two characters of the original data
307 arr = new Arr(len * 3 / 4 - placeHolders);
308
309 // if there are placeholders, only get up to the last complete 4 chars
310 l = placeHolders > 0 ? len - 4 : len;
311
312 var L = 0;
313
314 for (i = 0, j = 0; i < l; i += 4, j += 3) {
315 tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)];
316 arr[L++] = (tmp >> 16) & 0xFF;
317 arr[L++] = (tmp >> 8) & 0xFF;
318 arr[L++] = tmp & 0xFF;
319 }
320
321 if (placeHolders === 2) {
322 tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);
323 arr[L++] = tmp & 0xFF;
324 } else if (placeHolders === 1) {
325 tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2);
326 arr[L++] = (tmp >> 8) & 0xFF;
327 arr[L++] = tmp & 0xFF;
328 }
329
330 return arr
331 }
332
333 function tripletToBase64 (num) {
334 return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
335 }
336
337 function encodeChunk (uint8, start, end) {
338 var tmp;
339 var output = [];
340 for (var i = start; i < end; i += 3) {
341 tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
342 output.push(tripletToBase64(tmp));
343 }
344 return output.join('')
345 }
346
347 function fromByteArray (uint8) {
348 if (!inited) {
349 init();
350 }
351 var tmp;
352 var len = uint8.length;
353 var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
354 var output = '';
355 var parts = [];
356 var maxChunkLength = 16383; // must be multiple of 3
357
358 // go through the array every three bytes, we'll deal with trailing stuff later
359 for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
360 parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
361 }
362
363 // pad the end with zeros, but make sure to not forget the extra bytes
364 if (extraBytes === 1) {
365 tmp = uint8[len - 1];
366 output += lookup[tmp >> 2];
367 output += lookup[(tmp << 4) & 0x3F];
368 output += '==';
369 } else if (extraBytes === 2) {
370 tmp = (uint8[len - 2] << 8) + (uint8[len - 1]);
371 output += lookup[tmp >> 10];
372 output += lookup[(tmp >> 4) & 0x3F];
373 output += lookup[(tmp << 2) & 0x3F];
374 output += '=';
375 }
376
377 parts.push(output);
378
379 return parts.join('')
380 }
381
382 function read (buffer, offset, isLE, mLen, nBytes) {
383 var e, m;
384 var eLen = nBytes * 8 - mLen - 1;
385 var eMax = (1 << eLen) - 1;
386 var eBias = eMax >> 1;
387 var nBits = -7;
388 var i = isLE ? (nBytes - 1) : 0;
389 var d = isLE ? -1 : 1;
390 var s = buffer[offset + i];
391
392 i += d;
393
394 e = s & ((1 << (-nBits)) - 1);
395 s >>= (-nBits);
396 nBits += eLen;
397 for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
398
399 m = e & ((1 << (-nBits)) - 1);
400 e >>= (-nBits);
401 nBits += mLen;
402 for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
403
404 if (e === 0) {
405 e = 1 - eBias;
406 } else if (e === eMax) {
407 return m ? NaN : ((s ? -1 : 1) * Infinity)
408 } else {
409 m = m + Math.pow(2, mLen);
410 e = e - eBias;
411 }
412 return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
413 }
414
415 function write (buffer, value, offset, isLE, mLen, nBytes) {
416 var e, m, c;
417 var eLen = nBytes * 8 - mLen - 1;
418 var eMax = (1 << eLen) - 1;
419 var eBias = eMax >> 1;
420 var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
421 var i = isLE ? 0 : (nBytes - 1);
422 var d = isLE ? 1 : -1;
423 var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
424
425 value = Math.abs(value);
426
427 if (isNaN(value) || value === Infinity) {
428 m = isNaN(value) ? 1 : 0;
429 e = eMax;
430 } else {
431 e = Math.floor(Math.log(value) / Math.LN2);
432 if (value * (c = Math.pow(2, -e)) < 1) {
433 e--;
434 c *= 2;
435 }
436 if (e + eBias >= 1) {
437 value += rt / c;
438 } else {
439 value += rt * Math.pow(2, 1 - eBias);
440 }
441 if (value * c >= 2) {
442 e++;
443 c /= 2;
444 }
445
446 if (e + eBias >= eMax) {
447 m = 0;
448 e = eMax;
449 } else if (e + eBias >= 1) {
450 m = (value * c - 1) * Math.pow(2, mLen);
451 e = e + eBias;
452 } else {
453 m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
454 e = 0;
455 }
456 }
457
458 for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
459
460 e = (e << mLen) | m;
461 eLen += mLen;
462 for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
463
464 buffer[offset + i - d] |= s * 128;
465 }
466
467 var toString = {}.toString;
468
469 var isArray = Array.isArray || function (arr) {
470 return toString.call(arr) == '[object Array]';
471 };
472
473 var INSPECT_MAX_BYTES = 50;
474
475 /**
476 * If `Buffer.TYPED_ARRAY_SUPPORT`:
477 * === true Use Uint8Array implementation (fastest)
478 * === false Use Object implementation (most compatible, even IE6)
479 *
480 * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
481 * Opera 11.6+, iOS 4.2+.
482 *
483 * Due to various browser bugs, sometimes the Object implementation will be used even
484 * when the browser supports typed arrays.
485 *
486 * Note:
487 *
488 * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
489 * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
490 *
491 * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
492 *
493 * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
494 * incorrect length in some situations.
495
496 * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
497 * get the Object implementation, which is slower but behaves correctly.
498 */
499 Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined
500 ? global$1.TYPED_ARRAY_SUPPORT
501 : true;
502
503 function kMaxLength () {
504 return Buffer.TYPED_ARRAY_SUPPORT
505 ? 0x7fffffff
506 : 0x3fffffff
507 }
508
509 function createBuffer (that, length) {
510 if (kMaxLength() < length) {
511 throw new RangeError('Invalid typed array length')
512 }
513 if (Buffer.TYPED_ARRAY_SUPPORT) {
514 // Return an augmented `Uint8Array` instance, for best performance
515 that = new Uint8Array(length);
516 that.__proto__ = Buffer.prototype;
517 } else {
518 // Fallback: Return an object instance of the Buffer class
519 if (that === null) {
520 that = new Buffer(length);
521 }
522 that.length = length;
523 }
524
525 return that
526 }
527
528 /**
529 * The Buffer constructor returns instances of `Uint8Array` that have their
530 * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
531 * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
532 * and the `Uint8Array` methods. Square bracket notation works as expected -- it
533 * returns a single octet.
534 *
535 * The `Uint8Array` prototype remains unmodified.
536 */
537
538 function Buffer (arg, encodingOrOffset, length) {
539 if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
540 return new Buffer(arg, encodingOrOffset, length)
541 }
542
543 // Common case.
544 if (typeof arg === 'number') {
545 if (typeof encodingOrOffset === 'string') {
546 throw new Error(
547 'If encoding is specified then the first argument must be a string'
548 )
549 }
550 return allocUnsafe(this, arg)
551 }
552 return from(this, arg, encodingOrOffset, length)
553 }
554
555 Buffer.poolSize = 8192; // not used by this implementation
556
557 // TODO: Legacy, not needed anymore. Remove in next major version.
558 Buffer._augment = function (arr) {
559 arr.__proto__ = Buffer.prototype;
560 return arr
561 };
562
563 function from (that, value, encodingOrOffset, length) {
564 if (typeof value === 'number') {
565 throw new TypeError('"value" argument must not be a number')
566 }
567
568 if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
569 return fromArrayBuffer(that, value, encodingOrOffset, length)
570 }
571
572 if (typeof value === 'string') {
573 return fromString(that, value, encodingOrOffset)
574 }
575
576 return fromObject(that, value)
577 }
578
579 /**
580 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
581 * if value is a number.
582 * Buffer.from(str[, encoding])
583 * Buffer.from(array)
584 * Buffer.from(buffer)
585 * Buffer.from(arrayBuffer[, byteOffset[, length]])
586 **/
587 Buffer.from = function (value, encodingOrOffset, length) {
588 return from(null, value, encodingOrOffset, length)
589 };
590
591 if (Buffer.TYPED_ARRAY_SUPPORT) {
592 Buffer.prototype.__proto__ = Uint8Array.prototype;
593 Buffer.__proto__ = Uint8Array;
594 }
595
596 function assertSize (size) {
597 if (typeof size !== 'number') {
598 throw new TypeError('"size" argument must be a number')
599 } else if (size < 0) {
600 throw new RangeError('"size" argument must not be negative')
601 }
602 }
603
604 function alloc (that, size, fill, encoding) {
605 assertSize(size);
606 if (size <= 0) {
607 return createBuffer(that, size)
608 }
609 if (fill !== undefined) {
610 // Only pay attention to encoding if it's a string. This
611 // prevents accidentally sending in a number that would
612 // be interpretted as a start offset.
613 return typeof encoding === 'string'
614 ? createBuffer(that, size).fill(fill, encoding)
615 : createBuffer(that, size).fill(fill)
616 }
617 return createBuffer(that, size)
618 }
619
620 /**
621 * Creates a new filled Buffer instance.
622 * alloc(size[, fill[, encoding]])
623 **/
624 Buffer.alloc = function (size, fill, encoding) {
625 return alloc(null, size, fill, encoding)
626 };
627
628 function allocUnsafe (that, size) {
629 assertSize(size);
630 that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
631 if (!Buffer.TYPED_ARRAY_SUPPORT) {
632 for (var i = 0; i < size; ++i) {
633 that[i] = 0;
634 }
635 }
636 return that
637 }
638
639 /**
640 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
641 * */
642 Buffer.allocUnsafe = function (size) {
643 return allocUnsafe(null, size)
644 };
645 /**
646 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
647 */
648 Buffer.allocUnsafeSlow = function (size) {
649 return allocUnsafe(null, size)
650 };
651
652 function fromString (that, string, encoding) {
653 if (typeof encoding !== 'string' || encoding === '') {
654 encoding = 'utf8';
655 }
656
657 if (!Buffer.isEncoding(encoding)) {
658 throw new TypeError('"encoding" must be a valid string encoding')
659 }
660
661 var length = byteLength(string, encoding) | 0;
662 that = createBuffer(that, length);
663
664 var actual = that.write(string, encoding);
665
666 if (actual !== length) {
667 // Writing a hex string, for example, that contains invalid characters will
668 // cause everything after the first invalid character to be ignored. (e.g.
669 // 'abxxcd' will be treated as 'ab')
670 that = that.slice(0, actual);
671 }
672
673 return that
674 }
675
676 function fromArrayLike (that, array) {
677 var length = array.length < 0 ? 0 : checked(array.length) | 0;
678 that = createBuffer(that, length);
679 for (var i = 0; i < length; i += 1) {
680 that[i] = array[i] & 255;
681 }
682 return that
683 }
684
685 function fromArrayBuffer (that, array, byteOffset, length) {
686 array.byteLength; // this throws if `array` is not a valid ArrayBuffer
687
688 if (byteOffset < 0 || array.byteLength < byteOffset) {
689 throw new RangeError('\'offset\' is out of bounds')
690 }
691
692 if (array.byteLength < byteOffset + (length || 0)) {
693 throw new RangeError('\'length\' is out of bounds')
694 }
695
696 if (byteOffset === undefined && length === undefined) {
697 array = new Uint8Array(array);
698 } else if (length === undefined) {
699 array = new Uint8Array(array, byteOffset);
700 } else {
701 array = new Uint8Array(array, byteOffset, length);
702 }
703
704 if (Buffer.TYPED_ARRAY_SUPPORT) {
705 // Return an augmented `Uint8Array` instance, for best performance
706 that = array;
707 that.__proto__ = Buffer.prototype;
708 } else {
709 // Fallback: Return an object instance of the Buffer class
710 that = fromArrayLike(that, array);
711 }
712 return that
713 }
714
715 function fromObject (that, obj) {
716 if (internalIsBuffer(obj)) {
717 var len = checked(obj.length) | 0;
718 that = createBuffer(that, len);
719
720 if (that.length === 0) {
721 return that
722 }
723
724 obj.copy(that, 0, 0, len);
725 return that
726 }
727
728 if (obj) {
729 if ((typeof ArrayBuffer !== 'undefined' &&
730 obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
731 if (typeof obj.length !== 'number' || isnan(obj.length)) {
732 return createBuffer(that, 0)
733 }
734 return fromArrayLike(that, obj)
735 }
736
737 if (obj.type === 'Buffer' && isArray(obj.data)) {
738 return fromArrayLike(that, obj.data)
739 }
740 }
741
742 throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
743 }
744
745 function checked (length) {
746 // Note: cannot use `length < kMaxLength()` here because that fails when
747 // length is NaN (which is otherwise coerced to zero.)
748 if (length >= kMaxLength()) {
749 throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
750 'size: 0x' + kMaxLength().toString(16) + ' bytes')
751 }
752 return length | 0
753 }
754 Buffer.isBuffer = isBuffer;
755 function internalIsBuffer (b) {
756 return !!(b != null && b._isBuffer)
757 }
758
759 Buffer.compare = function compare (a, b) {
760 if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
761 throw new TypeError('Arguments must be Buffers')
762 }
763
764 if (a === b) return 0
765
766 var x = a.length;
767 var y = b.length;
768
769 for (var i = 0, len = Math.min(x, y); i < len; ++i) {
770 if (a[i] !== b[i]) {
771 x = a[i];
772 y = b[i];
773 break
774 }
775 }
776
777 if (x < y) return -1
778 if (y < x) return 1
779 return 0
780 };
781
782 Buffer.isEncoding = function isEncoding (encoding) {
783 switch (String(encoding).toLowerCase()) {
784 case 'hex':
785 case 'utf8':
786 case 'utf-8':
787 case 'ascii':
788 case 'latin1':
789 case 'binary':
790 case 'base64':
791 case 'ucs2':
792 case 'ucs-2':
793 case 'utf16le':
794 case 'utf-16le':
795 return true
796 default:
797 return false
798 }
799 };
800
801 Buffer.concat = function concat (list, length) {
802 if (!isArray(list)) {
803 throw new TypeError('"list" argument must be an Array of Buffers')
804 }
805
806 if (list.length === 0) {
807 return Buffer.alloc(0)
808 }
809
810 var i;
811 if (length === undefined) {
812 length = 0;
813 for (i = 0; i < list.length; ++i) {
814 length += list[i].length;
815 }
816 }
817
818 var buffer = Buffer.allocUnsafe(length);
819 var pos = 0;
820 for (i = 0; i < list.length; ++i) {
821 var buf = list[i];
822 if (!internalIsBuffer(buf)) {
823 throw new TypeError('"list" argument must be an Array of Buffers')
824 }
825 buf.copy(buffer, pos);
826 pos += buf.length;
827 }
828 return buffer
829 };
830
831 function byteLength (string, encoding) {
832 if (internalIsBuffer(string)) {
833 return string.length
834 }
835 if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
836 (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
837 return string.byteLength
838 }
839 if (typeof string !== 'string') {
840 string = '' + string;
841 }
842
843 var len = string.length;
844 if (len === 0) return 0
845
846 // Use a for loop to avoid recursion
847 var loweredCase = false;
848 for (;;) {
849 switch (encoding) {
850 case 'ascii':
851 case 'latin1':
852 case 'binary':
853 return len
854 case 'utf8':
855 case 'utf-8':
856 case undefined:
857 return utf8ToBytes(string).length
858 case 'ucs2':
859 case 'ucs-2':
860 case 'utf16le':
861 case 'utf-16le':
862 return len * 2
863 case 'hex':
864 return len >>> 1
865 case 'base64':
866 return base64ToBytes(string).length
867 default:
868 if (loweredCase) return utf8ToBytes(string).length // assume utf8
869 encoding = ('' + encoding).toLowerCase();
870 loweredCase = true;
871 }
872 }
873 }
874 Buffer.byteLength = byteLength;
875
876 function slowToString (encoding, start, end) {
877 var loweredCase = false;
878
879 // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
880 // property of a typed array.
881
882 // This behaves neither like String nor Uint8Array in that we set start/end
883 // to their upper/lower bounds if the value passed is out of range.
884 // undefined is handled specially as per ECMA-262 6th Edition,
885 // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
886 if (start === undefined || start < 0) {
887 start = 0;
888 }
889 // Return early if start > this.length. Done here to prevent potential uint32
890 // coercion fail below.
891 if (start > this.length) {
892 return ''
893 }
894
895 if (end === undefined || end > this.length) {
896 end = this.length;
897 }
898
899 if (end <= 0) {
900 return ''
901 }
902
903 // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
904 end >>>= 0;
905 start >>>= 0;
906
907 if (end <= start) {
908 return ''
909 }
910
911 if (!encoding) encoding = 'utf8';
912
913 while (true) {
914 switch (encoding) {
915 case 'hex':
916 return hexSlice(this, start, end)
917
918 case 'utf8':
919 case 'utf-8':
920 return utf8Slice(this, start, end)
921
922 case 'ascii':
923 return asciiSlice(this, start, end)
924
925 case 'latin1':
926 case 'binary':
927 return latin1Slice(this, start, end)
928
929 case 'base64':
930 return base64Slice(this, start, end)
931
932 case 'ucs2':
933 case 'ucs-2':
934 case 'utf16le':
935 case 'utf-16le':
936 return utf16leSlice(this, start, end)
937
938 default:
939 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
940 encoding = (encoding + '').toLowerCase();
941 loweredCase = true;
942 }
943 }
944 }
945
946 // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
947 // Buffer instances.
948 Buffer.prototype._isBuffer = true;
949
950 function swap (b, n, m) {
951 var i = b[n];
952 b[n] = b[m];
953 b[m] = i;
954 }
955
956 Buffer.prototype.swap16 = function swap16 () {
957 var len = this.length;
958 if (len % 2 !== 0) {
959 throw new RangeError('Buffer size must be a multiple of 16-bits')
960 }
961 for (var i = 0; i < len; i += 2) {
962 swap(this, i, i + 1);
963 }
964 return this
965 };
966
967 Buffer.prototype.swap32 = function swap32 () {
968 var len = this.length;
969 if (len % 4 !== 0) {
970 throw new RangeError('Buffer size must be a multiple of 32-bits')
971 }
972 for (var i = 0; i < len; i += 4) {
973 swap(this, i, i + 3);
974 swap(this, i + 1, i + 2);
975 }
976 return this
977 };
978
979 Buffer.prototype.swap64 = function swap64 () {
980 var len = this.length;
981 if (len % 8 !== 0) {
982 throw new RangeError('Buffer size must be a multiple of 64-bits')
983 }
984 for (var i = 0; i < len; i += 8) {
985 swap(this, i, i + 7);
986 swap(this, i + 1, i + 6);
987 swap(this, i + 2, i + 5);
988 swap(this, i + 3, i + 4);
989 }
990 return this
991 };
992
993 Buffer.prototype.toString = function toString () {
994 var length = this.length | 0;
995 if (length === 0) return ''
996 if (arguments.length === 0) return utf8Slice(this, 0, length)
997 return slowToString.apply(this, arguments)
998 };
999
1000 Buffer.prototype.equals = function equals (b) {
1001 if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer')
1002 if (this === b) return true
1003 return Buffer.compare(this, b) === 0
1004 };
1005
1006 Buffer.prototype.inspect = function inspect () {
1007 var str = '';
1008 var max = INSPECT_MAX_BYTES;
1009 if (this.length > 0) {
1010 str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
1011 if (this.length > max) str += ' ... ';
1012 }
1013 return '<Buffer ' + str + '>'
1014 };
1015
1016 Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
1017 if (!internalIsBuffer(target)) {
1018 throw new TypeError('Argument must be a Buffer')
1019 }
1020
1021 if (start === undefined) {
1022 start = 0;
1023 }
1024 if (end === undefined) {
1025 end = target ? target.length : 0;
1026 }
1027 if (thisStart === undefined) {
1028 thisStart = 0;
1029 }
1030 if (thisEnd === undefined) {
1031 thisEnd = this.length;
1032 }
1033
1034 if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
1035 throw new RangeError('out of range index')
1036 }
1037
1038 if (thisStart >= thisEnd && start >= end) {
1039 return 0
1040 }
1041 if (thisStart >= thisEnd) {
1042 return -1
1043 }
1044 if (start >= end) {
1045 return 1
1046 }
1047
1048 start >>>= 0;
1049 end >>>= 0;
1050 thisStart >>>= 0;
1051 thisEnd >>>= 0;
1052
1053 if (this === target) return 0
1054
1055 var x = thisEnd - thisStart;
1056 var y = end - start;
1057 var len = Math.min(x, y);
1058
1059 var thisCopy = this.slice(thisStart, thisEnd);
1060 var targetCopy = target.slice(start, end);
1061
1062 for (var i = 0; i < len; ++i) {
1063 if (thisCopy[i] !== targetCopy[i]) {
1064 x = thisCopy[i];
1065 y = targetCopy[i];
1066 break
1067 }
1068 }
1069
1070 if (x < y) return -1
1071 if (y < x) return 1
1072 return 0
1073 };
1074
1075 // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
1076 // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
1077 //
1078 // Arguments:
1079 // - buffer - a Buffer to search
1080 // - val - a string, Buffer, or number
1081 // - byteOffset - an index into `buffer`; will be clamped to an int32
1082 // - encoding - an optional encoding, relevant is val is a string
1083 // - dir - true for indexOf, false for lastIndexOf
1084 function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
1085 // Empty buffer means no match
1086 if (buffer.length === 0) return -1
1087
1088 // Normalize byteOffset
1089 if (typeof byteOffset === 'string') {
1090 encoding = byteOffset;
1091 byteOffset = 0;
1092 } else if (byteOffset > 0x7fffffff) {
1093 byteOffset = 0x7fffffff;
1094 } else if (byteOffset < -0x80000000) {
1095 byteOffset = -0x80000000;
1096 }
1097 byteOffset = +byteOffset; // Coerce to Number.
1098 if (isNaN(byteOffset)) {
1099 // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
1100 byteOffset = dir ? 0 : (buffer.length - 1);
1101 }
1102
1103 // Normalize byteOffset: negative offsets start from the end of the buffer
1104 if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
1105 if (byteOffset >= buffer.length) {
1106 if (dir) return -1
1107 else byteOffset = buffer.length - 1;
1108 } else if (byteOffset < 0) {
1109 if (dir) byteOffset = 0;
1110 else return -1
1111 }
1112
1113 // Normalize val
1114 if (typeof val === 'string') {
1115 val = Buffer.from(val, encoding);
1116 }
1117
1118 // Finally, search either indexOf (if dir is true) or lastIndexOf
1119 if (internalIsBuffer(val)) {
1120 // Special case: looking for empty string/buffer always fails
1121 if (val.length === 0) {
1122 return -1
1123 }
1124 return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
1125 } else if (typeof val === 'number') {
1126 val = val & 0xFF; // Search for a byte value [0-255]
1127 if (Buffer.TYPED_ARRAY_SUPPORT &&
1128 typeof Uint8Array.prototype.indexOf === 'function') {
1129 if (dir) {
1130 return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
1131 } else {
1132 return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
1133 }
1134 }
1135 return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
1136 }
1137
1138 throw new TypeError('val must be string, number or Buffer')
1139 }
1140
1141 function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
1142 var indexSize = 1;
1143 var arrLength = arr.length;
1144 var valLength = val.length;
1145
1146 if (encoding !== undefined) {
1147 encoding = String(encoding).toLowerCase();
1148 if (encoding === 'ucs2' || encoding === 'ucs-2' ||
1149 encoding === 'utf16le' || encoding === 'utf-16le') {
1150 if (arr.length < 2 || val.length < 2) {
1151 return -1
1152 }
1153 indexSize = 2;
1154 arrLength /= 2;
1155 valLength /= 2;
1156 byteOffset /= 2;
1157 }
1158 }
1159
1160 function read (buf, i) {
1161 if (indexSize === 1) {
1162 return buf[i]
1163 } else {
1164 return buf.readUInt16BE(i * indexSize)
1165 }
1166 }
1167
1168 var i;
1169 if (dir) {
1170 var foundIndex = -1;
1171 for (i = byteOffset; i < arrLength; i++) {
1172 if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
1173 if (foundIndex === -1) foundIndex = i;
1174 if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
1175 } else {
1176 if (foundIndex !== -1) i -= i - foundIndex;
1177 foundIndex = -1;
1178 }
1179 }
1180 } else {
1181 if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
1182 for (i = byteOffset; i >= 0; i--) {
1183 var found = true;
1184 for (var j = 0; j < valLength; j++) {
1185 if (read(arr, i + j) !== read(val, j)) {
1186 found = false;
1187 break
1188 }
1189 }
1190 if (found) return i
1191 }
1192 }
1193
1194 return -1
1195 }
1196
1197 Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
1198 return this.indexOf(val, byteOffset, encoding) !== -1
1199 };
1200
1201 Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
1202 return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
1203 };
1204
1205 Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
1206 return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
1207 };
1208
1209 function hexWrite (buf, string, offset, length) {
1210 offset = Number(offset) || 0;
1211 var remaining = buf.length - offset;
1212 if (!length) {
1213 length = remaining;
1214 } else {
1215 length = Number(length);
1216 if (length > remaining) {
1217 length = remaining;
1218 }
1219 }
1220
1221 // must be an even number of digits
1222 var strLen = string.length;
1223 if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
1224
1225 if (length > strLen / 2) {
1226 length = strLen / 2;
1227 }
1228 for (var i = 0; i < length; ++i) {
1229 var parsed = parseInt(string.substr(i * 2, 2), 16);
1230 if (isNaN(parsed)) return i
1231 buf[offset + i] = parsed;
1232 }
1233 return i
1234 }
1235
1236 function utf8Write (buf, string, offset, length) {
1237 return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
1238 }
1239
1240 function asciiWrite (buf, string, offset, length) {
1241 return blitBuffer(asciiToBytes(string), buf, offset, length)
1242 }
1243
1244 function latin1Write (buf, string, offset, length) {
1245 return asciiWrite(buf, string, offset, length)
1246 }
1247
1248 function base64Write (buf, string, offset, length) {
1249 return blitBuffer(base64ToBytes(string), buf, offset, length)
1250 }
1251
1252 function ucs2Write (buf, string, offset, length) {
1253 return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
1254 }
1255
1256 Buffer.prototype.write = function write (string, offset, length, encoding) {
1257 // Buffer#write(string)
1258 if (offset === undefined) {
1259 encoding = 'utf8';
1260 length = this.length;
1261 offset = 0;
1262 // Buffer#write(string, encoding)
1263 } else if (length === undefined && typeof offset === 'string') {
1264 encoding = offset;
1265 length = this.length;
1266 offset = 0;
1267 // Buffer#write(string, offset[, length][, encoding])
1268 } else if (isFinite(offset)) {
1269 offset = offset | 0;
1270 if (isFinite(length)) {
1271 length = length | 0;
1272 if (encoding === undefined) encoding = 'utf8';
1273 } else {
1274 encoding = length;
1275 length = undefined;
1276 }
1277 // legacy write(string, encoding, offset, length) - remove in v0.13
1278 } else {
1279 throw new Error(
1280 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
1281 )
1282 }
1283
1284 var remaining = this.length - offset;
1285 if (length === undefined || length > remaining) length = remaining;
1286
1287 if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
1288 throw new RangeError('Attempt to write outside buffer bounds')
1289 }
1290
1291 if (!encoding) encoding = 'utf8';
1292
1293 var loweredCase = false;
1294 for (;;) {
1295 switch (encoding) {
1296 case 'hex':
1297 return hexWrite(this, string, offset, length)
1298
1299 case 'utf8':
1300 case 'utf-8':
1301 return utf8Write(this, string, offset, length)
1302
1303 case 'ascii':
1304 return asciiWrite(this, string, offset, length)
1305
1306 case 'latin1':
1307 case 'binary':
1308 return latin1Write(this, string, offset, length)
1309
1310 case 'base64':
1311 // Warning: maxLength not taken into account in base64Write
1312 return base64Write(this, string, offset, length)
1313
1314 case 'ucs2':
1315 case 'ucs-2':
1316 case 'utf16le':
1317 case 'utf-16le':
1318 return ucs2Write(this, string, offset, length)
1319
1320 default:
1321 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
1322 encoding = ('' + encoding).toLowerCase();
1323 loweredCase = true;
1324 }
1325 }
1326 };
1327
1328 Buffer.prototype.toJSON = function toJSON () {
1329 return {
1330 type: 'Buffer',
1331 data: Array.prototype.slice.call(this._arr || this, 0)
1332 }
1333 };
1334
1335 function base64Slice (buf, start, end) {
1336 if (start === 0 && end === buf.length) {
1337 return fromByteArray(buf)
1338 } else {
1339 return fromByteArray(buf.slice(start, end))
1340 }
1341 }
1342
1343 function utf8Slice (buf, start, end) {
1344 end = Math.min(buf.length, end);
1345 var res = [];
1346
1347 var i = start;
1348 while (i < end) {
1349 var firstByte = buf[i];
1350 var codePoint = null;
1351 var bytesPerSequence = (firstByte > 0xEF) ? 4
1352 : (firstByte > 0xDF) ? 3
1353 : (firstByte > 0xBF) ? 2
1354 : 1;
1355
1356 if (i + bytesPerSequence <= end) {
1357 var secondByte, thirdByte, fourthByte, tempCodePoint;
1358
1359 switch (bytesPerSequence) {
1360 case 1:
1361 if (firstByte < 0x80) {
1362 codePoint = firstByte;
1363 }
1364 break
1365 case 2:
1366 secondByte = buf[i + 1];
1367 if ((secondByte & 0xC0) === 0x80) {
1368 tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
1369 if (tempCodePoint > 0x7F) {
1370 codePoint = tempCodePoint;
1371 }
1372 }
1373 break
1374 case 3:
1375 secondByte = buf[i + 1];
1376 thirdByte = buf[i + 2];
1377 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
1378 tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
1379 if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
1380 codePoint = tempCodePoint;
1381 }
1382 }
1383 break
1384 case 4:
1385 secondByte = buf[i + 1];
1386 thirdByte = buf[i + 2];
1387 fourthByte = buf[i + 3];
1388 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
1389 tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
1390 if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
1391 codePoint = tempCodePoint;
1392 }
1393 }
1394 }
1395 }
1396
1397 if (codePoint === null) {
1398 // we did not generate a valid codePoint so insert a
1399 // replacement char (U+FFFD) and advance only 1 byte
1400 codePoint = 0xFFFD;
1401 bytesPerSequence = 1;
1402 } else if (codePoint > 0xFFFF) {
1403 // encode to utf16 (surrogate pair dance)
1404 codePoint -= 0x10000;
1405 res.push(codePoint >>> 10 & 0x3FF | 0xD800);
1406 codePoint = 0xDC00 | codePoint & 0x3FF;
1407 }
1408
1409 res.push(codePoint);
1410 i += bytesPerSequence;
1411 }
1412
1413 return decodeCodePointsArray(res)
1414 }
1415
1416 // Based on http://stackoverflow.com/a/22747272/680742, the browser with
1417 // the lowest limit is Chrome, with 0x10000 args.
1418 // We go 1 magnitude less, for safety
1419 var MAX_ARGUMENTS_LENGTH = 0x1000;
1420
1421 function decodeCodePointsArray (codePoints) {
1422 var len = codePoints.length;
1423 if (len <= MAX_ARGUMENTS_LENGTH) {
1424 return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
1425 }
1426
1427 // Decode in chunks to avoid "call stack size exceeded".
1428 var res = '';
1429 var i = 0;
1430 while (i < len) {
1431 res += String.fromCharCode.apply(
1432 String,
1433 codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
1434 );
1435 }
1436 return res
1437 }
1438
1439 function asciiSlice (buf, start, end) {
1440 var ret = '';
1441 end = Math.min(buf.length, end);
1442
1443 for (var i = start; i < end; ++i) {
1444 ret += String.fromCharCode(buf[i] & 0x7F);
1445 }
1446 return ret
1447 }
1448
1449 function latin1Slice (buf, start, end) {
1450 var ret = '';
1451 end = Math.min(buf.length, end);
1452
1453 for (var i = start; i < end; ++i) {
1454 ret += String.fromCharCode(buf[i]);
1455 }
1456 return ret
1457 }
1458
1459 function hexSlice (buf, start, end) {
1460 var len = buf.length;
1461
1462 if (!start || start < 0) start = 0;
1463 if (!end || end < 0 || end > len) end = len;
1464
1465 var out = '';
1466 for (var i = start; i < end; ++i) {
1467 out += toHex(buf[i]);
1468 }
1469 return out
1470 }
1471
1472 function utf16leSlice (buf, start, end) {
1473 var bytes = buf.slice(start, end);
1474 var res = '';
1475 for (var i = 0; i < bytes.length; i += 2) {
1476 res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
1477 }
1478 return res
1479 }
1480
1481 Buffer.prototype.slice = function slice (start, end) {
1482 var len = this.length;
1483 start = ~~start;
1484 end = end === undefined ? len : ~~end;
1485
1486 if (start < 0) {
1487 start += len;
1488 if (start < 0) start = 0;
1489 } else if (start > len) {
1490 start = len;
1491 }
1492
1493 if (end < 0) {
1494 end += len;
1495 if (end < 0) end = 0;
1496 } else if (end > len) {
1497 end = len;
1498 }
1499
1500 if (end < start) end = start;
1501
1502 var newBuf;
1503 if (Buffer.TYPED_ARRAY_SUPPORT) {
1504 newBuf = this.subarray(start, end);
1505 newBuf.__proto__ = Buffer.prototype;
1506 } else {
1507 var sliceLen = end - start;
1508 newBuf = new Buffer(sliceLen, undefined);
1509 for (var i = 0; i < sliceLen; ++i) {
1510 newBuf[i] = this[i + start];
1511 }
1512 }
1513
1514 return newBuf
1515 };
1516
1517 /*
1518 * Need to make sure that buffer isn't trying to write out of bounds.
1519 */
1520 function checkOffset (offset, ext, length) {
1521 if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
1522 if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
1523 }
1524
1525 Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
1526 offset = offset | 0;
1527 byteLength = byteLength | 0;
1528 if (!noAssert) checkOffset(offset, byteLength, this.length);
1529
1530 var val = this[offset];
1531 var mul = 1;
1532 var i = 0;
1533 while (++i < byteLength && (mul *= 0x100)) {
1534 val += this[offset + i] * mul;
1535 }
1536
1537 return val
1538 };
1539
1540 Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
1541 offset = offset | 0;
1542 byteLength = byteLength | 0;
1543 if (!noAssert) {
1544 checkOffset(offset, byteLength, this.length);
1545 }
1546
1547 var val = this[offset + --byteLength];
1548 var mul = 1;
1549 while (byteLength > 0 && (mul *= 0x100)) {
1550 val += this[offset + --byteLength] * mul;
1551 }
1552
1553 return val
1554 };
1555
1556 Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
1557 if (!noAssert) checkOffset(offset, 1, this.length);
1558 return this[offset]
1559 };
1560
1561 Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
1562 if (!noAssert) checkOffset(offset, 2, this.length);
1563 return this[offset] | (this[offset + 1] << 8)
1564 };
1565
1566 Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
1567 if (!noAssert) checkOffset(offset, 2, this.length);
1568 return (this[offset] << 8) | this[offset + 1]
1569 };
1570
1571 Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
1572 if (!noAssert) checkOffset(offset, 4, this.length);
1573
1574 return ((this[offset]) |
1575 (this[offset + 1] << 8) |
1576 (this[offset + 2] << 16)) +
1577 (this[offset + 3] * 0x1000000)
1578 };
1579
1580 Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
1581 if (!noAssert) checkOffset(offset, 4, this.length);
1582
1583 return (this[offset] * 0x1000000) +
1584 ((this[offset + 1] << 16) |
1585 (this[offset + 2] << 8) |
1586 this[offset + 3])
1587 };
1588
1589 Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
1590 offset = offset | 0;
1591 byteLength = byteLength | 0;
1592 if (!noAssert) checkOffset(offset, byteLength, this.length);
1593
1594 var val = this[offset];
1595 var mul = 1;
1596 var i = 0;
1597 while (++i < byteLength && (mul *= 0x100)) {
1598 val += this[offset + i] * mul;
1599 }
1600 mul *= 0x80;
1601
1602 if (val >= mul) val -= Math.pow(2, 8 * byteLength);
1603
1604 return val
1605 };
1606
1607 Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
1608 offset = offset | 0;
1609 byteLength = byteLength | 0;
1610 if (!noAssert) checkOffset(offset, byteLength, this.length);
1611
1612 var i = byteLength;
1613 var mul = 1;
1614 var val = this[offset + --i];
1615 while (i > 0 && (mul *= 0x100)) {
1616 val += this[offset + --i] * mul;
1617 }
1618 mul *= 0x80;
1619
1620 if (val >= mul) val -= Math.pow(2, 8 * byteLength);
1621
1622 return val
1623 };
1624
1625 Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
1626 if (!noAssert) checkOffset(offset, 1, this.length);
1627 if (!(this[offset] & 0x80)) return (this[offset])
1628 return ((0xff - this[offset] + 1) * -1)
1629 };
1630
1631 Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
1632 if (!noAssert) checkOffset(offset, 2, this.length);
1633 var val = this[offset] | (this[offset + 1] << 8);
1634 return (val & 0x8000) ? val | 0xFFFF0000 : val
1635 };
1636
1637 Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
1638 if (!noAssert) checkOffset(offset, 2, this.length);
1639 var val = this[offset + 1] | (this[offset] << 8);
1640 return (val & 0x8000) ? val | 0xFFFF0000 : val
1641 };
1642
1643 Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
1644 if (!noAssert) checkOffset(offset, 4, this.length);
1645
1646 return (this[offset]) |
1647 (this[offset + 1] << 8) |
1648 (this[offset + 2] << 16) |
1649 (this[offset + 3] << 24)
1650 };
1651
1652 Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
1653 if (!noAssert) checkOffset(offset, 4, this.length);
1654
1655 return (this[offset] << 24) |
1656 (this[offset + 1] << 16) |
1657 (this[offset + 2] << 8) |
1658 (this[offset + 3])
1659 };
1660
1661 Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
1662 if (!noAssert) checkOffset(offset, 4, this.length);
1663 return read(this, offset, true, 23, 4)
1664 };
1665
1666 Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
1667 if (!noAssert) checkOffset(offset, 4, this.length);
1668 return read(this, offset, false, 23, 4)
1669 };
1670
1671 Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
1672 if (!noAssert) checkOffset(offset, 8, this.length);
1673 return read(this, offset, true, 52, 8)
1674 };
1675
1676 Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
1677 if (!noAssert) checkOffset(offset, 8, this.length);
1678 return read(this, offset, false, 52, 8)
1679 };
1680
1681 function checkInt (buf, value, offset, ext, max, min) {
1682 if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
1683 if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
1684 if (offset + ext > buf.length) throw new RangeError('Index out of range')
1685 }
1686
1687 Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
1688 value = +value;
1689 offset = offset | 0;
1690 byteLength = byteLength | 0;
1691 if (!noAssert) {
1692 var maxBytes = Math.pow(2, 8 * byteLength) - 1;
1693 checkInt(this, value, offset, byteLength, maxBytes, 0);
1694 }
1695
1696 var mul = 1;
1697 var i = 0;
1698 this[offset] = value & 0xFF;
1699 while (++i < byteLength && (mul *= 0x100)) {
1700 this[offset + i] = (value / mul) & 0xFF;
1701 }
1702
1703 return offset + byteLength
1704 };
1705
1706 Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
1707 value = +value;
1708 offset = offset | 0;
1709 byteLength = byteLength | 0;
1710 if (!noAssert) {
1711 var maxBytes = Math.pow(2, 8 * byteLength) - 1;
1712 checkInt(this, value, offset, byteLength, maxBytes, 0);
1713 }
1714
1715 var i = byteLength - 1;
1716 var mul = 1;
1717 this[offset + i] = value & 0xFF;
1718 while (--i >= 0 && (mul *= 0x100)) {
1719 this[offset + i] = (value / mul) & 0xFF;
1720 }
1721
1722 return offset + byteLength
1723 };
1724
1725 Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
1726 value = +value;
1727 offset = offset | 0;
1728 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
1729 if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
1730 this[offset] = (value & 0xff);
1731 return offset + 1
1732 };
1733
1734 function objectWriteUInt16 (buf, value, offset, littleEndian) {
1735 if (value < 0) value = 0xffff + value + 1;
1736 for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
1737 buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
1738 (littleEndian ? i : 1 - i) * 8;
1739 }
1740 }
1741
1742 Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
1743 value = +value;
1744 offset = offset | 0;
1745 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
1746 if (Buffer.TYPED_ARRAY_SUPPORT) {
1747 this[offset] = (value & 0xff);
1748 this[offset + 1] = (value >>> 8);
1749 } else {
1750 objectWriteUInt16(this, value, offset, true);
1751 }
1752 return offset + 2
1753 };
1754
1755 Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
1756 value = +value;
1757 offset = offset | 0;
1758 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
1759 if (Buffer.TYPED_ARRAY_SUPPORT) {
1760 this[offset] = (value >>> 8);
1761 this[offset + 1] = (value & 0xff);
1762 } else {
1763 objectWriteUInt16(this, value, offset, false);
1764 }
1765 return offset + 2
1766 };
1767
1768 function objectWriteUInt32 (buf, value, offset, littleEndian) {
1769 if (value < 0) value = 0xffffffff + value + 1;
1770 for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
1771 buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff;
1772 }
1773 }
1774
1775 Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
1776 value = +value;
1777 offset = offset | 0;
1778 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
1779 if (Buffer.TYPED_ARRAY_SUPPORT) {
1780 this[offset + 3] = (value >>> 24);
1781 this[offset + 2] = (value >>> 16);
1782 this[offset + 1] = (value >>> 8);
1783 this[offset] = (value & 0xff);
1784 } else {
1785 objectWriteUInt32(this, value, offset, true);
1786 }
1787 return offset + 4
1788 };
1789
1790 Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
1791 value = +value;
1792 offset = offset | 0;
1793 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
1794 if (Buffer.TYPED_ARRAY_SUPPORT) {
1795 this[offset] = (value >>> 24);
1796 this[offset + 1] = (value >>> 16);
1797 this[offset + 2] = (value >>> 8);
1798 this[offset + 3] = (value & 0xff);
1799 } else {
1800 objectWriteUInt32(this, value, offset, false);
1801 }
1802 return offset + 4
1803 };
1804
1805 Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
1806 value = +value;
1807 offset = offset | 0;
1808 if (!noAssert) {
1809 var limit = Math.pow(2, 8 * byteLength - 1);
1810
1811 checkInt(this, value, offset, byteLength, limit - 1, -limit);
1812 }
1813
1814 var i = 0;
1815 var mul = 1;
1816 var sub = 0;
1817 this[offset] = value & 0xFF;
1818 while (++i < byteLength && (mul *= 0x100)) {
1819 if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
1820 sub = 1;
1821 }
1822 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
1823 }
1824
1825 return offset + byteLength
1826 };
1827
1828 Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
1829 value = +value;
1830 offset = offset | 0;
1831 if (!noAssert) {
1832 var limit = Math.pow(2, 8 * byteLength - 1);
1833
1834 checkInt(this, value, offset, byteLength, limit - 1, -limit);
1835 }
1836
1837 var i = byteLength - 1;
1838 var mul = 1;
1839 var sub = 0;
1840 this[offset + i] = value & 0xFF;
1841 while (--i >= 0 && (mul *= 0x100)) {
1842 if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
1843 sub = 1;
1844 }
1845 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
1846 }
1847
1848 return offset + byteLength
1849 };
1850
1851 Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
1852 value = +value;
1853 offset = offset | 0;
1854 if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
1855 if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
1856 if (value < 0) value = 0xff + value + 1;
1857 this[offset] = (value & 0xff);
1858 return offset + 1
1859 };
1860
1861 Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
1862 value = +value;
1863 offset = offset | 0;
1864 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
1865 if (Buffer.TYPED_ARRAY_SUPPORT) {
1866 this[offset] = (value & 0xff);
1867 this[offset + 1] = (value >>> 8);
1868 } else {
1869 objectWriteUInt16(this, value, offset, true);
1870 }
1871 return offset + 2
1872 };
1873
1874 Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
1875 value = +value;
1876 offset = offset | 0;
1877 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
1878 if (Buffer.TYPED_ARRAY_SUPPORT) {
1879 this[offset] = (value >>> 8);
1880 this[offset + 1] = (value & 0xff);
1881 } else {
1882 objectWriteUInt16(this, value, offset, false);
1883 }
1884 return offset + 2
1885 };
1886
1887 Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
1888 value = +value;
1889 offset = offset | 0;
1890 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
1891 if (Buffer.TYPED_ARRAY_SUPPORT) {
1892 this[offset] = (value & 0xff);
1893 this[offset + 1] = (value >>> 8);
1894 this[offset + 2] = (value >>> 16);
1895 this[offset + 3] = (value >>> 24);
1896 } else {
1897 objectWriteUInt32(this, value, offset, true);
1898 }
1899 return offset + 4
1900 };
1901
1902 Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
1903 value = +value;
1904 offset = offset | 0;
1905 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
1906 if (value < 0) value = 0xffffffff + value + 1;
1907 if (Buffer.TYPED_ARRAY_SUPPORT) {
1908 this[offset] = (value >>> 24);
1909 this[offset + 1] = (value >>> 16);
1910 this[offset + 2] = (value >>> 8);
1911 this[offset + 3] = (value & 0xff);
1912 } else {
1913 objectWriteUInt32(this, value, offset, false);
1914 }
1915 return offset + 4
1916 };
1917
1918 function checkIEEE754 (buf, value, offset, ext, max, min) {
1919 if (offset + ext > buf.length) throw new RangeError('Index out of range')
1920 if (offset < 0) throw new RangeError('Index out of range')
1921 }
1922
1923 function writeFloat (buf, value, offset, littleEndian, noAssert) {
1924 if (!noAssert) {
1925 checkIEEE754(buf, value, offset, 4);
1926 }
1927 write(buf, value, offset, littleEndian, 23, 4);
1928 return offset + 4
1929 }
1930
1931 Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
1932 return writeFloat(this, value, offset, true, noAssert)
1933 };
1934
1935 Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
1936 return writeFloat(this, value, offset, false, noAssert)
1937 };
1938
1939 function writeDouble (buf, value, offset, littleEndian, noAssert) {
1940 if (!noAssert) {
1941 checkIEEE754(buf, value, offset, 8);
1942 }
1943 write(buf, value, offset, littleEndian, 52, 8);
1944 return offset + 8
1945 }
1946
1947 Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
1948 return writeDouble(this, value, offset, true, noAssert)
1949 };
1950
1951 Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
1952 return writeDouble(this, value, offset, false, noAssert)
1953 };
1954
1955 // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
1956 Buffer.prototype.copy = function copy (target, targetStart, start, end) {
1957 if (!start) start = 0;
1958 if (!end && end !== 0) end = this.length;
1959 if (targetStart >= target.length) targetStart = target.length;
1960 if (!targetStart) targetStart = 0;
1961 if (end > 0 && end < start) end = start;
1962
1963 // Copy 0 bytes; we're done
1964 if (end === start) return 0
1965 if (target.length === 0 || this.length === 0) return 0
1966
1967 // Fatal error conditions
1968 if (targetStart < 0) {
1969 throw new RangeError('targetStart out of bounds')
1970 }
1971 if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
1972 if (end < 0) throw new RangeError('sourceEnd out of bounds')
1973
1974 // Are we oob?
1975 if (end > this.length) end = this.length;
1976 if (target.length - targetStart < end - start) {
1977 end = target.length - targetStart + start;
1978 }
1979
1980 var len = end - start;
1981 var i;
1982
1983 if (this === target && start < targetStart && targetStart < end) {
1984 // descending copy from end
1985 for (i = len - 1; i >= 0; --i) {
1986 target[i + targetStart] = this[i + start];
1987 }
1988 } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
1989 // ascending copy from start
1990 for (i = 0; i < len; ++i) {
1991 target[i + targetStart] = this[i + start];
1992 }
1993 } else {
1994 Uint8Array.prototype.set.call(
1995 target,
1996 this.subarray(start, start + len),
1997 targetStart
1998 );
1999 }
2000
2001 return len
2002 };
2003
2004 // Usage:
2005 // buffer.fill(number[, offset[, end]])
2006 // buffer.fill(buffer[, offset[, end]])
2007 // buffer.fill(string[, offset[, end]][, encoding])
2008 Buffer.prototype.fill = function fill (val, start, end, encoding) {
2009 // Handle string cases:
2010 if (typeof val === 'string') {
2011 if (typeof start === 'string') {
2012 encoding = start;
2013 start = 0;
2014 end = this.length;
2015 } else if (typeof end === 'string') {
2016 encoding = end;
2017 end = this.length;
2018 }
2019 if (val.length === 1) {
2020 var code = val.charCodeAt(0);
2021 if (code < 256) {
2022 val = code;
2023 }
2024 }
2025 if (encoding !== undefined && typeof encoding !== 'string') {
2026 throw new TypeError('encoding must be a string')
2027 }
2028 if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
2029 throw new TypeError('Unknown encoding: ' + encoding)
2030 }
2031 } else if (typeof val === 'number') {
2032 val = val & 255;
2033 }
2034
2035 // Invalid ranges are not set to a default, so can range check early.
2036 if (start < 0 || this.length < start || this.length < end) {
2037 throw new RangeError('Out of range index')
2038 }
2039
2040 if (end <= start) {
2041 return this
2042 }
2043
2044 start = start >>> 0;
2045 end = end === undefined ? this.length : end >>> 0;
2046
2047 if (!val) val = 0;
2048
2049 var i;
2050 if (typeof val === 'number') {
2051 for (i = start; i < end; ++i) {
2052 this[i] = val;
2053 }
2054 } else {
2055 var bytes = internalIsBuffer(val)
2056 ? val
2057 : utf8ToBytes(new Buffer(val, encoding).toString());
2058 var len = bytes.length;
2059 for (i = 0; i < end - start; ++i) {
2060 this[i + start] = bytes[i % len];
2061 }
2062 }
2063
2064 return this
2065 };
2066
2067 // HELPER FUNCTIONS
2068 // ================
2069
2070 var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
2071
2072 function base64clean (str) {
2073 // Node strips out invalid characters like \n and \t from the string, base64-js does not
2074 str = stringtrim(str).replace(INVALID_BASE64_RE, '');
2075 // Node converts strings with length < 2 to ''
2076 if (str.length < 2) return ''
2077 // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
2078 while (str.length % 4 !== 0) {
2079 str = str + '=';
2080 }
2081 return str
2082 }
2083
2084 function stringtrim (str) {
2085 if (str.trim) return str.trim()
2086 return str.replace(/^\s+|\s+$/g, '')
2087 }
2088
2089 function toHex (n) {
2090 if (n < 16) return '0' + n.toString(16)
2091 return n.toString(16)
2092 }
2093
2094 function utf8ToBytes (string, units) {
2095 units = units || Infinity;
2096 var codePoint;
2097 var length = string.length;
2098 var leadSurrogate = null;
2099 var bytes = [];
2100
2101 for (var i = 0; i < length; ++i) {
2102 codePoint = string.charCodeAt(i);
2103
2104 // is surrogate component
2105 if (codePoint > 0xD7FF && codePoint < 0xE000) {
2106 // last char was a lead
2107 if (!leadSurrogate) {
2108 // no lead yet
2109 if (codePoint > 0xDBFF) {
2110 // unexpected trail
2111 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
2112 continue
2113 } else if (i + 1 === length) {
2114 // unpaired lead
2115 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
2116 continue
2117 }
2118
2119 // valid lead
2120 leadSurrogate = codePoint;
2121
2122 continue
2123 }
2124
2125 // 2 leads in a row
2126 if (codePoint < 0xDC00) {
2127 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
2128 leadSurrogate = codePoint;
2129 continue
2130 }
2131
2132 // valid surrogate pair
2133 codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
2134 } else if (leadSurrogate) {
2135 // valid bmp char, but last char was a lead
2136 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
2137 }
2138
2139 leadSurrogate = null;
2140
2141 // encode utf8
2142 if (codePoint < 0x80) {
2143 if ((units -= 1) < 0) break
2144 bytes.push(codePoint);
2145 } else if (codePoint < 0x800) {
2146 if ((units -= 2) < 0) break
2147 bytes.push(
2148 codePoint >> 0x6 | 0xC0,
2149 codePoint & 0x3F | 0x80
2150 );
2151 } else if (codePoint < 0x10000) {
2152 if ((units -= 3) < 0) break
2153 bytes.push(
2154 codePoint >> 0xC | 0xE0,
2155 codePoint >> 0x6 & 0x3F | 0x80,
2156 codePoint & 0x3F | 0x80
2157 );
2158 } else if (codePoint < 0x110000) {
2159 if ((units -= 4) < 0) break
2160 bytes.push(
2161 codePoint >> 0x12 | 0xF0,
2162 codePoint >> 0xC & 0x3F | 0x80,
2163 codePoint >> 0x6 & 0x3F | 0x80,
2164 codePoint & 0x3F | 0x80
2165 );
2166 } else {
2167 throw new Error('Invalid code point')
2168 }
2169 }
2170
2171 return bytes
2172 }
2173
2174 function asciiToBytes (str) {
2175 var byteArray = [];
2176 for (var i = 0; i < str.length; ++i) {
2177 // Node's code seems to be doing this and not & 0x7F..
2178 byteArray.push(str.charCodeAt(i) & 0xFF);
2179 }
2180 return byteArray
2181 }
2182
2183 function utf16leToBytes (str, units) {
2184 var c, hi, lo;
2185 var byteArray = [];
2186 for (var i = 0; i < str.length; ++i) {
2187 if ((units -= 2) < 0) break
2188
2189 c = str.charCodeAt(i);
2190 hi = c >> 8;
2191 lo = c % 256;
2192 byteArray.push(lo);
2193 byteArray.push(hi);
2194 }
2195
2196 return byteArray
2197 }
2198
2199
2200 function base64ToBytes (str) {
2201 return toByteArray(base64clean(str))
2202 }
2203
2204 function blitBuffer (src, dst, offset, length) {
2205 for (var i = 0; i < length; ++i) {
2206 if ((i + offset >= dst.length) || (i >= src.length)) break
2207 dst[i + offset] = src[i];
2208 }
2209 return i
2210 }
2211
2212 function isnan (val) {
2213 return val !== val // eslint-disable-line no-self-compare
2214 }
2215
2216
2217 // the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
2218 // The _isBuffer check is for Safari 5-7 support, because it's missing
2219 // Object.prototype.constructor. Remove this eventually
2220 function isBuffer(obj) {
2221 return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
2222 }
2223
2224 function isFastBuffer (obj) {
2225 return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
2226 }
2227
2228 // For Node v0.10 support. Remove this eventually.
2229 function isSlowBuffer (obj) {
2230 return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0))
2231 }
2232
2233 var padString_1 = createCommonjsModule(function (module, exports) {
2234 Object.defineProperty(exports, "__esModule", { value: true });
2235 function padString(input) {
2236 var segmentLength = 4;
2237 var stringLength = input.length;
2238 var diff = stringLength % segmentLength;
2239 if (!diff) {
2240 return input;
2241 }
2242 var position = stringLength;
2243 var padLength = segmentLength - diff;
2244 var paddedStringLength = stringLength + padLength;
2245 var buffer = Buffer.alloc(paddedStringLength);
2246 buffer.write(input);
2247 while (padLength--) {
2248 buffer.write("=", position++);
2249 }
2250 return buffer.toString();
2251 }
2252 exports.default = padString;
2253 });
2254
2255 unwrapExports(padString_1);
2256
2257 var base64url_1 = createCommonjsModule(function (module, exports) {
2258 Object.defineProperty(exports, "__esModule", { value: true });
2259
2260 function encode(input, encoding) {
2261 if (encoding === void 0) { encoding = "utf8"; }
2262 if (isBuffer(input)) {
2263 return fromBase64(input.toString("base64"));
2264 }
2265 return fromBase64(Buffer.from(input, encoding).toString("base64"));
2266 }
2267 function decode(base64url, encoding) {
2268 if (encoding === void 0) { encoding = "utf8"; }
2269 return Buffer.from(toBase64(base64url), "base64").toString(encoding);
2270 }
2271 function toBase64(base64url) {
2272 base64url = base64url.toString();
2273 return padString_1.default(base64url)
2274 .replace(/\-/g, "+")
2275 .replace(/_/g, "/");
2276 }
2277 function fromBase64(base64) {
2278 return base64
2279 .replace(/=/g, "")
2280 .replace(/\+/g, "-")
2281 .replace(/\//g, "_");
2282 }
2283 function toBuffer(base64url) {
2284 return Buffer.from(toBase64(base64url), "base64");
2285 }
2286 var base64url = encode;
2287 base64url.encode = encode;
2288 base64url.decode = decode;
2289 base64url.toBase64 = toBase64;
2290 base64url.fromBase64 = fromBase64;
2291 base64url.toBuffer = toBuffer;
2292 exports.default = base64url;
2293 });
2294
2295 unwrapExports(base64url_1);
2296
2297 var base64url = createCommonjsModule(function (module) {
2298 module.exports = base64url_1.default;
2299 module.exports.default = module.exports;
2300 });
2301
2302 var utils = createCommonjsModule(function (module, exports) {
2303
2304 Object.defineProperty(exports, "__esModule", {
2305 value: true
2306 });
2307 exports.getEncodedMessage = exports.b64encode = exports.b64encodeJSON = exports.getDERfromPEM = exports.str2ab = exports.atob = void 0;
2308
2309 var _base64url = _interopRequireDefault(base64url);
2310
2311 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2312
2313 const atob = b64str => new Buffer(b64str, 'base64').toString('binary');
2314
2315 exports.atob = atob;
2316
2317 const str2ab = str => {
2318 const buf = new ArrayBuffer(str.length);
2319 const bufView = new Uint8Array(buf);
2320
2321 for (let i = 0, strLen = str.length; i < strLen; i++) {
2322 bufView[i] = str.charCodeAt(i);
2323 }
2324
2325 return buf;
2326 };
2327
2328 exports.str2ab = str2ab;
2329
2330 const getDERfromPEM = pem => {
2331 const pemB64 = pem.trim().split('\n').slice(1, -1) // Remove the --- BEGIN / END PRIVATE KEY ---
2332 .join();
2333 return str2ab(atob(pemB64));
2334 };
2335
2336 exports.getDERfromPEM = getDERfromPEM;
2337
2338 const b64encodeJSON = obj => _base64url.default.encode(str2ab(JSON.stringify(obj)));
2339
2340 exports.b64encodeJSON = b64encodeJSON;
2341 const b64encode = _base64url.default.encode;
2342 exports.b64encode = b64encode;
2343
2344 const getEncodedMessage = (header, payload) => {
2345 const encodedHeader = b64encodeJSON(header);
2346 const encodedPayload = b64encodeJSON(payload);
2347 const encodedMessage = `${encodedHeader}.${encodedPayload}`;
2348 return encodedMessage;
2349 };
2350
2351 exports.getEncodedMessage = getEncodedMessage;
2352 });
2353
2354 unwrapExports(utils);
2355 var utils_1 = utils.getEncodedMessage;
2356 var utils_2 = utils.b64encode;
2357 var utils_3 = utils.b64encodeJSON;
2358 var utils_4 = utils.getDERfromPEM;
2359 var utils_5 = utils.str2ab;
2360 var utils_6 = utils.atob;
2361
2362 (function() {
2363 /* istanbul ignore next */
2364 if (typeof globalThis === 'object') return;
2365 Object.defineProperty(Object.prototype, '__magic__', {
2366 get: function() {
2367 return this;
2368 },
2369 configurable: true, // This makes it possible to `delete` the getter later.
2370 });
2371 __magic__.globalThis = __magic__; // lolwat
2372 delete Object.prototype.__magic__;
2373 })();
2374
2375 var jwt = createCommonjsModule(function (module, exports) {
2376
2377 Object.defineProperty(exports, "__esModule", {
2378 value: true
2379 });
2380 exports.getTokenFromGCPServiceAccount = exports.getToken = exports.getHeader = void 0;
2381
2382
2383
2384
2385
2386 const algorithms = {
2387 RS256: {
2388 name: 'RSASSA-PKCS1-v1_5',
2389 hash: {
2390 name: 'SHA-256'
2391 }
2392 }
2393 };
2394
2395 const getHeader = (alg, headerAdditions) => ({ ...headerAdditions,
2396 alg,
2397 typ: 'JWT'
2398 }); // XXX https://developers.google.com/identity/protocols/OAuth2ServiceAccount#jwt-auth
2399
2400
2401 exports.getHeader = getHeader;
2402
2403 const getToken = async ({
2404 privateKeyPEM,
2405 payload,
2406 alg = 'RS256',
2407 cryptoImpl = null,
2408 headerAdditions = {}
2409 }) => {
2410 const algorithm = algorithms[alg];
2411
2412 if (!algorithm) {
2413 throw new Error(`@sagi.io/workers-jwt: Unsupported algorithm ${alg}.`);
2414 }
2415
2416 if (!globalThis.crypto) {
2417 if (!cryptoImpl) {
2418 throw new Error(`@sagi.io/workers-jwt: No crypto nor cryptoImpl were found.`);
2419 }
2420
2421 globalThis.crypto = cryptoImpl;
2422 }
2423
2424 const privateKeyDER = (0, utils.getDERfromPEM)(privateKeyPEM);
2425 const privateKey = await crypto.subtle.importKey('pkcs8', privateKeyDER, algorithm, false, ['sign']);
2426 const header = getHeader(alg, headerAdditions);
2427 const encodedMessage = (0, utils.getEncodedMessage)(header, payload);
2428 const encodedMessageArrBuf = (0, utils.str2ab)(encodedMessage);
2429 const signatureArrBuf = await crypto.subtle.sign(algorithms.RS256.name, privateKey, encodedMessageArrBuf);
2430 const encodedSignature = (0, utils.b64encode)(signatureArrBuf);
2431 const token = `${encodedMessage}.${encodedSignature}`;
2432 return token;
2433 }; // Service Account Authoriazation without OAuth2:
2434 // https://developers.google.com/identity/protocols/OAuth2ServiceAccount#jwt-auth
2435 // Service Account Auth for OAuth2 Tokens: Choose "HTTP / REST" for:
2436 // https://developers.google.com/identity/protocols/OAuth2ServiceAccount
2437
2438
2439 exports.getToken = getToken;
2440
2441 const getTokenFromGCPServiceAccount = async ({
2442 serviceAccountJSON,
2443 aud,
2444 alg = 'RS256',
2445 cryptoImpl = null,
2446 expiredAfter = 3600,
2447 headerAdditions = {},
2448 payloadAdditions = {}
2449 }) => {
2450 const {
2451 client_email: clientEmail,
2452 private_key_id: privateKeyId,
2453 private_key: privateKeyPEM
2454 } = serviceAccountJSON;
2455 Object.assign(headerAdditions, {
2456 kid: privateKeyId
2457 });
2458 const iat = parseInt(Date.now() / 1000);
2459 const exp = iat + expiredAfter;
2460 const iss = clientEmail;
2461 const sub = clientEmail;
2462 const payload = {
2463 aud,
2464 iss,
2465 sub,
2466 iat,
2467 exp,
2468 ...payloadAdditions
2469 };
2470 return getToken({
2471 privateKeyPEM,
2472 payload,
2473 alg,
2474 headerAdditions,
2475 cryptoImpl
2476 });
2477 };
2478
2479 exports.getTokenFromGCPServiceAccount = getTokenFromGCPServiceAccount;
2480 });
2481
2482 unwrapExports(jwt);
2483 var jwt_1 = jwt.getTokenFromGCPServiceAccount;
2484 var jwt_2 = jwt.getToken;
2485 var jwt_3 = jwt.getHeader;
2486
2487 const { getToken, getTokenFromGCPServiceAccount } = jwt;
2488
2489 var workersJwt = { getToken, getTokenFromGCPServiceAccount };
2490 var workersJwt_2 = workersJwt.getTokenFromGCPServiceAccount;
2491
2492 class GoogleDrive {
2493 constructor(auth) {
2494 this.auth = auth;
2495 this.expires = 0;
2496 this._getIdCache = new Map();
2497 }
2498
2499 async initializeClient() {
2500 // any method that do api call must call this beforehand
2501 if (Date.now() < this.expires) return;
2502
2503 if (this.auth.service_account && typeof this.auth.service_account_json != 'undefined') {
2504 const aud = this.auth.service_account_json.token_uri;
2505 const serviceAccountJSON = this.auth.service_account_json;
2506 const jwttoken = await workersJwt_2({
2507 serviceAccountJSON,
2508 aud,
2509 payloadAdditions: {
2510 scope: 'https://www.googleapis.com/auth/drive'
2511 }
2512 });
2513 const resp = await xf.post(serviceAccountJSON.token_uri, {
2514 urlencoded: {
2515 grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
2516 assertion: jwttoken
2517 }
2518 }).json();
2519 this.client = xf.extend({
2520 baseURI: 'https://www.googleapis.com/drive/v3/',
2521 headers: {
2522 Authorization: `Bearer ${resp.access_token}`
2523 }
2524 });
2525 } else {
2526 const resp = await xf.post('https://www.googleapis.com/oauth2/v4/token', {
2527 urlencoded: {
2528 client_id: this.auth.client_id,
2529 client_secret: this.auth.client_secret,
2530 refresh_token: this.auth.refresh_token,
2531 grant_type: 'refresh_token'
2532 }
2533 }).json();
2534 this.client = xf.extend({
2535 baseURI: 'https://www.googleapis.com/drive/v3/',
2536 headers: {
2537 Authorization: `Bearer ${resp.access_token}`
2538 }
2539 });
2540 }
2541
2542 this.expires = Date.now() + 3500 * 1000; // normally, it should expiers after 3600 seconds
2543 }
2544
2545 async listDrive() {
2546 await this.initializeClient();
2547 return this.client.get('drives').json();
2548 }
2549
2550 async download(id, range = '') {
2551 await this.initializeClient();
2552 return this.client.get(`files/${id}`, {
2553 qs: {
2554 includeItemsFromAllDrives: true,
2555 supportsAllDrives: true,
2556 alt: 'media'
2557 },
2558 headers: {
2559 Range: range
2560 }
2561 });
2562 }
2563
2564 async downloadByPath(path, rootId = 'root', range = '') {
2565 const id = await this.getId(path, rootId);
2566 if (!id) return null;
2567 return this.download(id, range);
2568 }
2569
2570 async getMeta(id) {
2571 await this.initializeClient();
2572 return this.client.get(`files/${id}`, {
2573 qs: {
2574 includeItemsFromAllDrives: true,
2575 supportsAllDrives: true,
2576 fields: '*'
2577 }
2578 }).json();
2579 }
2580
2581 async getMetaByPath(path, rootId = 'root') {
2582 const id = await this.getId(path, rootId);
2583 if (!id) return null;
2584 return this.getMeta(id);
2585 }
2586
2587 async listFolder(id) {
2588 await this.initializeClient();
2589
2590 const getList = pageToken => {
2591 const qs = {
2592 includeItemsFromAllDrives: true,
2593 supportsAllDrives: true,
2594 q: `'${id}' in parents and trashed = false`,
2595 orderBy: 'folder,name,modifiedTime desc',
2596 fields: 'files(id,name,mimeType,size,modifiedTime),nextPageToken',
2597 pageSize: 1000
2598 };
2599
2600 if (pageToken) {
2601 qs.pageToken = pageToken;
2602 }
2603
2604 return this.client.get('files', {
2605 qs
2606 }).json();
2607 };
2608
2609 const files = [];
2610 let pageToken;
2611
2612 do {
2613 const resp = await getList(pageToken);
2614 files.push(...resp.files);
2615 pageToken = resp.nextPageToken;
2616 } while (pageToken);
2617
2618 return {
2619 files
2620 };
2621 }
2622
2623 async listFolderByPath(path, rootId = 'root') {
2624 const id = await this.getId(path, rootId);
2625 if (!id) return null;
2626 return this.listFolder(id);
2627 }
2628
2629 async getId(path, rootId = 'root') {
2630 const toks = path.split('/').filter(Boolean);
2631 let id = rootId;
2632
2633 for (const tok of toks) {
2634 id = await this._getId(id, tok);
2635 }
2636
2637 return id;
2638 }
2639
2640 async _getId(parentId, childName) {
2641 if (this._getIdCache.has(parentId + childName)) {
2642 return this._getIdCache.get(parentId + childName);
2643 }
2644
2645 await this.initializeClient();
2646 childName = childName.replace(/\'/g, `\\'`); // escape single quote
2647
2648 const resp = await this.client.get('files', {
2649 qs: {
2650 includeItemsFromAllDrives: true,
2651 supportsAllDrives: true,
2652 q: `'${parentId}' in parents and name = '${childName}' and trashed = false`,
2653 fields: 'files(id)'
2654 }
2655 }).json().catch(e => ({
2656 files: []
2657 })); // if error, make it empty
2658
2659 if (resp.files.length === 0) {
2660 return null;
2661 }
2662
2663 this._getIdCache.has(parentId + childName);
2664
2665 return resp.files[0].id; // when there are more than 1 items, simply return the first one
2666 }
2667
2668 async upload(parentId, name, file) {
2669 await this.initializeClient();
2670 const createResp = await this.client.post('https://www.googleapis.com/upload/drive/v3/files', {
2671 qs: {
2672 uploadType: 'resumable',
2673 supportsAllDrives: true
2674 },
2675 json: {
2676 name,
2677 parents: [parentId]
2678 }
2679 });
2680 const putUrl = createResp.headers.get('Location');
2681 return this.client.put(putUrl, {
2682 body: file
2683 }).json();
2684 }
2685
2686 async uploadByPath(path, name, file, rootId = 'root') {
2687 const id = await this.getId(path, rootId);
2688 if (!id) return null;
2689 return this.upload(id, name, file);
2690 }
2691
2692 async delete(fileId) {
2693 return this.client.delete(`files/${fileId}`);
2694 }
2695
2696 async deleteByPath(path, rootId = 'root') {
2697 const id = await this.getId(path, rootId);
2698 if (!id) return null;
2699 return this.delete(id);
2700 }
2701
2702 }
2703
2704 const gd = new GoogleDrive(self.props);
2705 const HTML = `<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><title>${self.props.title}</title><link href="/~_~_gdindex/resources/css/app.css" rel=stylesheet></head><body><script>window.props = { title: '${self.props.title}', default_root_id: '${self.props.default_root_id}', api: location.protocol + '//' + location.host, upload: ${self.props.upload} }<\/script><div id=app></div><script src="/~_~_gdindex/resources/js/app.js"><\/script></body></html>`;
2706
2707 async function onGet(request) {
2708 let {
2709 pathname: path
2710 } = request;
2711 const rootId = request.searchParams.get('rootId') || self.props.default_root_id;
2712
2713 if (path.startsWith('/~_~_gdindex/resources/')) {
2714 const remain = path.replace('/~_~_gdindex/resources/', '');
2715 const r = await fetch(`https://raw.githubusercontent.com/maple3142/GDIndex/master/web/dist/${remain}`);
2716 return new Response(r.body, {
2717 headers: {
2718 'Content-Type': mime.getType(remain) + '; charset=utf-8',
2719 'Cache-Control': 'max-age=600'
2720 }
2721 });
2722 } else if (path === '/~_~_gdindex/drives') {
2723 return new Response(JSON.stringify(await gd.listDrive()), {
2724 headers: {
2725 'Content-Type': 'application/json'
2726 }
2727 });
2728 } else if (path.substr(-1) === '/' || path.startsWith('/~viewer')) {
2729 return new Response(HTML, {
2730 headers: {
2731 'Content-Type': 'text/html; charset=utf-8'
2732 }
2733 });
2734 } else {
2735 const result = await gd.getMetaByPath(path, rootId);
2736
2737 if (!result) {
2738 return new Response('null', {
2739 headers: {
2740 'Content-Type': 'application/json'
2741 },
2742 status: 404
2743 });
2744 }
2745
2746 const isGoogleApps = result.mimeType.includes('vnd.google-apps');
2747
2748 if (!isGoogleApps) {
2749 const r = await gd.download(result.id, request.headers.get('Range'));
2750 const h = new Headers(r.headers);
2751 h.set('Content-Disposition', `inline; filename*=UTF-8''${encodeURIComponent(result.name)}`);
2752 return new Response(r.body, {
2753 status: r.status,
2754 headers: h
2755 });
2756 } else {
2757 return Response.redirect(result.webViewLink, 302);
2758 }
2759 }
2760 }
2761
2762 async function onPost(request) {
2763 let {
2764 pathname: path
2765 } = request;
2766 const rootId = request.searchParams.get('rootId') || self.props.default_root_id;
2767
2768 if (path.substr(-1) === '/') {
2769 return new Response(JSON.stringify(await gd.listFolderByPath(path, rootId)), {
2770 headers: {
2771 'Content-Type': 'application/json'
2772 }
2773 });
2774 } else {
2775 const result = await gd.getMetaByPath(path, rootId);
2776
2777 if (!result) {
2778 return new Response('null', {
2779 headers: {
2780 'Content-Type': 'application/json'
2781 },
2782 status: 404
2783 });
2784 }
2785
2786 const isGoogleApps = result.mimeType.includes('vnd.google-apps');
2787
2788 if (!isGoogleApps) {
2789 const r = await gd.download(result.id, request.headers.get('Range'));
2790 const h = new Headers(r.headers);
2791 h.set('Content-Disposition', `inline; filename*=UTF-8''${encodeURIComponent(result.name)}`);
2792 return new Response(r.body, {
2793 status: r.status,
2794 headers: h
2795 });
2796 } else {
2797 return Response.redirect(result.webViewLink, 302);
2798 }
2799 }
2800 }
2801
2802 async function onPut(request) {
2803 if (!self.props.upload) {
2804 return new Response("Upload isn't enabled.", {
2805 headers: {
2806 'Content-Type': 'text/plain'
2807 },
2808 status: 405
2809 });
2810 }
2811
2812 let {
2813 pathname: path
2814 } = request;
2815
2816 if (path.substr(-1) === '/') {
2817 return new Response(null, {
2818 headers: {
2819 'Content-Type': 'application/json'
2820 },
2821 status: 405
2822 });
2823 }
2824
2825 const url = request.searchParams.get('url');
2826 let fileBody;
2827
2828 if (url) {
2829 const u = new URL(url);
2830 const Referer = u.href;
2831 const Origin = u.protocol + '//' + u.host;
2832 fileBody = (await fetch(url, {
2833 headers: {
2834 Referer,
2835 Origin
2836 }
2837 })).body;
2838 } else {
2839 fileBody = request.body;
2840 }
2841
2842 const tok = path.split('/');
2843 const name = tok.pop();
2844 const parent = tok.join('/');
2845 const rootId = request.searchParams.get('rootId') || self.props.default_root_id;
2846 return new Response(JSON.stringify(await gd.uploadByPath(parent, name, fileBody, rootId)), {
2847 headers: {
2848 'Content-Type': 'application/json'
2849 }
2850 });
2851 }
2852
2853 function unauthorized() {
2854 return new Response('Unauthorized', {
2855 headers: {
2856 'WWW-Authenticate': 'Basic realm="goindex"',
2857 'Access-Control-Allow-Origin': '*'
2858 },
2859 status: 401
2860 });
2861 }
2862
2863 function parseBasicAuth(auth) {
2864 try {
2865 return atob(auth.split(' ').pop()).split(':');
2866 } catch (e) {
2867 return [];
2868 }
2869 }
2870
2871 function doBasicAuth(request) {
2872 const auth = request.headers.get('Authorization');
2873
2874 if (!auth || !/^Basic [A-Za-z0-9._~+/-]+=*$/i.test(auth)) {
2875 return false;
2876 }
2877
2878 const [user, pass] = parseBasicAuth(auth);
2879 return user === self.props.user && pass === self.props.pass;
2880 }
2881
2882 function encodePathComponent(path) {
2883 return path.split('/').map(encodeURIComponent).join('/');
2884 }
2885
2886 async function handleRequest(request) {
2887 if (request.method === 'OPTIONS') // allow preflight request
2888 return new Response('', {
2889 status: 200,
2890 headers: {
2891 'Access-Control-Allow-Origin': '*',
2892 'Access-Control-Allow-Headers': '*',
2893 'Access-Control-Allow-Methods': 'GET, POST, PUT, HEAD, OPTIONS'
2894 }
2895 });
2896
2897 if (self.props.auth && !doBasicAuth(request)) {
2898 return unauthorized();
2899 }
2900
2901 request = Object.assign({}, request, new URL(request.url));
2902 request.pathname = request.pathname.split('/').map(decodeURIComponent).map(decodeURIComponent) // for some super special cases, browser will force encode it... eg: +αあるふぁきゅん。 - +♂.mp3
2903 .join('/');
2904
2905 if ((self.props.lite || request.headers.get('x-lite') == 'true') && request.pathname.endsWith('/')) {
2906 // lite mode
2907 const path = request.pathname;
2908 let parent = encodePathComponent(path.split('/').slice(0, -2).join('/') + '/');
2909 const {
2910 files
2911 } = await gd.listFolderByPath(path, self.props.default_root_id);
2912 let fileht = '';
2913
2914 for (const f of files) {
2915 const isf = f.mimeType === 'application/vnd.google-apps.folder';
2916 const p = encodePathComponent(path + f.name);
2917 fileht += `<li><a href="${p + (isf ? '/' : '')}">${f.name}</a></li>`;
2918 }
2919
2920 const ht = `<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2921<html>
2922<head>
2923<title>Index of ${path}</title>
2924</head>
2925<body>
2926<h1>Index of ${path}</h1>
2927<ul>
2928<li><a href="${parent}"> Parent Directory</a></li>
2929${fileht}
2930</ul>
2931</body>
2932</html>`;
2933 return new Response(ht, {
2934 status: 200,
2935 headers: {
2936 'Content-Type': 'text/html; charset=utf-8'
2937 }
2938 });
2939 }
2940
2941 let resp;
2942 if (request.method === 'GET') resp = await onGet(request);else if (request.method === 'POST') resp = await onPost(request);else if (request.method === 'PUT') resp = await onPut(request);else resp = new Response('', {
2943 status: 405
2944 });
2945 const obj = Object.create(null);
2946
2947 for (const [k, v] of resp.headers.entries()) {
2948 obj[k] = v;
2949 }
2950
2951 return new Response(resp.body, {
2952 status: resp.status,
2953 statusText: resp.statusText,
2954 headers: Object.assign(obj, {
2955 'Access-Control-Allow-Origin': '*'
2956 })
2957 });
2958 }
2959
2960 addEventListener('fetch', event => {
2961 event.respondWith(handleRequest(event.request).catch(err => {
2962 console.error(err);
2963 return new Response(JSON.stringify(err.stack), {
2964 status: 500,
2965 headers: {
2966 'Content-Type': 'application/json'
2967 }
2968 });
2969 }));
2970 });
2971
2972}());
2973