1 | (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
|
2 | (function (process){(function (){
|
3 | "use strict";
|
4 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
5 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
6 | };
|
7 | const http_1 = __importDefault(require("http"));
|
8 | const https_1 = __importDefault(require("https"));
|
9 | const stream_1 = require("stream");
|
10 | const httpLibs = { 'http:': http_1.default, 'https:': https_1.default };
|
11 | const redirectStatusCodes = new Set([301, 302, 303, 307, 308]);
|
12 | const retryStatusCodes = new Set([429, 503]);
|
13 |
|
14 | const requestEvents = ['connect', 'continue', 'information', 'socket', 'timeout', 'upgrade'];
|
15 | const responseEvents = ['aborted'];
|
16 | Miniget.MinigetError = class MinigetError extends Error {
|
17 | constructor(message, statusCode) {
|
18 | super(message);
|
19 | this.statusCode = statusCode;
|
20 | }
|
21 | };
|
22 | Miniget.defaultOptions = {
|
23 | maxRedirects: 10,
|
24 | maxRetries: 2,
|
25 | maxReconnects: 0,
|
26 | backoff: { inc: 100, max: 10000 },
|
27 | };
|
28 | function Miniget(url, options = {}) {
|
29 | var _a;
|
30 | const opts = Object.assign({}, Miniget.defaultOptions, options);
|
31 | const stream = new stream_1.PassThrough({ highWaterMark: opts.highWaterMark });
|
32 | stream.destroyed = stream.aborted = false;
|
33 | let activeRequest;
|
34 | let activeResponse;
|
35 | let activeDecodedStream;
|
36 | let redirects = 0;
|
37 | let retries = 0;
|
38 | let retryTimeout;
|
39 | let reconnects = 0;
|
40 | let contentLength;
|
41 | let acceptRanges = false;
|
42 | let rangeStart = 0, rangeEnd;
|
43 | let downloaded = 0;
|
44 |
|
45 | if ((_a = opts.headers) === null || _a === void 0 ? void 0 : _a.Range) {
|
46 | let r = /bytes=(\d+)-(\d+)?/.exec(`${opts.headers.Range}`);
|
47 | if (r) {
|
48 | rangeStart = parseInt(r[1], 10);
|
49 | rangeEnd = parseInt(r[2], 10);
|
50 | }
|
51 | }
|
52 |
|
53 | if (opts.acceptEncoding) {
|
54 | opts.headers = Object.assign({
|
55 | 'Accept-Encoding': Object.keys(opts.acceptEncoding).join(', '),
|
56 | }, opts.headers);
|
57 | }
|
58 | const downloadHasStarted = () => activeDecodedStream && downloaded > 0;
|
59 | const downloadComplete = () => !acceptRanges || downloaded === contentLength;
|
60 | const reconnect = (err) => {
|
61 | activeDecodedStream = null;
|
62 | retries = 0;
|
63 | let inc = opts.backoff.inc;
|
64 | let ms = Math.min(inc, opts.backoff.max);
|
65 | retryTimeout = setTimeout(doDownload, ms);
|
66 | stream.emit('reconnect', reconnects, err);
|
67 | };
|
68 | const reconnectIfEndedEarly = (err) => {
|
69 | if (options.method !== 'HEAD' && !downloadComplete() && reconnects++ < opts.maxReconnects) {
|
70 | reconnect(err);
|
71 | return true;
|
72 | }
|
73 | return false;
|
74 | };
|
75 | const retryRequest = (retryOptions) => {
|
76 | if (stream.destroyed) {
|
77 | return false;
|
78 | }
|
79 | if (downloadHasStarted()) {
|
80 | return reconnectIfEndedEarly(retryOptions.err);
|
81 | }
|
82 | else if ((!retryOptions.err || retryOptions.err.message === 'ENOTFOUND') &&
|
83 | retries++ < opts.maxRetries) {
|
84 | let ms = retryOptions.retryAfter ||
|
85 | Math.min(retries * opts.backoff.inc, opts.backoff.max);
|
86 | retryTimeout = setTimeout(doDownload, ms);
|
87 | stream.emit('retry', retries, retryOptions.err);
|
88 | return true;
|
89 | }
|
90 | return false;
|
91 | };
|
92 | const forwardEvents = (ee, events) => {
|
93 | for (let event of events) {
|
94 | ee.on(event, stream.emit.bind(stream, event));
|
95 | }
|
96 | };
|
97 | const doDownload = () => {
|
98 | let parsed = {}, httpLib;
|
99 | try {
|
100 | let urlObj = typeof url === 'string' ? new URL(url) : url;
|
101 | parsed = Object.assign({}, {
|
102 | host: urlObj.host,
|
103 | hostname: urlObj.hostname,
|
104 | path: urlObj.pathname + urlObj.search + urlObj.hash,
|
105 | port: urlObj.port,
|
106 | protocol: urlObj.protocol,
|
107 | });
|
108 | if (urlObj.username) {
|
109 | parsed.auth = `${urlObj.username}:${urlObj.password}`;
|
110 | }
|
111 | httpLib = httpLibs[String(parsed.protocol)];
|
112 | }
|
113 | catch (err) {
|
114 | // Let the error be caught by the if statement below.
|
115 | }
|
116 | if (!httpLib) {
|
117 | stream.emit('error', new Miniget.MinigetError(`Invalid URL: ${url}`));
|
118 | return;
|
119 | }
|
120 | Object.assign(parsed, opts);
|
121 | if (acceptRanges && downloaded > 0) {
|
122 | let start = downloaded + rangeStart;
|
123 | let end = rangeEnd || '';
|
124 | parsed.headers = Object.assign({}, parsed.headers, {
|
125 | Range: `bytes=${start}-${end}`,
|
126 | });
|
127 | }
|
128 | if (opts.transform) {
|
129 | try {
|
130 | parsed = opts.transform(parsed);
|
131 | }
|
132 | catch (err) {
|
133 | stream.emit('error', err);
|
134 | return;
|
135 | }
|
136 | if (!parsed || parsed.protocol) {
|
137 | httpLib = httpLibs[String(parsed === null || parsed === void 0 ? void 0 : parsed.protocol)];
|
138 | if (!httpLib) {
|
139 | stream.emit('error', new Miniget.MinigetError('Invalid URL object from `transform` function'));
|
140 | return;
|
141 | }
|
142 | }
|
143 | }
|
144 | const onError = (err) => {
|
145 | if (stream.destroyed || stream.readableEnded) {
|
146 | return;
|
147 | }
|
148 | // Needed for node v10.
|
149 | if (stream._readableState.ended) {
|
150 | return;
|
151 | }
|
152 | cleanup();
|
153 | if (!retryRequest({ err })) {
|
154 | stream.emit('error', err);
|
155 | }
|
156 | else {
|
157 | activeRequest.removeListener('close', onRequestClose);
|
158 | }
|
159 | };
|
160 | const onRequestClose = () => {
|
161 | cleanup();
|
162 | retryRequest({});
|
163 | };
|
164 | const cleanup = () => {
|
165 | activeRequest.removeListener('close', onRequestClose);
|
166 | activeResponse === null || activeResponse === void 0 ? void 0 : activeResponse.removeListener('data', onData);
|
167 | activeDecodedStream === null || activeDecodedStream === void 0 ? void 0 : activeDecodedStream.removeListener('end', onEnd);
|
168 | };
|
169 | const onData = (chunk) => { downloaded += chunk.length; };
|
170 | const onEnd = () => {
|
171 | cleanup();
|
172 | if (!reconnectIfEndedEarly()) {
|
173 | stream.end();
|
174 | }
|
175 | };
|
176 | activeRequest = httpLib.request(parsed, (res) => {
|
177 | // Needed for node v10, v12.
|
178 | // istanbul ignore next
|
179 | if (stream.destroyed) {
|
180 | return;
|
181 | }
|
182 | if (redirectStatusCodes.has(res.statusCode)) {
|
183 | if (redirects++ >= opts.maxRedirects) {
|
184 | stream.emit('error', new Miniget.MinigetError('Too many redirects'));
|
185 | }
|
186 | else {
|
187 | if (res.headers.location) {
|
188 | url = res.headers.location;
|
189 | }
|
190 | else {
|
191 | let err = new Miniget.MinigetError('Redirect status code given with no location', res.statusCode);
|
192 | stream.emit('error', err);
|
193 | cleanup();
|
194 | return;
|
195 | }
|
196 | setTimeout(doDownload, parseInt(res.headers['retry-after'] || '0', 10) * 1000);
|
197 | stream.emit('redirect', url);
|
198 | }
|
199 | cleanup();
|
200 | return;
|
201 | // Check for rate limiting.
|
202 | }
|
203 | else if (retryStatusCodes.has(res.statusCode)) {
|
204 | if (!retryRequest({ retryAfter: parseInt(res.headers['retry-after'] || '0', 10) })) {
|
205 | let err = new Miniget.MinigetError(`Status code: ${res.statusCode}`, res.statusCode);
|
206 | stream.emit('error', err);
|
207 | }
|
208 | cleanup();
|
209 | return;
|
210 | }
|
211 | else if (res.statusCode && (res.statusCode < 200 || res.statusCode >= 400)) {
|
212 | let err = new Miniget.MinigetError(`Status code: ${res.statusCode}`, res.statusCode);
|
213 | if (res.statusCode >= 500) {
|
214 | onError(err);
|
215 | }
|
216 | else {
|
217 | stream.emit('error', err);
|
218 | }
|
219 | cleanup();
|
220 | return;
|
221 | }
|
222 | activeDecodedStream = res;
|
223 | if (opts.acceptEncoding && res.headers['content-encoding']) {
|
224 | for (let enc of res.headers['content-encoding'].split(', ').reverse()) {
|
225 | let fn = opts.acceptEncoding[enc];
|
226 | if (fn) {
|
227 | activeDecodedStream = activeDecodedStream.pipe(fn());
|
228 | activeDecodedStream.on('error', onError);
|
229 | }
|
230 | }
|
231 | }
|
232 | if (!contentLength) {
|
233 | contentLength = parseInt(`${res.headers['content-length']}`, 10);
|
234 | acceptRanges = res.headers['accept-ranges'] === 'bytes' &&
|
235 | contentLength > 0 && opts.maxReconnects > 0;
|
236 | }
|
237 | res.on('data', onData);
|
238 | activeDecodedStream.on('end', onEnd);
|
239 | activeDecodedStream.pipe(stream, { end: !acceptRanges });
|
240 | activeResponse = res;
|
241 | stream.emit('response', res);
|
242 | res.on('error', onError);
|
243 | forwardEvents(res, responseEvents);
|
244 | });
|
245 | activeRequest.on('error', onError);
|
246 | activeRequest.on('close', onRequestClose);
|
247 | forwardEvents(activeRequest, requestEvents);
|
248 | if (stream.destroyed) {
|
249 | streamDestroy(...destroyArgs);
|
250 | }
|
251 | stream.emit('request', activeRequest);
|
252 | activeRequest.end();
|
253 | };
|
254 | stream.abort = (err) => {
|
255 | console.warn('`MinigetStream#abort()` has been deprecated in favor of `MinigetStream#destroy()`');
|
256 | stream.aborted = true;
|
257 | stream.emit('abort');
|
258 | stream.destroy(err);
|
259 | };
|
260 | let destroyArgs;
|
261 | const streamDestroy = (err) => {
|
262 | activeRequest.destroy(err);
|
263 | activeDecodedStream === null || activeDecodedStream === void 0 ? void 0 : activeDecodedStream.unpipe(stream);
|
264 | activeDecodedStream === null || activeDecodedStream === void 0 ? void 0 : activeDecodedStream.destroy();
|
265 | clearTimeout(retryTimeout);
|
266 | };
|
267 | stream._destroy = (...args) => {
|
268 | stream.destroyed = true;
|
269 | if (activeRequest) {
|
270 | streamDestroy(...args);
|
271 | }
|
272 | else {
|
273 | destroyArgs = args;
|
274 | }
|
275 | };
|
276 | stream.text = () => new Promise((resolve, reject) => {
|
277 | let body = '';
|
278 | stream.setEncoding('utf8');
|
279 | stream.on('data', chunk => body += chunk);
|
280 | stream.on('end', () => resolve(body));
|
281 | stream.on('error', reject);
|
282 | });
|
283 | process.nextTick(doDownload);
|
284 | return stream;
|
285 | }
|
286 | module.exports = Miniget;
|
287 |
|
288 | }).call(this)}).call(this,require('_process'))
|
289 | },{"_process":11,"http":32,"https":8,"stream":17}],2:[function(require,module,exports){
|
290 | const miniget = require('miniget')
|
291 |
|
292 | module.exports = async (query, options = {}) => {
|
293 | const response = await miniget(
|
294 | `https://www.youtube.com/results?search_query=${encodeURIComponent(query)}`, options
|
295 | ).text()
|
296 | const match = response.match(/(window\["ytInitialData"]|var ytInitialData)\s*=\s*(.*)};\s*<\/script>/)
|
297 | const json = JSON.parse(match[2].trim() + "}")
|
298 | const result = json
|
299 | ['contents']['twoColumnSearchResultsRenderer']['primaryContents']['sectionListRenderer']
|
300 | ['contents'][0]['itemSectionRenderer']['contents']
|
301 | return result.filter(video => {
|
302 | const type = Object.keys(video)[0].replace('Renderer', '')
|
303 | if (options.filter === 'video') return type === 'video'
|
304 | else if (options.filter === 'playlist') return type === 'playlist'
|
305 | else return ['video', 'playlist'].includes(type)
|
306 | }).map(video => {
|
307 | const type = Object.keys(video)[0].replace('Renderer', '')
|
308 | const data = video[type + 'Renderer']
|
309 | const identifier = data[type + 'Id']
|
310 | if (type === 'video') {
|
311 | const isStream = !Object.keys(data).includes('lengthText')
|
312 | let length = Number.MAX_VALUE
|
313 | if (!isStream) {
|
314 | length = 0
|
315 | data['lengthText']['simpleText'].split(':').reverse().forEach((value, index) => {
|
316 | const i = Number(value)
|
317 | length += (index === 0 ? i : i * (60 ** index))
|
318 | })
|
319 | }
|
320 | return {
|
321 | type: type,
|
322 | identifier: identifier,
|
323 | uri: 'https://www.youtube.com/watch?v=' + identifier,
|
324 | title: data['title']['runs'][0]['text'],
|
325 | author: {
|
326 | name: data['ownerText']['runs'][0]['text'],
|
327 | profile: data['channelThumbnailSupportedRenderers']['channelThumbnailWithLinkRenderer']
|
328 | ['thumbnail']['thumbnails'][0]['url'],
|
329 | uri: 'https://www.youtube.com' + data['ownerText']['runs'][0]['navigationEndpoint']
|
330 | ['commandMetadata']['webCommandMetadata']['url']
|
331 | },
|
332 | length: {
|
333 | ms: isStream ? length : length * 1000,
|
334 | sec: length
|
335 | },
|
336 | isStream: isStream,
|
337 | thumbnails: data['thumbnail']['thumbnails']
|
338 | }
|
339 | } else return {
|
340 | type: type,
|
341 | identifier: identifier,
|
342 | uri: 'https://www.youtube.com/playlist?list=' + identifier,
|
343 | title: data['title']['simpleText'],
|
344 | author: {
|
345 | name: data['longBylineText']['runs'][0]['text'],
|
346 | uri: 'https://www.youtube.com' + data['longBylineText']['runs'][0]['navigationEndpoint']
|
347 | ['commandMetadata']['webCommandMetadata']['url']
|
348 | },
|
349 | count: Number(data['videoCount']),
|
350 | thumbnails: data['thumbnails']
|
351 | }
|
352 | })
|
353 | }
|
354 |
|
355 | },{"miniget":1}],3:[function(require,module,exports){
|
356 | 'use strict'
|
357 |
|
358 | exports.byteLength = byteLength
|
359 | exports.toByteArray = toByteArray
|
360 | exports.fromByteArray = fromByteArray
|
361 |
|
362 | var lookup = []
|
363 | var revLookup = []
|
364 | var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
|
365 |
|
366 | var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
367 | for (var i = 0, len = code.length; i < len; ++i) {
|
368 | lookup[i] = code[i]
|
369 | revLookup[code.charCodeAt(i)] = i
|
370 | }
|
371 |
|
372 | // Support decoding URL-safe base64 strings, as Node.js does.
|
373 | // See: https://en.wikipedia.org/wiki/Base64#URL_applications
|
374 | revLookup['-'.charCodeAt(0)] = 62
|
375 | revLookup['_'.charCodeAt(0)] = 63
|
376 |
|
377 | function getLens (b64) {
|
378 | var len = b64.length
|
379 |
|
380 | if (len % 4 > 0) {
|
381 | throw new Error('Invalid string. Length must be a multiple of 4')
|
382 | }
|
383 |
|
384 | // Trim off extra bytes after placeholder bytes are found
|
385 | // See: https://github.com/beatgammit/base64-js/issues/42
|
386 | var validLen = b64.indexOf('=')
|
387 | if (validLen === -1) validLen = len
|
388 |
|
389 | var placeHoldersLen = validLen === len
|
390 | ? 0
|
391 | : 4 - (validLen % 4)
|
392 |
|
393 | return [validLen, placeHoldersLen]
|
394 | }
|
395 |
|
396 | // base64 is 4/3 + up to two characters of the original data
|
397 | function byteLength (b64) {
|
398 | var lens = getLens(b64)
|
399 | var validLen = lens[0]
|
400 | var placeHoldersLen = lens[1]
|
401 | return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
402 | }
|
403 |
|
404 | function _byteLength (b64, validLen, placeHoldersLen) {
|
405 | return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
406 | }
|
407 |
|
408 | function toByteArray (b64) {
|
409 | var tmp
|
410 | var lens = getLens(b64)
|
411 | var validLen = lens[0]
|
412 | var placeHoldersLen = lens[1]
|
413 |
|
414 | var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
|
415 |
|
416 | var curByte = 0
|
417 |
|
418 | // if there are placeholders, only get up to the last complete 4 chars
|
419 | var len = placeHoldersLen > 0
|
420 | ? validLen - 4
|
421 | : validLen
|
422 |
|
423 | var i
|
424 | for (i = 0; i < len; i += 4) {
|
425 | tmp =
|
426 | (revLookup[b64.charCodeAt(i)] << 18) |
|
427 | (revLookup[b64.charCodeAt(i + 1)] << 12) |
|
428 | (revLookup[b64.charCodeAt(i + 2)] << 6) |
|
429 | revLookup[b64.charCodeAt(i + 3)]
|
430 | arr[curByte++] = (tmp >> 16) & 0xFF
|
431 | arr[curByte++] = (tmp >> 8) & 0xFF
|
432 | arr[curByte++] = tmp & 0xFF
|
433 | }
|
434 |
|
435 | if (placeHoldersLen === 2) {
|
436 | tmp =
|
437 | (revLookup[b64.charCodeAt(i)] << 2) |
|
438 | (revLookup[b64.charCodeAt(i + 1)] >> 4)
|
439 | arr[curByte++] = tmp & 0xFF
|
440 | }
|
441 |
|
442 | if (placeHoldersLen === 1) {
|
443 | tmp =
|
444 | (revLookup[b64.charCodeAt(i)] << 10) |
|
445 | (revLookup[b64.charCodeAt(i + 1)] << 4) |
|
446 | (revLookup[b64.charCodeAt(i + 2)] >> 2)
|
447 | arr[curByte++] = (tmp >> 8) & 0xFF
|
448 | arr[curByte++] = tmp & 0xFF
|
449 | }
|
450 |
|
451 | return arr
|
452 | }
|
453 |
|
454 | function tripletToBase64 (num) {
|
455 | return lookup[num >> 18 & 0x3F] +
|
456 | lookup[num >> 12 & 0x3F] +
|
457 | lookup[num >> 6 & 0x3F] +
|
458 | lookup[num & 0x3F]
|
459 | }
|
460 |
|
461 | function encodeChunk (uint8, start, end) {
|
462 | var tmp
|
463 | var output = []
|
464 | for (var i = start; i < end; i += 3) {
|
465 | tmp =
|
466 | ((uint8[i] << 16) & 0xFF0000) +
|
467 | ((uint8[i + 1] << 8) & 0xFF00) +
|
468 | (uint8[i + 2] & 0xFF)
|
469 | output.push(tripletToBase64(tmp))
|
470 | }
|
471 | return output.join('')
|
472 | }
|
473 |
|
474 | function fromByteArray (uint8) {
|
475 | var tmp
|
476 | var len = uint8.length
|
477 | var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
|
478 | var parts = []
|
479 | var maxChunkLength = 16383 // must be multiple of 3
|
480 |
|
481 | // go through the array every three bytes, we'll deal with trailing stuff later
|
482 | for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
483 | parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
|
484 | }
|
485 |
|
486 | // pad the end with zeros, but make sure to not forget the extra bytes
|
487 | if (extraBytes === 1) {
|
488 | tmp = uint8[len - 1]
|
489 | parts.push(
|
490 | lookup[tmp >> 2] +
|
491 | lookup[(tmp << 4) & 0x3F] +
|
492 | '=='
|
493 | )
|
494 | } else if (extraBytes === 2) {
|
495 | tmp = (uint8[len - 2] << 8) + uint8[len - 1]
|
496 | parts.push(
|
497 | lookup[tmp >> 10] +
|
498 | lookup[(tmp >> 4) & 0x3F] +
|
499 | lookup[(tmp << 2) & 0x3F] +
|
500 | '='
|
501 | )
|
502 | }
|
503 |
|
504 | return parts.join('')
|
505 | }
|
506 |
|
507 | },{}],4:[function(require,module,exports){
|
508 |
|
509 | },{}],5:[function(require,module,exports){
|
510 | (function (Buffer){(function (){
|
511 | /*!
|
512 | * The buffer module from node.js, for the browser.
|
513 | *
|
514 | * @author Feross Aboukhadijeh <https://feross.org>
|
515 | * @license MIT
|
516 | */
|
517 | /* eslint-disable no-proto */
|
518 |
|
519 | 'use strict'
|
520 |
|
521 | var base64 = require('base64-js')
|
522 | var ieee754 = require('ieee754')
|
523 |
|
524 | exports.Buffer = Buffer
|
525 | exports.SlowBuffer = SlowBuffer
|
526 | exports.INSPECT_MAX_BYTES = 50
|
527 |
|
528 | var K_MAX_LENGTH = 0x7fffffff
|
529 | exports.kMaxLength = K_MAX_LENGTH
|
530 |
|
531 | /**
|
532 | * If `Buffer.TYPED_ARRAY_SUPPORT`:
|
533 | * === true Use Uint8Array implementation (fastest)
|
534 | * === false Print warning and recommend using `buffer` v4.x which has an Object
|
535 | * implementation (most compatible, even IE6)
|
536 | *
|
537 | * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
|
538 | * Opera 11.6+, iOS 4.2+.
|
539 | *
|
540 | * We report that the browser does not support typed arrays if the are not subclassable
|
541 | * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
|
542 | * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
|
543 | * for __proto__ and has a buggy typed array implementation.
|
544 | */
|
545 | Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
|
546 |
|
547 | if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
|
548 | typeof console.error === 'function') {
|
549 | console.error(
|
550 | 'This browser lacks typed array (Uint8Array) support which is required by ' +
|
551 | '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
|
552 | )
|
553 | }
|
554 |
|
555 | function typedArraySupport () {
|
556 | // Can typed array instances can be augmented?
|
557 | try {
|
558 | var arr = new Uint8Array(1)
|
559 | arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } }
|
560 | return arr.foo() === 42
|
561 | } catch (e) {
|
562 | return false
|
563 | }
|
564 | }
|
565 |
|
566 | Object.defineProperty(Buffer.prototype, 'parent', {
|
567 | enumerable: true,
|
568 | get: function () {
|
569 | if (!Buffer.isBuffer(this)) return undefined
|
570 | return this.buffer
|
571 | }
|
572 | })
|
573 |
|
574 | Object.defineProperty(Buffer.prototype, 'offset', {
|
575 | enumerable: true,
|
576 | get: function () {
|
577 | if (!Buffer.isBuffer(this)) return undefined
|
578 | return this.byteOffset
|
579 | }
|
580 | })
|
581 |
|
582 | function createBuffer (length) {
|
583 | if (length > K_MAX_LENGTH) {
|
584 | throw new RangeError('The value "' + length + '" is invalid for option "size"')
|
585 | }
|
586 | // Return an augmented `Uint8Array` instance
|
587 | var buf = new Uint8Array(length)
|
588 | buf.__proto__ = Buffer.prototype
|
589 | return buf
|
590 | }
|
591 |
|
592 | /**
|
593 | * The Buffer constructor returns instances of `Uint8Array` that have their
|
594 | * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
595 | * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
596 | * and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
597 | * returns a single octet.
|
598 | *
|
599 | * The `Uint8Array` prototype remains unmodified.
|
600 | */
|
601 |
|
602 | function Buffer (arg, encodingOrOffset, length) {
|
603 | // Common case.
|
604 | if (typeof arg === 'number') {
|
605 | if (typeof encodingOrOffset === 'string') {
|
606 | throw new TypeError(
|
607 | 'The "string" argument must be of type string. Received type number'
|
608 | )
|
609 | }
|
610 | return allocUnsafe(arg)
|
611 | }
|
612 | return from(arg, encodingOrOffset, length)
|
613 | }
|
614 |
|
615 | // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
|
616 | if (typeof Symbol !== 'undefined' && Symbol.species != null &&
|
617 | Buffer[Symbol.species] === Buffer) {
|
618 | Object.defineProperty(Buffer, Symbol.species, {
|
619 | value: null,
|
620 | configurable: true,
|
621 | enumerable: false,
|
622 | writable: false
|
623 | })
|
624 | }
|
625 |
|
626 | Buffer.poolSize = 8192 // not used by this implementation
|
627 |
|
628 | function from (value, encodingOrOffset, length) {
|
629 | if (typeof value === 'string') {
|
630 | return fromString(value, encodingOrOffset)
|
631 | }
|
632 |
|
633 | if (ArrayBuffer.isView(value)) {
|
634 | return fromArrayLike(value)
|
635 | }
|
636 |
|
637 | if (value == null) {
|
638 | throw TypeError(
|
639 | 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
640 | 'or Array-like Object. Received type ' + (typeof value)
|
641 | )
|
642 | }
|
643 |
|
644 | if (isInstance(value, ArrayBuffer) ||
|
645 | (value && isInstance(value.buffer, ArrayBuffer))) {
|
646 | return fromArrayBuffer(value, encodingOrOffset, length)
|
647 | }
|
648 |
|
649 | if (typeof value === 'number') {
|
650 | throw new TypeError(
|
651 | 'The "value" argument must not be of type number. Received type number'
|
652 | )
|
653 | }
|
654 |
|
655 | var valueOf = value.valueOf && value.valueOf()
|
656 | if (valueOf != null && valueOf !== value) {
|
657 | return Buffer.from(valueOf, encodingOrOffset, length)
|
658 | }
|
659 |
|
660 | var b = fromObject(value)
|
661 | if (b) return b
|
662 |
|
663 | if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
|
664 | typeof value[Symbol.toPrimitive] === 'function') {
|
665 | return Buffer.from(
|
666 | value[Symbol.toPrimitive]('string'), encodingOrOffset, length
|
667 | )
|
668 | }
|
669 |
|
670 | throw new TypeError(
|
671 | 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
672 | 'or Array-like Object. Received type ' + (typeof value)
|
673 | )
|
674 | }
|
675 |
|
676 | /**
|
677 | * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
|
678 | * if value is a number.
|
679 | * Buffer.from(str[, encoding])
|
680 | * Buffer.from(array)
|
681 | * Buffer.from(buffer)
|
682 | * Buffer.from(arrayBuffer[, byteOffset[, length]])
|
683 | **/
|
684 | Buffer.from = function (value, encodingOrOffset, length) {
|
685 | return from(value, encodingOrOffset, length)
|
686 | }
|
687 |
|
688 | // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
|
689 | // https://github.com/feross/buffer/pull/148
|
690 | Buffer.prototype.__proto__ = Uint8Array.prototype
|
691 | Buffer.__proto__ = Uint8Array
|
692 |
|
693 | function assertSize (size) {
|
694 | if (typeof size !== 'number') {
|
695 | throw new TypeError('"size" argument must be of type number')
|
696 | } else if (size < 0) {
|
697 | throw new RangeError('The value "' + size + '" is invalid for option "size"')
|
698 | }
|
699 | }
|
700 |
|
701 | function alloc (size, fill, encoding) {
|
702 | assertSize(size)
|
703 | if (size <= 0) {
|
704 | return createBuffer(size)
|
705 | }
|
706 | if (fill !== undefined) {
|
707 | // Only pay attention to encoding if it's a string. This
|
708 | // prevents accidentally sending in a number that would
|
709 | // be interpretted as a start offset.
|
710 | return typeof encoding === 'string'
|
711 | ? createBuffer(size).fill(fill, encoding)
|
712 | : createBuffer(size).fill(fill)
|
713 | }
|
714 | return createBuffer(size)
|
715 | }
|
716 |
|
717 | /**
|
718 | * Creates a new filled Buffer instance.
|
719 | * alloc(size[, fill[, encoding]])
|
720 | **/
|
721 | Buffer.alloc = function (size, fill, encoding) {
|
722 | return alloc(size, fill, encoding)
|
723 | }
|
724 |
|
725 | function allocUnsafe (size) {
|
726 | assertSize(size)
|
727 | return createBuffer(size < 0 ? 0 : checked(size) | 0)
|
728 | }
|
729 |
|
730 | /**
|
731 | * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
|
732 | * */
|
733 | Buffer.allocUnsafe = function (size) {
|
734 | return allocUnsafe(size)
|
735 | }
|
736 | /**
|
737 | * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
738 | */
|
739 | Buffer.allocUnsafeSlow = function (size) {
|
740 | return allocUnsafe(size)
|
741 | }
|
742 |
|
743 | function fromString (string, encoding) {
|
744 | if (typeof encoding !== 'string' || encoding === '') {
|
745 | encoding = 'utf8'
|
746 | }
|
747 |
|
748 | if (!Buffer.isEncoding(encoding)) {
|
749 | throw new TypeError('Unknown encoding: ' + encoding)
|
750 | }
|
751 |
|
752 | var length = byteLength(string, encoding) | 0
|
753 | var buf = createBuffer(length)
|
754 |
|
755 | var actual = buf.write(string, encoding)
|
756 |
|
757 | if (actual !== length) {
|
758 | // Writing a hex string, for example, that contains invalid characters will
|
759 | // cause everything after the first invalid character to be ignored. (e.g.
|
760 | // 'abxxcd' will be treated as 'ab')
|
761 | buf = buf.slice(0, actual)
|
762 | }
|
763 |
|
764 | return buf
|
765 | }
|
766 |
|
767 | function fromArrayLike (array) {
|
768 | var length = array.length < 0 ? 0 : checked(array.length) | 0
|
769 | var buf = createBuffer(length)
|
770 | for (var i = 0; i < length; i += 1) {
|
771 | buf[i] = array[i] & 255
|
772 | }
|
773 | return buf
|
774 | }
|
775 |
|
776 | function fromArrayBuffer (array, byteOffset, length) {
|
777 | if (byteOffset < 0 || array.byteLength < byteOffset) {
|
778 | throw new RangeError('"offset" is outside of buffer bounds')
|
779 | }
|
780 |
|
781 | if (array.byteLength < byteOffset + (length || 0)) {
|
782 | throw new RangeError('"length" is outside of buffer bounds')
|
783 | }
|
784 |
|
785 | var buf
|
786 | if (byteOffset === undefined && length === undefined) {
|
787 | buf = new Uint8Array(array)
|
788 | } else if (length === undefined) {
|
789 | buf = new Uint8Array(array, byteOffset)
|
790 | } else {
|
791 | buf = new Uint8Array(array, byteOffset, length)
|
792 | }
|
793 |
|
794 | // Return an augmented `Uint8Array` instance
|
795 | buf.__proto__ = Buffer.prototype
|
796 | return buf
|
797 | }
|
798 |
|
799 | function fromObject (obj) {
|
800 | if (Buffer.isBuffer(obj)) {
|
801 | var len = checked(obj.length) | 0
|
802 | var buf = createBuffer(len)
|
803 |
|
804 | if (buf.length === 0) {
|
805 | return buf
|
806 | }
|
807 |
|
808 | obj.copy(buf, 0, 0, len)
|
809 | return buf
|
810 | }
|
811 |
|
812 | if (obj.length !== undefined) {
|
813 | if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
|
814 | return createBuffer(0)
|
815 | }
|
816 | return fromArrayLike(obj)
|
817 | }
|
818 |
|
819 | if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
|
820 | return fromArrayLike(obj.data)
|
821 | }
|
822 | }
|
823 |
|
824 | function checked (length) {
|
825 | // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
|
826 | // length is NaN (which is otherwise coerced to zero.)
|
827 | if (length >= K_MAX_LENGTH) {
|
828 | throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
829 | 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
|
830 | }
|
831 | return length | 0
|
832 | }
|
833 |
|
834 | function SlowBuffer (length) {
|
835 | if (+length != length) { // eslint-disable-line eqeqeq
|
836 | length = 0
|
837 | }
|
838 | return Buffer.alloc(+length)
|
839 | }
|
840 |
|
841 | Buffer.isBuffer = function isBuffer (b) {
|
842 | return b != null && b._isBuffer === true &&
|
843 | b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
|
844 | }
|
845 |
|
846 | Buffer.compare = function compare (a, b) {
|
847 | if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
|
848 | if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
|
849 | if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
|
850 | throw new TypeError(
|
851 | 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
|
852 | )
|
853 | }
|
854 |
|
855 | if (a === b) return 0
|
856 |
|
857 | var x = a.length
|
858 | var y = b.length
|
859 |
|
860 | for (var i = 0, len = Math.min(x, y); i < len; ++i) {
|
861 | if (a[i] !== b[i]) {
|
862 | x = a[i]
|
863 | y = b[i]
|
864 | break
|
865 | }
|
866 | }
|
867 |
|
868 | if (x < y) return -1
|
869 | if (y < x) return 1
|
870 | return 0
|
871 | }
|
872 |
|
873 | Buffer.isEncoding = function isEncoding (encoding) {
|
874 | switch (String(encoding).toLowerCase()) {
|
875 | case 'hex':
|
876 | case 'utf8':
|
877 | case 'utf-8':
|
878 | case 'ascii':
|
879 | case 'latin1':
|
880 | case 'binary':
|
881 | case 'base64':
|
882 | case 'ucs2':
|
883 | case 'ucs-2':
|
884 | case 'utf16le':
|
885 | case 'utf-16le':
|
886 | return true
|
887 | default:
|
888 | return false
|
889 | }
|
890 | }
|
891 |
|
892 | Buffer.concat = function concat (list, length) {
|
893 | if (!Array.isArray(list)) {
|
894 | throw new TypeError('"list" argument must be an Array of Buffers')
|
895 | }
|
896 |
|
897 | if (list.length === 0) {
|
898 | return Buffer.alloc(0)
|
899 | }
|
900 |
|
901 | var i
|
902 | if (length === undefined) {
|
903 | length = 0
|
904 | for (i = 0; i < list.length; ++i) {
|
905 | length += list[i].length
|
906 | }
|
907 | }
|
908 |
|
909 | var buffer = Buffer.allocUnsafe(length)
|
910 | var pos = 0
|
911 | for (i = 0; i < list.length; ++i) {
|
912 | var buf = list[i]
|
913 | if (isInstance(buf, Uint8Array)) {
|
914 | buf = Buffer.from(buf)
|
915 | }
|
916 | if (!Buffer.isBuffer(buf)) {
|
917 | throw new TypeError('"list" argument must be an Array of Buffers')
|
918 | }
|
919 | buf.copy(buffer, pos)
|
920 | pos += buf.length
|
921 | }
|
922 | return buffer
|
923 | }
|
924 |
|
925 | function byteLength (string, encoding) {
|
926 | if (Buffer.isBuffer(string)) {
|
927 | return string.length
|
928 | }
|
929 | if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
|
930 | return string.byteLength
|
931 | }
|
932 | if (typeof string !== 'string') {
|
933 | throw new TypeError(
|
934 | 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
|
935 | 'Received type ' + typeof string
|
936 | )
|
937 | }
|
938 |
|
939 | var len = string.length
|
940 | var mustMatch = (arguments.length > 2 && arguments[2] === true)
|
941 | if (!mustMatch && len === 0) return 0
|
942 |
|
943 | // Use a for loop to avoid recursion
|
944 | var loweredCase = false
|
945 | for (;;) {
|
946 | switch (encoding) {
|
947 | case 'ascii':
|
948 | case 'latin1':
|
949 | case 'binary':
|
950 | return len
|
951 | case 'utf8':
|
952 | case 'utf-8':
|
953 | return utf8ToBytes(string).length
|
954 | case 'ucs2':
|
955 | case 'ucs-2':
|
956 | case 'utf16le':
|
957 | case 'utf-16le':
|
958 | return len * 2
|
959 | case 'hex':
|
960 | return len >>> 1
|
961 | case 'base64':
|
962 | return base64ToBytes(string).length
|
963 | default:
|
964 | if (loweredCase) {
|
965 | return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
|
966 | }
|
967 | encoding = ('' + encoding).toLowerCase()
|
968 | loweredCase = true
|
969 | }
|
970 | }
|
971 | }
|
972 | Buffer.byteLength = byteLength
|
973 |
|
974 | function slowToString (encoding, start, end) {
|
975 | var loweredCase = false
|
976 |
|
977 | // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
|
978 | // property of a typed array.
|
979 |
|
980 | // This behaves neither like String nor Uint8Array in that we set start/end
|
981 | // to their upper/lower bounds if the value passed is out of range.
|
982 | // undefined is handled specially as per ECMA-262 6th Edition,
|
983 | // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
|
984 | if (start === undefined || start < 0) {
|
985 | start = 0
|
986 | }
|
987 | // Return early if start > this.length. Done here to prevent potential uint32
|
988 | // coercion fail below.
|
989 | if (start > this.length) {
|
990 | return ''
|
991 | }
|
992 |
|
993 | if (end === undefined || end > this.length) {
|
994 | end = this.length
|
995 | }
|
996 |
|
997 | if (end <= 0) {
|
998 | return ''
|
999 | }
|
1000 |
|
1001 | // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
|
1002 | end >>>= 0
|
1003 | start >>>= 0
|
1004 |
|
1005 | if (end <= start) {
|
1006 | return ''
|
1007 | }
|
1008 |
|
1009 | if (!encoding) encoding = 'utf8'
|
1010 |
|
1011 | while (true) {
|
1012 | switch (encoding) {
|
1013 | case 'hex':
|
1014 | return hexSlice(this, start, end)
|
1015 |
|
1016 | case 'utf8':
|
1017 | case 'utf-8':
|
1018 | return utf8Slice(this, start, end)
|
1019 |
|
1020 | case 'ascii':
|
1021 | return asciiSlice(this, start, end)
|
1022 |
|
1023 | case 'latin1':
|
1024 | case 'binary':
|
1025 | return latin1Slice(this, start, end)
|
1026 |
|
1027 | case 'base64':
|
1028 | return base64Slice(this, start, end)
|
1029 |
|
1030 | case 'ucs2':
|
1031 | case 'ucs-2':
|
1032 | case 'utf16le':
|
1033 | case 'utf-16le':
|
1034 | return utf16leSlice(this, start, end)
|
1035 |
|
1036 | default:
|
1037 | if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
1038 | encoding = (encoding + '').toLowerCase()
|
1039 | loweredCase = true
|
1040 | }
|
1041 | }
|
1042 | }
|
1043 |
|
1044 | // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
|
1045 | // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
|
1046 | // reliably in a browserify context because there could be multiple different
|
1047 | // copies of the 'buffer' package in use. This method works even for Buffer
|
1048 | // instances that were created from another copy of the `buffer` package.
|
1049 | // See: https://github.com/feross/buffer/issues/154
|
1050 | Buffer.prototype._isBuffer = true
|
1051 |
|
1052 | function swap (b, n, m) {
|
1053 | var i = b[n]
|
1054 | b[n] = b[m]
|
1055 | b[m] = i
|
1056 | }
|
1057 |
|
1058 | Buffer.prototype.swap16 = function swap16 () {
|
1059 | var len = this.length
|
1060 | if (len % 2 !== 0) {
|
1061 | throw new RangeError('Buffer size must be a multiple of 16-bits')
|
1062 | }
|
1063 | for (var i = 0; i < len; i += 2) {
|
1064 | swap(this, i, i + 1)
|
1065 | }
|
1066 | return this
|
1067 | }
|
1068 |
|
1069 | Buffer.prototype.swap32 = function swap32 () {
|
1070 | var len = this.length
|
1071 | if (len % 4 !== 0) {
|
1072 | throw new RangeError('Buffer size must be a multiple of 32-bits')
|
1073 | }
|
1074 | for (var i = 0; i < len; i += 4) {
|
1075 | swap(this, i, i + 3)
|
1076 | swap(this, i + 1, i + 2)
|
1077 | }
|
1078 | return this
|
1079 | }
|
1080 |
|
1081 | Buffer.prototype.swap64 = function swap64 () {
|
1082 | var len = this.length
|
1083 | if (len % 8 !== 0) {
|
1084 | throw new RangeError('Buffer size must be a multiple of 64-bits')
|
1085 | }
|
1086 | for (var i = 0; i < len; i += 8) {
|
1087 | swap(this, i, i + 7)
|
1088 | swap(this, i + 1, i + 6)
|
1089 | swap(this, i + 2, i + 5)
|
1090 | swap(this, i + 3, i + 4)
|
1091 | }
|
1092 | return this
|
1093 | }
|
1094 |
|
1095 | Buffer.prototype.toString = function toString () {
|
1096 | var length = this.length
|
1097 | if (length === 0) return ''
|
1098 | if (arguments.length === 0) return utf8Slice(this, 0, length)
|
1099 | return slowToString.apply(this, arguments)
|
1100 | }
|
1101 |
|
1102 | Buffer.prototype.toLocaleString = Buffer.prototype.toString
|
1103 |
|
1104 | Buffer.prototype.equals = function equals (b) {
|
1105 | if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
1106 | if (this === b) return true
|
1107 | return Buffer.compare(this, b) === 0
|
1108 | }
|
1109 |
|
1110 | Buffer.prototype.inspect = function inspect () {
|
1111 | var str = ''
|
1112 | var max = exports.INSPECT_MAX_BYTES
|
1113 | str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
|
1114 | if (this.length > max) str += ' ... '
|
1115 | return '<Buffer ' + str + '>'
|
1116 | }
|
1117 |
|
1118 | Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
|
1119 | if (isInstance(target, Uint8Array)) {
|
1120 | target = Buffer.from(target, target.offset, target.byteLength)
|
1121 | }
|
1122 | if (!Buffer.isBuffer(target)) {
|
1123 | throw new TypeError(
|
1124 | 'The "target" argument must be one of type Buffer or Uint8Array. ' +
|
1125 | 'Received type ' + (typeof target)
|
1126 | )
|
1127 | }
|
1128 |
|
1129 | if (start === undefined) {
|
1130 | start = 0
|
1131 | }
|
1132 | if (end === undefined) {
|
1133 | end = target ? target.length : 0
|
1134 | }
|
1135 | if (thisStart === undefined) {
|
1136 | thisStart = 0
|
1137 | }
|
1138 | if (thisEnd === undefined) {
|
1139 | thisEnd = this.length
|
1140 | }
|
1141 |
|
1142 | if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
1143 | throw new RangeError('out of range index')
|
1144 | }
|
1145 |
|
1146 | if (thisStart >= thisEnd && start >= end) {
|
1147 | return 0
|
1148 | }
|
1149 | if (thisStart >= thisEnd) {
|
1150 | return -1
|
1151 | }
|
1152 | if (start >= end) {
|
1153 | return 1
|
1154 | }
|
1155 |
|
1156 | start >>>= 0
|
1157 | end >>>= 0
|
1158 | thisStart >>>= 0
|
1159 | thisEnd >>>= 0
|
1160 |
|
1161 | if (this === target) return 0
|
1162 |
|
1163 | var x = thisEnd - thisStart
|
1164 | var y = end - start
|
1165 | var len = Math.min(x, y)
|
1166 |
|
1167 | var thisCopy = this.slice(thisStart, thisEnd)
|
1168 | var targetCopy = target.slice(start, end)
|
1169 |
|
1170 | for (var i = 0; i < len; ++i) {
|
1171 | if (thisCopy[i] !== targetCopy[i]) {
|
1172 | x = thisCopy[i]
|
1173 | y = targetCopy[i]
|
1174 | break
|
1175 | }
|
1176 | }
|
1177 |
|
1178 | if (x < y) return -1
|
1179 | if (y < x) return 1
|
1180 | return 0
|
1181 | }
|
1182 |
|
1183 | // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
|
1184 | // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
|
1185 | //
|
1186 | // Arguments:
|
1187 | // - buffer - a Buffer to search
|
1188 | // - val - a string, Buffer, or number
|
1189 | // - byteOffset - an index into `buffer`; will be clamped to an int32
|
1190 | // - encoding - an optional encoding, relevant is val is a string
|
1191 | // - dir - true for indexOf, false for lastIndexOf
|
1192 | function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
1193 | // Empty buffer means no match
|
1194 | if (buffer.length === 0) return -1
|
1195 |
|
1196 | // Normalize byteOffset
|
1197 | if (typeof byteOffset === 'string') {
|
1198 | encoding = byteOffset
|
1199 | byteOffset = 0
|
1200 | } else if (byteOffset > 0x7fffffff) {
|
1201 | byteOffset = 0x7fffffff
|
1202 | } else if (byteOffset < -0x80000000) {
|
1203 | byteOffset = -0x80000000
|
1204 | }
|
1205 | byteOffset = +byteOffset // Coerce to Number.
|
1206 | if (numberIsNaN(byteOffset)) {
|
1207 | // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
|
1208 | byteOffset = dir ? 0 : (buffer.length - 1)
|
1209 | }
|
1210 |
|
1211 | // Normalize byteOffset: negative offsets start from the end of the buffer
|
1212 | if (byteOffset < 0) byteOffset = buffer.length + byteOffset
|
1213 | if (byteOffset >= buffer.length) {
|
1214 | if (dir) return -1
|
1215 | else byteOffset = buffer.length - 1
|
1216 | } else if (byteOffset < 0) {
|
1217 | if (dir) byteOffset = 0
|
1218 | else return -1
|
1219 | }
|
1220 |
|
1221 | // Normalize val
|
1222 | if (typeof val === 'string') {
|
1223 | val = Buffer.from(val, encoding)
|
1224 | }
|
1225 |
|
1226 | // Finally, search either indexOf (if dir is true) or lastIndexOf
|
1227 | if (Buffer.isBuffer(val)) {
|
1228 | // Special case: looking for empty string/buffer always fails
|
1229 | if (val.length === 0) {
|
1230 | return -1
|
1231 | }
|
1232 | return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
1233 | } else if (typeof val === 'number') {
|
1234 | val = val & 0xFF // Search for a byte value [0-255]
|
1235 | if (typeof Uint8Array.prototype.indexOf === 'function') {
|
1236 | if (dir) {
|
1237 | return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
1238 | } else {
|
1239 | return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
1240 | }
|
1241 | }
|
1242 | return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
|
1243 | }
|
1244 |
|
1245 | throw new TypeError('val must be string, number or Buffer')
|
1246 | }
|
1247 |
|
1248 | function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
1249 | var indexSize = 1
|
1250 | var arrLength = arr.length
|
1251 | var valLength = val.length
|
1252 |
|
1253 | if (encoding !== undefined) {
|
1254 | encoding = String(encoding).toLowerCase()
|
1255 | if (encoding === 'ucs2' || encoding === 'ucs-2' ||
|
1256 | encoding === 'utf16le' || encoding === 'utf-16le') {
|
1257 | if (arr.length < 2 || val.length < 2) {
|
1258 | return -1
|
1259 | }
|
1260 | indexSize = 2
|
1261 | arrLength /= 2
|
1262 | valLength /= 2
|
1263 | byteOffset /= 2
|
1264 | }
|
1265 | }
|
1266 |
|
1267 | function read (buf, i) {
|
1268 | if (indexSize === 1) {
|
1269 | return buf[i]
|
1270 | } else {
|
1271 | return buf.readUInt16BE(i * indexSize)
|
1272 | }
|
1273 | }
|
1274 |
|
1275 | var i
|
1276 | if (dir) {
|
1277 | var foundIndex = -1
|
1278 | for (i = byteOffset; i < arrLength; i++) {
|
1279 | if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
1280 | if (foundIndex === -1) foundIndex = i
|
1281 | if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
1282 | } else {
|
1283 | if (foundIndex !== -1) i -= i - foundIndex
|
1284 | foundIndex = -1
|
1285 | }
|
1286 | }
|
1287 | } else {
|
1288 | if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
|
1289 | for (i = byteOffset; i >= 0; i--) {
|
1290 | var found = true
|
1291 | for (var j = 0; j < valLength; j++) {
|
1292 | if (read(arr, i + j) !== read(val, j)) {
|
1293 | found = false
|
1294 | break
|
1295 | }
|
1296 | }
|
1297 | if (found) return i
|
1298 | }
|
1299 | }
|
1300 |
|
1301 | return -1
|
1302 | }
|
1303 |
|
1304 | Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
1305 | return this.indexOf(val, byteOffset, encoding) !== -1
|
1306 | }
|
1307 |
|
1308 | Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
1309 | return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
1310 | }
|
1311 |
|
1312 | Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
|
1313 | return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
|
1314 | }
|
1315 |
|
1316 | function hexWrite (buf, string, offset, length) {
|
1317 | offset = Number(offset) || 0
|
1318 | var remaining = buf.length - offset
|
1319 | if (!length) {
|
1320 | length = remaining
|
1321 | } else {
|
1322 | length = Number(length)
|
1323 | if (length > remaining) {
|
1324 | length = remaining
|
1325 | }
|
1326 | }
|
1327 |
|
1328 | var strLen = string.length
|
1329 |
|
1330 | if (length > strLen / 2) {
|
1331 | length = strLen / 2
|
1332 | }
|
1333 | for (var i = 0; i < length; ++i) {
|
1334 | var parsed = parseInt(string.substr(i * 2, 2), 16)
|
1335 | if (numberIsNaN(parsed)) return i
|
1336 | buf[offset + i] = parsed
|
1337 | }
|
1338 | return i
|
1339 | }
|
1340 |
|
1341 | function utf8Write (buf, string, offset, length) {
|
1342 | return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
|
1343 | }
|
1344 |
|
1345 | function asciiWrite (buf, string, offset, length) {
|
1346 | return blitBuffer(asciiToBytes(string), buf, offset, length)
|
1347 | }
|
1348 |
|
1349 | function latin1Write (buf, string, offset, length) {
|
1350 | return asciiWrite(buf, string, offset, length)
|
1351 | }
|
1352 |
|
1353 | function base64Write (buf, string, offset, length) {
|
1354 | return blitBuffer(base64ToBytes(string), buf, offset, length)
|
1355 | }
|
1356 |
|
1357 | function ucs2Write (buf, string, offset, length) {
|
1358 | return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
|
1359 | }
|
1360 |
|
1361 | Buffer.prototype.write = function write (string, offset, length, encoding) {
|
1362 | // Buffer#write(string)
|
1363 | if (offset === undefined) {
|
1364 | encoding = 'utf8'
|
1365 | length = this.length
|
1366 | offset = 0
|
1367 | // Buffer#write(string, encoding)
|
1368 | } else if (length === undefined && typeof offset === 'string') {
|
1369 | encoding = offset
|
1370 | length = this.length
|
1371 | offset = 0
|
1372 | // Buffer#write(string, offset[, length][, encoding])
|
1373 | } else if (isFinite(offset)) {
|
1374 | offset = offset >>> 0
|
1375 | if (isFinite(length)) {
|
1376 | length = length >>> 0
|
1377 | if (encoding === undefined) encoding = 'utf8'
|
1378 | } else {
|
1379 | encoding = length
|
1380 | length = undefined
|
1381 | }
|
1382 | } else {
|
1383 | throw new Error(
|
1384 | 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
1385 | )
|
1386 | }
|
1387 |
|
1388 | var remaining = this.length - offset
|
1389 | if (length === undefined || length > remaining) length = remaining
|
1390 |
|
1391 | if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
1392 | throw new RangeError('Attempt to write outside buffer bounds')
|
1393 | }
|
1394 |
|
1395 | if (!encoding) encoding = 'utf8'
|
1396 |
|
1397 | var loweredCase = false
|
1398 | for (;;) {
|
1399 | switch (encoding) {
|
1400 | case 'hex':
|
1401 | return hexWrite(this, string, offset, length)
|
1402 |
|
1403 | case 'utf8':
|
1404 | case 'utf-8':
|
1405 | return utf8Write(this, string, offset, length)
|
1406 |
|
1407 | case 'ascii':
|
1408 | return asciiWrite(this, string, offset, length)
|
1409 |
|
1410 | case 'latin1':
|
1411 | case 'binary':
|
1412 | return latin1Write(this, string, offset, length)
|
1413 |
|
1414 | case 'base64':
|
1415 | // Warning: maxLength not taken into account in base64Write
|
1416 | return base64Write(this, string, offset, length)
|
1417 |
|
1418 | case 'ucs2':
|
1419 | case 'ucs-2':
|
1420 | case 'utf16le':
|
1421 | case 'utf-16le':
|
1422 | return ucs2Write(this, string, offset, length)
|
1423 |
|
1424 | default:
|
1425 | if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
1426 | encoding = ('' + encoding).toLowerCase()
|
1427 | loweredCase = true
|
1428 | }
|
1429 | }
|
1430 | }
|
1431 |
|
1432 | Buffer.prototype.toJSON = function toJSON () {
|
1433 | return {
|
1434 | type: 'Buffer',
|
1435 | data: Array.prototype.slice.call(this._arr || this, 0)
|
1436 | }
|
1437 | }
|
1438 |
|
1439 | function base64Slice (buf, start, end) {
|
1440 | if (start === 0 && end === buf.length) {
|
1441 | return base64.fromByteArray(buf)
|
1442 | } else {
|
1443 | return base64.fromByteArray(buf.slice(start, end))
|
1444 | }
|
1445 | }
|
1446 |
|
1447 | function utf8Slice (buf, start, end) {
|
1448 | end = Math.min(buf.length, end)
|
1449 | var res = []
|
1450 |
|
1451 | var i = start
|
1452 | while (i < end) {
|
1453 | var firstByte = buf[i]
|
1454 | var codePoint = null
|
1455 | var bytesPerSequence = (firstByte > 0xEF) ? 4
|
1456 | : (firstByte > 0xDF) ? 3
|
1457 | : (firstByte > 0xBF) ? 2
|
1458 | : 1
|
1459 |
|
1460 | if (i + bytesPerSequence <= end) {
|
1461 | var secondByte, thirdByte, fourthByte, tempCodePoint
|
1462 |
|
1463 | switch (bytesPerSequence) {
|
1464 | case 1:
|
1465 | if (firstByte < 0x80) {
|
1466 | codePoint = firstByte
|
1467 | }
|
1468 | break
|
1469 | case 2:
|
1470 | secondByte = buf[i + 1]
|
1471 | if ((secondByte & 0xC0) === 0x80) {
|
1472 | tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
|
1473 | if (tempCodePoint > 0x7F) {
|
1474 | codePoint = tempCodePoint
|
1475 | }
|
1476 | }
|
1477 | break
|
1478 | case 3:
|
1479 | secondByte = buf[i + 1]
|
1480 | thirdByte = buf[i + 2]
|
1481 | if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
|
1482 | tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
|
1483 | if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
1484 | codePoint = tempCodePoint
|
1485 | }
|
1486 | }
|
1487 | break
|
1488 | case 4:
|
1489 | secondByte = buf[i + 1]
|
1490 | thirdByte = buf[i + 2]
|
1491 | fourthByte = buf[i + 3]
|
1492 | if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
|
1493 | tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
|
1494 | if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
|
1495 | codePoint = tempCodePoint
|
1496 | }
|
1497 | }
|
1498 | }
|
1499 | }
|
1500 |
|
1501 | if (codePoint === null) {
|
1502 | // we did not generate a valid codePoint so insert a
|
1503 | // replacement char (U+FFFD) and advance only 1 byte
|
1504 | codePoint = 0xFFFD
|
1505 | bytesPerSequence = 1
|
1506 | } else if (codePoint > 0xFFFF) {
|
1507 | // encode to utf16 (surrogate pair dance)
|
1508 | codePoint -= 0x10000
|
1509 | res.push(codePoint >>> 10 & 0x3FF | 0xD800)
|
1510 | codePoint = 0xDC00 | codePoint & 0x3FF
|
1511 | }
|
1512 |
|
1513 | res.push(codePoint)
|
1514 | i += bytesPerSequence
|
1515 | }
|
1516 |
|
1517 | return decodeCodePointsArray(res)
|
1518 | }
|
1519 |
|
1520 | // Based on http://stackoverflow.com/a/22747272/680742, the browser with
|
1521 | // the lowest limit is Chrome, with 0x10000 args.
|
1522 | // We go 1 magnitude less, for safety
|
1523 | var MAX_ARGUMENTS_LENGTH = 0x1000
|
1524 |
|
1525 | function decodeCodePointsArray (codePoints) {
|
1526 | var len = codePoints.length
|
1527 | if (len <= MAX_ARGUMENTS_LENGTH) {
|
1528 | return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
|
1529 | }
|
1530 |
|
1531 | // Decode in chunks to avoid "call stack size exceeded".
|
1532 | var res = ''
|
1533 | var i = 0
|
1534 | while (i < len) {
|
1535 | res += String.fromCharCode.apply(
|
1536 | String,
|
1537 | codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
1538 | )
|
1539 | }
|
1540 | return res
|
1541 | }
|
1542 |
|
1543 | function asciiSlice (buf, start, end) {
|
1544 | var ret = ''
|
1545 | end = Math.min(buf.length, end)
|
1546 |
|
1547 | for (var i = start; i < end; ++i) {
|
1548 | ret += String.fromCharCode(buf[i] & 0x7F)
|
1549 | }
|
1550 | return ret
|
1551 | }
|
1552 |
|
1553 | function latin1Slice (buf, start, end) {
|
1554 | var ret = ''
|
1555 | end = Math.min(buf.length, end)
|
1556 |
|
1557 | for (var i = start; i < end; ++i) {
|
1558 | ret += String.fromCharCode(buf[i])
|
1559 | }
|
1560 | return ret
|
1561 | }
|
1562 |
|
1563 | function hexSlice (buf, start, end) {
|
1564 | var len = buf.length
|
1565 |
|
1566 | if (!start || start < 0) start = 0
|
1567 | if (!end || end < 0 || end > len) end = len
|
1568 |
|
1569 | var out = ''
|
1570 | for (var i = start; i < end; ++i) {
|
1571 | out += toHex(buf[i])
|
1572 | }
|
1573 | return out
|
1574 | }
|
1575 |
|
1576 | function utf16leSlice (buf, start, end) {
|
1577 | var bytes = buf.slice(start, end)
|
1578 | var res = ''
|
1579 | for (var i = 0; i < bytes.length; i += 2) {
|
1580 | res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
|
1581 | }
|
1582 | return res
|
1583 | }
|
1584 |
|
1585 | Buffer.prototype.slice = function slice (start, end) {
|
1586 | var len = this.length
|
1587 | start = ~~start
|
1588 | end = end === undefined ? len : ~~end
|
1589 |
|
1590 | if (start < 0) {
|
1591 | start += len
|
1592 | if (start < 0) start = 0
|
1593 | } else if (start > len) {
|
1594 | start = len
|
1595 | }
|
1596 |
|
1597 | if (end < 0) {
|
1598 | end += len
|
1599 | if (end < 0) end = 0
|
1600 | } else if (end > len) {
|
1601 | end = len
|
1602 | }
|
1603 |
|
1604 | if (end < start) end = start
|
1605 |
|
1606 | var newBuf = this.subarray(start, end)
|
1607 | // Return an augmented `Uint8Array` instance
|
1608 | newBuf.__proto__ = Buffer.prototype
|
1609 | return newBuf
|
1610 | }
|
1611 |
|
1612 | /*
|
1613 | * Need to make sure that buffer isn't trying to write out of bounds.
|
1614 | */
|
1615 | function checkOffset (offset, ext, length) {
|
1616 | if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
|
1617 | if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
|
1618 | }
|
1619 |
|
1620 | Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
|
1621 | offset = offset >>> 0
|
1622 | byteLength = byteLength >>> 0
|
1623 | if (!noAssert) checkOffset(offset, byteLength, this.length)
|
1624 |
|
1625 | var val = this[offset]
|
1626 | var mul = 1
|
1627 | var i = 0
|
1628 | while (++i < byteLength && (mul *= 0x100)) {
|
1629 | val += this[offset + i] * mul
|
1630 | }
|
1631 |
|
1632 | return val
|
1633 | }
|
1634 |
|
1635 | Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
|
1636 | offset = offset >>> 0
|
1637 | byteLength = byteLength >>> 0
|
1638 | if (!noAssert) {
|
1639 | checkOffset(offset, byteLength, this.length)
|
1640 | }
|
1641 |
|
1642 | var val = this[offset + --byteLength]
|
1643 | var mul = 1
|
1644 | while (byteLength > 0 && (mul *= 0x100)) {
|
1645 | val += this[offset + --byteLength] * mul
|
1646 | }
|
1647 |
|
1648 | return val
|
1649 | }
|
1650 |
|
1651 | Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
|
1652 | offset = offset >>> 0
|
1653 | if (!noAssert) checkOffset(offset, 1, this.length)
|
1654 | return this[offset]
|
1655 | }
|
1656 |
|
1657 | Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
|
1658 | offset = offset >>> 0
|
1659 | if (!noAssert) checkOffset(offset, 2, this.length)
|
1660 | return this[offset] | (this[offset + 1] << 8)
|
1661 | }
|
1662 |
|
1663 | Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
|
1664 | offset = offset >>> 0
|
1665 | if (!noAssert) checkOffset(offset, 2, this.length)
|
1666 | return (this[offset] << 8) | this[offset + 1]
|
1667 | }
|
1668 |
|
1669 | Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
|
1670 | offset = offset >>> 0
|
1671 | if (!noAssert) checkOffset(offset, 4, this.length)
|
1672 |
|
1673 | return ((this[offset]) |
|
1674 | (this[offset + 1] << 8) |
|
1675 | (this[offset + 2] << 16)) +
|
1676 | (this[offset + 3] * 0x1000000)
|
1677 | }
|
1678 |
|
1679 | Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
|
1680 | offset = offset >>> 0
|
1681 | if (!noAssert) checkOffset(offset, 4, this.length)
|
1682 |
|
1683 | return (this[offset] * 0x1000000) +
|
1684 | ((this[offset + 1] << 16) |
|
1685 | (this[offset + 2] << 8) |
|
1686 | this[offset + 3])
|
1687 | }
|
1688 |
|
1689 | Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
|
1690 | offset = offset >>> 0
|
1691 | byteLength = byteLength >>> 0
|
1692 | if (!noAssert) checkOffset(offset, byteLength, this.length)
|
1693 |
|
1694 | var val = this[offset]
|
1695 | var mul = 1
|
1696 | var i = 0
|
1697 | while (++i < byteLength && (mul *= 0x100)) {
|
1698 | val += this[offset + i] * mul
|
1699 | }
|
1700 | mul *= 0x80
|
1701 |
|
1702 | if (val >= mul) val -= Math.pow(2, 8 * byteLength)
|
1703 |
|
1704 | return val
|
1705 | }
|
1706 |
|
1707 | Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
|
1708 | offset = offset >>> 0
|
1709 | byteLength = byteLength >>> 0
|
1710 | if (!noAssert) checkOffset(offset, byteLength, this.length)
|
1711 |
|
1712 | var i = byteLength
|
1713 | var mul = 1
|
1714 | var val = this[offset + --i]
|
1715 | while (i > 0 && (mul *= 0x100)) {
|
1716 | val += this[offset + --i] * mul
|
1717 | }
|
1718 | mul *= 0x80
|
1719 |
|
1720 | if (val >= mul) val -= Math.pow(2, 8 * byteLength)
|
1721 |
|
1722 | return val
|
1723 | }
|
1724 |
|
1725 | Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
|
1726 | offset = offset >>> 0
|
1727 | if (!noAssert) checkOffset(offset, 1, this.length)
|
1728 | if (!(this[offset] & 0x80)) return (this[offset])
|
1729 | return ((0xff - this[offset] + 1) * -1)
|
1730 | }
|
1731 |
|
1732 | Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
|
1733 | offset = offset >>> 0
|
1734 | if (!noAssert) checkOffset(offset, 2, this.length)
|
1735 | var val = this[offset] | (this[offset + 1] << 8)
|
1736 | return (val & 0x8000) ? val | 0xFFFF0000 : val
|
1737 | }
|
1738 |
|
1739 | Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
|
1740 | offset = offset >>> 0
|
1741 | if (!noAssert) checkOffset(offset, 2, this.length)
|
1742 | var val = this[offset + 1] | (this[offset] << 8)
|
1743 | return (val & 0x8000) ? val | 0xFFFF0000 : val
|
1744 | }
|
1745 |
|
1746 | Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
|
1747 | offset = offset >>> 0
|
1748 | if (!noAssert) checkOffset(offset, 4, this.length)
|
1749 |
|
1750 | return (this[offset]) |
|
1751 | (this[offset + 1] << 8) |
|
1752 | (this[offset + 2] << 16) |
|
1753 | (this[offset + 3] << 24)
|
1754 | }
|
1755 |
|
1756 | Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
|
1757 | offset = offset >>> 0
|
1758 | if (!noAssert) checkOffset(offset, 4, this.length)
|
1759 |
|
1760 | return (this[offset] << 24) |
|
1761 | (this[offset + 1] << 16) |
|
1762 | (this[offset + 2] << 8) |
|
1763 | (this[offset + 3])
|
1764 | }
|
1765 |
|
1766 | Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
|
1767 | offset = offset >>> 0
|
1768 | if (!noAssert) checkOffset(offset, 4, this.length)
|
1769 | return ieee754.read(this, offset, true, 23, 4)
|
1770 | }
|
1771 |
|
1772 | Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
|
1773 | offset = offset >>> 0
|
1774 | if (!noAssert) checkOffset(offset, 4, this.length)
|
1775 | return ieee754.read(this, offset, false, 23, 4)
|
1776 | }
|
1777 |
|
1778 | Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
|
1779 | offset = offset >>> 0
|
1780 | if (!noAssert) checkOffset(offset, 8, this.length)
|
1781 | return ieee754.read(this, offset, true, 52, 8)
|
1782 | }
|
1783 |
|
1784 | Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
|
1785 | offset = offset >>> 0
|
1786 | if (!noAssert) checkOffset(offset, 8, this.length)
|
1787 | return ieee754.read(this, offset, false, 52, 8)
|
1788 | }
|
1789 |
|
1790 | function checkInt (buf, value, offset, ext, max, min) {
|
1791 | if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
|
1792 | if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
|
1793 | if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
1794 | }
|
1795 |
|
1796 | Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
|
1797 | value = +value
|
1798 | offset = offset >>> 0
|
1799 | byteLength = byteLength >>> 0
|
1800 | if (!noAssert) {
|
1801 | var maxBytes = Math.pow(2, 8 * byteLength) - 1
|
1802 | checkInt(this, value, offset, byteLength, maxBytes, 0)
|
1803 | }
|
1804 |
|
1805 | var mul = 1
|
1806 | var i = 0
|
1807 | this[offset] = value & 0xFF
|
1808 | while (++i < byteLength && (mul *= 0x100)) {
|
1809 | this[offset + i] = (value / mul) & 0xFF
|
1810 | }
|
1811 |
|
1812 | return offset + byteLength
|
1813 | }
|
1814 |
|
1815 | Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
|
1816 | value = +value
|
1817 | offset = offset >>> 0
|
1818 | byteLength = byteLength >>> 0
|
1819 | if (!noAssert) {
|
1820 | var maxBytes = Math.pow(2, 8 * byteLength) - 1
|
1821 | checkInt(this, value, offset, byteLength, maxBytes, 0)
|
1822 | }
|
1823 |
|
1824 | var i = byteLength - 1
|
1825 | var mul = 1
|
1826 | this[offset + i] = value & 0xFF
|
1827 | while (--i >= 0 && (mul *= 0x100)) {
|
1828 | this[offset + i] = (value / mul) & 0xFF
|
1829 | }
|
1830 |
|
1831 | return offset + byteLength
|
1832 | }
|
1833 |
|
1834 | Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
1835 | value = +value
|
1836 | offset = offset >>> 0
|
1837 | if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
|
1838 | this[offset] = (value & 0xff)
|
1839 | return offset + 1
|
1840 | }
|
1841 |
|
1842 | Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
|
1843 | value = +value
|
1844 | offset = offset >>> 0
|
1845 | if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
|
1846 | this[offset] = (value & 0xff)
|
1847 | this[offset + 1] = (value >>> 8)
|
1848 | return offset + 2
|
1849 | }
|
1850 |
|
1851 | Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
|
1852 | value = +value
|
1853 | offset = offset >>> 0
|
1854 | if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
|
1855 | this[offset] = (value >>> 8)
|
1856 | this[offset + 1] = (value & 0xff)
|
1857 | return offset + 2
|
1858 | }
|
1859 |
|
1860 | Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
|
1861 | value = +value
|
1862 | offset = offset >>> 0
|
1863 | if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
|
1864 | this[offset + 3] = (value >>> 24)
|
1865 | this[offset + 2] = (value >>> 16)
|
1866 | this[offset + 1] = (value >>> 8)
|
1867 | this[offset] = (value & 0xff)
|
1868 | return offset + 4
|
1869 | }
|
1870 |
|
1871 | Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
|
1872 | value = +value
|
1873 | offset = offset >>> 0
|
1874 | if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
|
1875 | this[offset] = (value >>> 24)
|
1876 | this[offset + 1] = (value >>> 16)
|
1877 | this[offset + 2] = (value >>> 8)
|
1878 | this[offset + 3] = (value & 0xff)
|
1879 | return offset + 4
|
1880 | }
|
1881 |
|
1882 | Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
|
1883 | value = +value
|
1884 | offset = offset >>> 0
|
1885 | if (!noAssert) {
|
1886 | var limit = Math.pow(2, (8 * byteLength) - 1)
|
1887 |
|
1888 | checkInt(this, value, offset, byteLength, limit - 1, -limit)
|
1889 | }
|
1890 |
|
1891 | var i = 0
|
1892 | var mul = 1
|
1893 | var sub = 0
|
1894 | this[offset] = value & 0xFF
|
1895 | while (++i < byteLength && (mul *= 0x100)) {
|
1896 | if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
1897 | sub = 1
|
1898 | }
|
1899 | this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
|
1900 | }
|
1901 |
|
1902 | return offset + byteLength
|
1903 | }
|
1904 |
|
1905 | Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
|
1906 | value = +value
|
1907 | offset = offset >>> 0
|
1908 | if (!noAssert) {
|
1909 | var limit = Math.pow(2, (8 * byteLength) - 1)
|
1910 |
|
1911 | checkInt(this, value, offset, byteLength, limit - 1, -limit)
|
1912 | }
|
1913 |
|
1914 | var i = byteLength - 1
|
1915 | var mul = 1
|
1916 | var sub = 0
|
1917 | this[offset + i] = value & 0xFF
|
1918 | while (--i >= 0 && (mul *= 0x100)) {
|
1919 | if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
1920 | sub = 1
|
1921 | }
|
1922 | this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
|
1923 | }
|
1924 |
|
1925 | return offset + byteLength
|
1926 | }
|
1927 |
|
1928 | Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
|
1929 | value = +value
|
1930 | offset = offset >>> 0
|
1931 | if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
|
1932 | if (value < 0) value = 0xff + value + 1
|
1933 | this[offset] = (value & 0xff)
|
1934 | return offset + 1
|
1935 | }
|
1936 |
|
1937 | Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
|
1938 | value = +value
|
1939 | offset = offset >>> 0
|
1940 | if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
1941 | this[offset] = (value & 0xff)
|
1942 | this[offset + 1] = (value >>> 8)
|
1943 | return offset + 2
|
1944 | }
|
1945 |
|
1946 | Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
|
1947 | value = +value
|
1948 | offset = offset >>> 0
|
1949 | if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
1950 | this[offset] = (value >>> 8)
|
1951 | this[offset + 1] = (value & 0xff)
|
1952 | return offset + 2
|
1953 | }
|
1954 |
|
1955 | Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
|
1956 | value = +value
|
1957 | offset = offset >>> 0
|
1958 | if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
1959 | this[offset] = (value & 0xff)
|
1960 | this[offset + 1] = (value >>> 8)
|
1961 | this[offset + 2] = (value >>> 16)
|
1962 | this[offset + 3] = (value >>> 24)
|
1963 | return offset + 4
|
1964 | }
|
1965 |
|
1966 | Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
|
1967 | value = +value
|
1968 | offset = offset >>> 0
|
1969 | if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
1970 | if (value < 0) value = 0xffffffff + value + 1
|
1971 | this[offset] = (value >>> 24)
|
1972 | this[offset + 1] = (value >>> 16)
|
1973 | this[offset + 2] = (value >>> 8)
|
1974 | this[offset + 3] = (value & 0xff)
|
1975 | return offset + 4
|
1976 | }
|
1977 |
|
1978 | function checkIEEE754 (buf, value, offset, ext, max, min) {
|
1979 | if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
1980 | if (offset < 0) throw new RangeError('Index out of range')
|
1981 | }
|
1982 |
|
1983 | function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
1984 | value = +value
|
1985 | offset = offset >>> 0
|
1986 | if (!noAssert) {
|
1987 | checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
|
1988 | }
|
1989 | ieee754.write(buf, value, offset, littleEndian, 23, 4)
|
1990 | return offset + 4
|
1991 | }
|
1992 |
|
1993 | Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
|
1994 | return writeFloat(this, value, offset, true, noAssert)
|
1995 | }
|
1996 |
|
1997 | Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
|
1998 | return writeFloat(this, value, offset, false, noAssert)
|
1999 | }
|
2000 |
|
2001 | function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
2002 | value = +value
|
2003 | offset = offset >>> 0
|
2004 | if (!noAssert) {
|
2005 | checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
|
2006 | }
|
2007 | ieee754.write(buf, value, offset, littleEndian, 52, 8)
|
2008 | return offset + 8
|
2009 | }
|
2010 |
|
2011 | Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
|
2012 | return writeDouble(this, value, offset, true, noAssert)
|
2013 | }
|
2014 |
|
2015 | Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
|
2016 | return writeDouble(this, value, offset, false, noAssert)
|
2017 | }
|
2018 |
|
2019 | // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
2020 | Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
2021 | if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
|
2022 | if (!start) start = 0
|
2023 | if (!end && end !== 0) end = this.length
|
2024 | if (targetStart >= target.length) targetStart = target.length
|
2025 | if (!targetStart) targetStart = 0
|
2026 | if (end > 0 && end < start) end = start
|
2027 |
|
2028 | // Copy 0 bytes; we're done
|
2029 | if (end === start) return 0
|
2030 | if (target.length === 0 || this.length === 0) return 0
|
2031 |
|
2032 | // Fatal error conditions
|
2033 | if (targetStart < 0) {
|
2034 | throw new RangeError('targetStart out of bounds')
|
2035 | }
|
2036 | if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
|
2037 | if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
2038 |
|
2039 | // Are we oob?
|
2040 | if (end > this.length) end = this.length
|
2041 | if (target.length - targetStart < end - start) {
|
2042 | end = target.length - targetStart + start
|
2043 | }
|
2044 |
|
2045 | var len = end - start
|
2046 |
|
2047 | if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
|
2048 | // Use built-in when available, missing from IE11
|
2049 | this.copyWithin(targetStart, start, end)
|
2050 | } else if (this === target && start < targetStart && targetStart < end) {
|
2051 | // descending copy from end
|
2052 | for (var i = len - 1; i >= 0; --i) {
|
2053 | target[i + targetStart] = this[i + start]
|
2054 | }
|
2055 | } else {
|
2056 | Uint8Array.prototype.set.call(
|
2057 | target,
|
2058 | this.subarray(start, end),
|
2059 | targetStart
|
2060 | )
|
2061 | }
|
2062 |
|
2063 | return len
|
2064 | }
|
2065 |
|
2066 | // Usage:
|
2067 | // buffer.fill(number[, offset[, end]])
|
2068 | // buffer.fill(buffer[, offset[, end]])
|
2069 | // buffer.fill(string[, offset[, end]][, encoding])
|
2070 | Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
2071 | // Handle string cases:
|
2072 | if (typeof val === 'string') {
|
2073 | if (typeof start === 'string') {
|
2074 | encoding = start
|
2075 | start = 0
|
2076 | end = this.length
|
2077 | } else if (typeof end === 'string') {
|
2078 | encoding = end
|
2079 | end = this.length
|
2080 | }
|
2081 | if (encoding !== undefined && typeof encoding !== 'string') {
|
2082 | throw new TypeError('encoding must be a string')
|
2083 | }
|
2084 | if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
2085 | throw new TypeError('Unknown encoding: ' + encoding)
|
2086 | }
|
2087 | if (val.length === 1) {
|
2088 | var code = val.charCodeAt(0)
|
2089 | if ((encoding === 'utf8' && code < 128) ||
|
2090 | encoding === 'latin1') {
|
2091 | // Fast path: If `val` fits into a single byte, use that numeric value.
|
2092 | val = code
|
2093 | }
|
2094 | }
|
2095 | } else if (typeof val === 'number') {
|
2096 | val = val & 255
|
2097 | }
|
2098 |
|
2099 | // Invalid ranges are not set to a default, so can range check early.
|
2100 | if (start < 0 || this.length < start || this.length < end) {
|
2101 | throw new RangeError('Out of range index')
|
2102 | }
|
2103 |
|
2104 | if (end <= start) {
|
2105 | return this
|
2106 | }
|
2107 |
|
2108 | start = start >>> 0
|
2109 | end = end === undefined ? this.length : end >>> 0
|
2110 |
|
2111 | if (!val) val = 0
|
2112 |
|
2113 | var i
|
2114 | if (typeof val === 'number') {
|
2115 | for (i = start; i < end; ++i) {
|
2116 | this[i] = val
|
2117 | }
|
2118 | } else {
|
2119 | var bytes = Buffer.isBuffer(val)
|
2120 | ? val
|
2121 | : Buffer.from(val, encoding)
|
2122 | var len = bytes.length
|
2123 | if (len === 0) {
|
2124 | throw new TypeError('The value "' + val +
|
2125 | '" is invalid for argument "value"')
|
2126 | }
|
2127 | for (i = 0; i < end - start; ++i) {
|
2128 | this[i + start] = bytes[i % len]
|
2129 | }
|
2130 | }
|
2131 |
|
2132 | return this
|
2133 | }
|
2134 |
|
2135 | // HELPER FUNCTIONS
|
2136 | // ================
|
2137 |
|
2138 | var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
|
2139 |
|
2140 | function base64clean (str) {
|
2141 | // Node takes equal signs as end of the Base64 encoding
|
2142 | str = str.split('=')[0]
|
2143 | // Node strips out invalid characters like \n and \t from the string, base64-js does not
|
2144 | str = str.trim().replace(INVALID_BASE64_RE, '')
|
2145 | // Node converts strings with length < 2 to ''
|
2146 | if (str.length < 2) return ''
|
2147 | // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
|
2148 | while (str.length % 4 !== 0) {
|
2149 | str = str + '='
|
2150 | }
|
2151 | return str
|
2152 | }
|
2153 |
|
2154 | function toHex (n) {
|
2155 | if (n < 16) return '0' + n.toString(16)
|
2156 | return n.toString(16)
|
2157 | }
|
2158 |
|
2159 | function utf8ToBytes (string, units) {
|
2160 | units = units || Infinity
|
2161 | var codePoint
|
2162 | var length = string.length
|
2163 | var leadSurrogate = null
|
2164 | var bytes = []
|
2165 |
|
2166 | for (var i = 0; i < length; ++i) {
|
2167 | codePoint = string.charCodeAt(i)
|
2168 |
|
2169 | // is surrogate component
|
2170 | if (codePoint > 0xD7FF && codePoint < 0xE000) {
|
2171 | // last char was a lead
|
2172 | if (!leadSurrogate) {
|
2173 | // no lead yet
|
2174 | if (codePoint > 0xDBFF) {
|
2175 | // unexpected trail
|
2176 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
2177 | continue
|
2178 | } else if (i + 1 === length) {
|
2179 | // unpaired lead
|
2180 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
2181 | continue
|
2182 | }
|
2183 |
|
2184 | // valid lead
|
2185 | leadSurrogate = codePoint
|
2186 |
|
2187 | continue
|
2188 | }
|
2189 |
|
2190 | // 2 leads in a row
|
2191 | if (codePoint < 0xDC00) {
|
2192 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
2193 | leadSurrogate = codePoint
|
2194 | continue
|
2195 | }
|
2196 |
|
2197 | // valid surrogate pair
|
2198 | codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
|
2199 | } else if (leadSurrogate) {
|
2200 | // valid bmp char, but last char was a lead
|
2201 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
2202 | }
|
2203 |
|
2204 | leadSurrogate = null
|
2205 |
|
2206 | // encode utf8
|
2207 | if (codePoint < 0x80) {
|
2208 | if ((units -= 1) < 0) break
|
2209 | bytes.push(codePoint)
|
2210 | } else if (codePoint < 0x800) {
|
2211 | if ((units -= 2) < 0) break
|
2212 | bytes.push(
|
2213 | codePoint >> 0x6 | 0xC0,
|
2214 | codePoint & 0x3F | 0x80
|
2215 | )
|
2216 | } else if (codePoint < 0x10000) {
|
2217 | if ((units -= 3) < 0) break
|
2218 | bytes.push(
|
2219 | codePoint >> 0xC | 0xE0,
|
2220 | codePoint >> 0x6 & 0x3F | 0x80,
|
2221 | codePoint & 0x3F | 0x80
|
2222 | )
|
2223 | } else if (codePoint < 0x110000) {
|
2224 | if ((units -= 4) < 0) break
|
2225 | bytes.push(
|
2226 | codePoint >> 0x12 | 0xF0,
|
2227 | codePoint >> 0xC & 0x3F | 0x80,
|
2228 | codePoint >> 0x6 & 0x3F | 0x80,
|
2229 | codePoint & 0x3F | 0x80
|
2230 | )
|
2231 | } else {
|
2232 | throw new Error('Invalid code point')
|
2233 | }
|
2234 | }
|
2235 |
|
2236 | return bytes
|
2237 | }
|
2238 |
|
2239 | function asciiToBytes (str) {
|
2240 | var byteArray = []
|
2241 | for (var i = 0; i < str.length; ++i) {
|
2242 | // Node's code seems to be doing this and not & 0x7F..
|
2243 | byteArray.push(str.charCodeAt(i) & 0xFF)
|
2244 | }
|
2245 | return byteArray
|
2246 | }
|
2247 |
|
2248 | function utf16leToBytes (str, units) {
|
2249 | var c, hi, lo
|
2250 | var byteArray = []
|
2251 | for (var i = 0; i < str.length; ++i) {
|
2252 | if ((units -= 2) < 0) break
|
2253 |
|
2254 | c = str.charCodeAt(i)
|
2255 | hi = c >> 8
|
2256 | lo = c % 256
|
2257 | byteArray.push(lo)
|
2258 | byteArray.push(hi)
|
2259 | }
|
2260 |
|
2261 | return byteArray
|
2262 | }
|
2263 |
|
2264 | function base64ToBytes (str) {
|
2265 | return base64.toByteArray(base64clean(str))
|
2266 | }
|
2267 |
|
2268 | function blitBuffer (src, dst, offset, length) {
|
2269 | for (var i = 0; i < length; ++i) {
|
2270 | if ((i + offset >= dst.length) || (i >= src.length)) break
|
2271 | dst[i + offset] = src[i]
|
2272 | }
|
2273 | return i
|
2274 | }
|
2275 |
|
2276 | // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
|
2277 | // the `instanceof` check but they should be treated as of that type.
|
2278 | // See: https://github.com/feross/buffer/issues/166
|
2279 | function isInstance (obj, type) {
|
2280 | return obj instanceof type ||
|
2281 | (obj != null && obj.constructor != null && obj.constructor.name != null &&
|
2282 | obj.constructor.name === type.name)
|
2283 | }
|
2284 | function numberIsNaN (obj) {
|
2285 | // For IE11 support
|
2286 | return obj !== obj // eslint-disable-line no-self-compare
|
2287 | }
|
2288 |
|
2289 | }).call(this)}).call(this,require("buffer").Buffer)
|
2290 | },{"base64-js":3,"buffer":5,"ieee754":9}],6:[function(require,module,exports){
|
2291 | module.exports = {
|
2292 | "100": "Continue",
|
2293 | "101": "Switching Protocols",
|
2294 | "102": "Processing",
|
2295 | "200": "OK",
|
2296 | "201": "Created",
|
2297 | "202": "Accepted",
|
2298 | "203": "Non-Authoritative Information",
|
2299 | "204": "No Content",
|
2300 | "205": "Reset Content",
|
2301 | "206": "Partial Content",
|
2302 | "207": "Multi-Status",
|
2303 | "208": "Already Reported",
|
2304 | "226": "IM Used",
|
2305 | "300": "Multiple Choices",
|
2306 | "301": "Moved Permanently",
|
2307 | "302": "Found",
|
2308 | "303": "See Other",
|
2309 | "304": "Not Modified",
|
2310 | "305": "Use Proxy",
|
2311 | "307": "Temporary Redirect",
|
2312 | "308": "Permanent Redirect",
|
2313 | "400": "Bad Request",
|
2314 | "401": "Unauthorized",
|
2315 | "402": "Payment Required",
|
2316 | "403": "Forbidden",
|
2317 | "404": "Not Found",
|
2318 | "405": "Method Not Allowed",
|
2319 | "406": "Not Acceptable",
|
2320 | "407": "Proxy Authentication Required",
|
2321 | "408": "Request Timeout",
|
2322 | "409": "Conflict",
|
2323 | "410": "Gone",
|
2324 | "411": "Length Required",
|
2325 | "412": "Precondition Failed",
|
2326 | "413": "Payload Too Large",
|
2327 | "414": "URI Too Long",
|
2328 | "415": "Unsupported Media Type",
|
2329 | "416": "Range Not Satisfiable",
|
2330 | "417": "Expectation Failed",
|
2331 | "418": "I'm a teapot",
|
2332 | "421": "Misdirected Request",
|
2333 | "422": "Unprocessable Entity",
|
2334 | "423": "Locked",
|
2335 | "424": "Failed Dependency",
|
2336 | "425": "Unordered Collection",
|
2337 | "426": "Upgrade Required",
|
2338 | "428": "Precondition Required",
|
2339 | "429": "Too Many Requests",
|
2340 | "431": "Request Header Fields Too Large",
|
2341 | "451": "Unavailable For Legal Reasons",
|
2342 | "500": "Internal Server Error",
|
2343 | "501": "Not Implemented",
|
2344 | "502": "Bad Gateway",
|
2345 | "503": "Service Unavailable",
|
2346 | "504": "Gateway Timeout",
|
2347 | "505": "HTTP Version Not Supported",
|
2348 | "506": "Variant Also Negotiates",
|
2349 | "507": "Insufficient Storage",
|
2350 | "508": "Loop Detected",
|
2351 | "509": "Bandwidth Limit Exceeded",
|
2352 | "510": "Not Extended",
|
2353 | "511": "Network Authentication Required"
|
2354 | }
|
2355 |
|
2356 | },{}],7:[function(require,module,exports){
|
2357 | // Copyright Joyent, Inc. and other Node contributors.
|
2358 | //
|
2359 | // Permission is hereby granted, free of charge, to any person obtaining a
|
2360 | // copy of this software and associated documentation files (the
|
2361 | // "Software"), to deal in the Software without restriction, including
|
2362 | // without limitation the rights to use, copy, modify, merge, publish,
|
2363 | // distribute, sublicense, and/or sell copies of the Software, and to permit
|
2364 | // persons to whom the Software is furnished to do so, subject to the
|
2365 | // following conditions:
|
2366 | //
|
2367 | // The above copyright notice and this permission notice shall be included
|
2368 | // in all copies or substantial portions of the Software.
|
2369 | //
|
2370 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
2371 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
2372 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
2373 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
2374 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
2375 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
2376 | // USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2377 |
|
2378 | 'use strict';
|
2379 |
|
2380 | var R = typeof Reflect === 'object' ? Reflect : null
|
2381 | var ReflectApply = R && typeof R.apply === 'function'
|
2382 | ? R.apply
|
2383 | : function ReflectApply(target, receiver, args) {
|
2384 | return Function.prototype.apply.call(target, receiver, args);
|
2385 | }
|
2386 |
|
2387 | var ReflectOwnKeys
|
2388 | if (R && typeof R.ownKeys === 'function') {
|
2389 | ReflectOwnKeys = R.ownKeys
|
2390 | } else if (Object.getOwnPropertySymbols) {
|
2391 | ReflectOwnKeys = function ReflectOwnKeys(target) {
|
2392 | return Object.getOwnPropertyNames(target)
|
2393 | .concat(Object.getOwnPropertySymbols(target));
|
2394 | };
|
2395 | } else {
|
2396 | ReflectOwnKeys = function ReflectOwnKeys(target) {
|
2397 | return Object.getOwnPropertyNames(target);
|
2398 | };
|
2399 | }
|
2400 |
|
2401 | function ProcessEmitWarning(warning) {
|
2402 | if (console && console.warn) console.warn(warning);
|
2403 | }
|
2404 |
|
2405 | var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
|
2406 | return value !== value;
|
2407 | }
|
2408 |
|
2409 | function EventEmitter() {
|
2410 | EventEmitter.init.call(this);
|
2411 | }
|
2412 | module.exports = EventEmitter;
|
2413 | module.exports.once = once;
|
2414 |
|
2415 | // Backwards-compat with node 0.10.x
|
2416 | EventEmitter.EventEmitter = EventEmitter;
|
2417 |
|
2418 | EventEmitter.prototype._events = undefined;
|
2419 | EventEmitter.prototype._eventsCount = 0;
|
2420 | EventEmitter.prototype._maxListeners = undefined;
|
2421 |
|
2422 | // By default EventEmitters will print a warning if more than 10 listeners are
|
2423 | // added to it. This is a useful default which helps finding memory leaks.
|
2424 | var defaultMaxListeners = 10;
|
2425 |
|
2426 | function checkListener(listener) {
|
2427 | if (typeof listener !== 'function') {
|
2428 | throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
|
2429 | }
|
2430 | }
|
2431 |
|
2432 | Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
|
2433 | enumerable: true,
|
2434 | get: function() {
|
2435 | return defaultMaxListeners;
|
2436 | },
|
2437 | set: function(arg) {
|
2438 | if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
|
2439 | throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
|
2440 | }
|
2441 | defaultMaxListeners = arg;
|
2442 | }
|
2443 | });
|
2444 |
|
2445 | EventEmitter.init = function() {
|
2446 |
|
2447 | if (this._events === undefined ||
|
2448 | this._events === Object.getPrototypeOf(this)._events) {
|
2449 | this._events = Object.create(null);
|
2450 | this._eventsCount = 0;
|
2451 | }
|
2452 |
|
2453 | this._maxListeners = this._maxListeners || undefined;
|
2454 | };
|
2455 |
|
2456 | // Obviously not all Emitters should be limited to 10. This function allows
|
2457 | // that to be increased. Set to zero for unlimited.
|
2458 | EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
|
2459 | if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
|
2460 | throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
|
2461 | }
|
2462 | this._maxListeners = n;
|
2463 | return this;
|
2464 | };
|
2465 |
|
2466 | function _getMaxListeners(that) {
|
2467 | if (that._maxListeners === undefined)
|
2468 | return EventEmitter.defaultMaxListeners;
|
2469 | return that._maxListeners;
|
2470 | }
|
2471 |
|
2472 | EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
|
2473 | return _getMaxListeners(this);
|
2474 | };
|
2475 |
|
2476 | EventEmitter.prototype.emit = function emit(type) {
|
2477 | var args = [];
|
2478 | for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
|
2479 | var doError = (type === 'error');
|
2480 |
|
2481 | var events = this._events;
|
2482 | if (events !== undefined)
|
2483 | doError = (doError && events.error === undefined);
|
2484 | else if (!doError)
|
2485 | return false;
|
2486 |
|
2487 | // If there is no 'error' event listener then throw.
|
2488 | if (doError) {
|
2489 | var er;
|
2490 | if (args.length > 0)
|
2491 | er = args[0];
|
2492 | if (er instanceof Error) {
|
2493 | // Note: The comments on the `throw` lines are intentional, they show
|
2494 | // up in Node's output if this results in an unhandled exception.
|
2495 | throw er; // Unhandled 'error' event
|
2496 | }
|
2497 | // At least give some kind of context to the user
|
2498 | var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
|
2499 | err.context = er;
|
2500 | throw err; // Unhandled 'error' event
|
2501 | }
|
2502 |
|
2503 | var handler = events[type];
|
2504 |
|
2505 | if (handler === undefined)
|
2506 | return false;
|
2507 |
|
2508 | if (typeof handler === 'function') {
|
2509 | ReflectApply(handler, this, args);
|
2510 | } else {
|
2511 | var len = handler.length;
|
2512 | var listeners = arrayClone(handler, len);
|
2513 | for (var i = 0; i < len; ++i)
|
2514 | ReflectApply(listeners[i], this, args);
|
2515 | }
|
2516 |
|
2517 | return true;
|
2518 | };
|
2519 |
|
2520 | function _addListener(target, type, listener, prepend) {
|
2521 | var m;
|
2522 | var events;
|
2523 | var existing;
|
2524 |
|
2525 | checkListener(listener);
|
2526 |
|
2527 | events = target._events;
|
2528 | if (events === undefined) {
|
2529 | events = target._events = Object.create(null);
|
2530 | target._eventsCount = 0;
|
2531 | } else {
|
2532 | // To avoid recursion in the case that type === "newListener"! Before
|
2533 | // adding it to the listeners, first emit "newListener".
|
2534 | if (events.newListener !== undefined) {
|
2535 | target.emit('newListener', type,
|
2536 | listener.listener ? listener.listener : listener);
|
2537 |
|
2538 | // Re-assign `events` because a newListener handler could have caused the
|
2539 | // this._events to be assigned to a new object
|
2540 | events = target._events;
|
2541 | }
|
2542 | existing = events[type];
|
2543 | }
|
2544 |
|
2545 | if (existing === undefined) {
|
2546 | // Optimize the case of one listener. Don't need the extra array object.
|
2547 | existing = events[type] = listener;
|
2548 | ++target._eventsCount;
|
2549 | } else {
|
2550 | if (typeof existing === 'function') {
|
2551 | // Adding the second element, need to change to array.
|
2552 | existing = events[type] =
|
2553 | prepend ? [listener, existing] : [existing, listener];
|
2554 | // If we've already got an array, just append.
|
2555 | } else if (prepend) {
|
2556 | existing.unshift(listener);
|
2557 | } else {
|
2558 | existing.push(listener);
|
2559 | }
|
2560 |
|
2561 | // Check for listener leak
|
2562 | m = _getMaxListeners(target);
|
2563 | if (m > 0 && existing.length > m && !existing.warned) {
|
2564 | existing.warned = true;
|
2565 | // No error code for this since it is a Warning
|
2566 | // eslint-disable-next-line no-restricted-syntax
|
2567 | var w = new Error('Possible EventEmitter memory leak detected. ' +
|
2568 | existing.length + ' ' + String(type) + ' listeners ' +
|
2569 | 'added. Use emitter.setMaxListeners() to ' +
|
2570 | 'increase limit');
|
2571 | w.name = 'MaxListenersExceededWarning';
|
2572 | w.emitter = target;
|
2573 | w.type = type;
|
2574 | w.count = existing.length;
|
2575 | ProcessEmitWarning(w);
|
2576 | }
|
2577 | }
|
2578 |
|
2579 | return target;
|
2580 | }
|
2581 |
|
2582 | EventEmitter.prototype.addListener = function addListener(type, listener) {
|
2583 | return _addListener(this, type, listener, false);
|
2584 | };
|
2585 |
|
2586 | EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
2587 |
|
2588 | EventEmitter.prototype.prependListener =
|
2589 | function prependListener(type, listener) {
|
2590 | return _addListener(this, type, listener, true);
|
2591 | };
|
2592 |
|
2593 | function onceWrapper() {
|
2594 | if (!this.fired) {
|
2595 | this.target.removeListener(this.type, this.wrapFn);
|
2596 | this.fired = true;
|
2597 | if (arguments.length === 0)
|
2598 | return this.listener.call(this.target);
|
2599 | return this.listener.apply(this.target, arguments);
|
2600 | }
|
2601 | }
|
2602 |
|
2603 | function _onceWrap(target, type, listener) {
|
2604 | var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
|
2605 | var wrapped = onceWrapper.bind(state);
|
2606 | wrapped.listener = listener;
|
2607 | state.wrapFn = wrapped;
|
2608 | return wrapped;
|
2609 | }
|
2610 |
|
2611 | EventEmitter.prototype.once = function once(type, listener) {
|
2612 | checkListener(listener);
|
2613 | this.on(type, _onceWrap(this, type, listener));
|
2614 | return this;
|
2615 | };
|
2616 |
|
2617 | EventEmitter.prototype.prependOnceListener =
|
2618 | function prependOnceListener(type, listener) {
|
2619 | checkListener(listener);
|
2620 | this.prependListener(type, _onceWrap(this, type, listener));
|
2621 | return this;
|
2622 | };
|
2623 |
|
2624 | // Emits a 'removeListener' event if and only if the listener was removed.
|
2625 | EventEmitter.prototype.removeListener =
|
2626 | function removeListener(type, listener) {
|
2627 | var list, events, position, i, originalListener;
|
2628 |
|
2629 | checkListener(listener);
|
2630 |
|
2631 | events = this._events;
|
2632 | if (events === undefined)
|
2633 | return this;
|
2634 |
|
2635 | list = events[type];
|
2636 | if (list === undefined)
|
2637 | return this;
|
2638 |
|
2639 | if (list === listener || list.listener === listener) {
|
2640 | if (--this._eventsCount === 0)
|
2641 | this._events = Object.create(null);
|
2642 | else {
|
2643 | delete events[type];
|
2644 | if (events.removeListener)
|
2645 | this.emit('removeListener', type, list.listener || listener);
|
2646 | }
|
2647 | } else if (typeof list !== 'function') {
|
2648 | position = -1;
|
2649 |
|
2650 | for (i = list.length - 1; i >= 0; i--) {
|
2651 | if (list[i] === listener || list[i].listener === listener) {
|
2652 | originalListener = list[i].listener;
|
2653 | position = i;
|
2654 | break;
|
2655 | }
|
2656 | }
|
2657 |
|
2658 | if (position < 0)
|
2659 | return this;
|
2660 |
|
2661 | if (position === 0)
|
2662 | list.shift();
|
2663 | else {
|
2664 | spliceOne(list, position);
|
2665 | }
|
2666 |
|
2667 | if (list.length === 1)
|
2668 | events[type] = list[0];
|
2669 |
|
2670 | if (events.removeListener !== undefined)
|
2671 | this.emit('removeListener', type, originalListener || listener);
|
2672 | }
|
2673 |
|
2674 | return this;
|
2675 | };
|
2676 |
|
2677 | EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
2678 |
|
2679 | EventEmitter.prototype.removeAllListeners =
|
2680 | function removeAllListeners(type) {
|
2681 | var listeners, events, i;
|
2682 |
|
2683 | events = this._events;
|
2684 | if (events === undefined)
|
2685 | return this;
|
2686 |
|
2687 | // not listening for removeListener, no need to emit
|
2688 | if (events.removeListener === undefined) {
|
2689 | if (arguments.length === 0) {
|
2690 | this._events = Object.create(null);
|
2691 | this._eventsCount = 0;
|
2692 | } else if (events[type] !== undefined) {
|
2693 | if (--this._eventsCount === 0)
|
2694 | this._events = Object.create(null);
|
2695 | else
|
2696 | delete events[type];
|
2697 | }
|
2698 | return this;
|
2699 | }
|
2700 |
|
2701 | // emit removeListener for all listeners on all events
|
2702 | if (arguments.length === 0) {
|
2703 | var keys = Object.keys(events);
|
2704 | var key;
|
2705 | for (i = 0; i < keys.length; ++i) {
|
2706 | key = keys[i];
|
2707 | if (key === 'removeListener') continue;
|
2708 | this.removeAllListeners(key);
|
2709 | }
|
2710 | this.removeAllListeners('removeListener');
|
2711 | this._events = Object.create(null);
|
2712 | this._eventsCount = 0;
|
2713 | return this;
|
2714 | }
|
2715 |
|
2716 | listeners = events[type];
|
2717 |
|
2718 | if (typeof listeners === 'function') {
|
2719 | this.removeListener(type, listeners);
|
2720 | } else if (listeners !== undefined) {
|
2721 | // LIFO order
|
2722 | for (i = listeners.length - 1; i >= 0; i--) {
|
2723 | this.removeListener(type, listeners[i]);
|
2724 | }
|
2725 | }
|
2726 |
|
2727 | return this;
|
2728 | };
|
2729 |
|
2730 | function _listeners(target, type, unwrap) {
|
2731 | var events = target._events;
|
2732 |
|
2733 | if (events === undefined)
|
2734 | return [];
|
2735 |
|
2736 | var evlistener = events[type];
|
2737 | if (evlistener === undefined)
|
2738 | return [];
|
2739 |
|
2740 | if (typeof evlistener === 'function')
|
2741 | return unwrap ? [evlistener.listener || evlistener] : [evlistener];
|
2742 |
|
2743 | return unwrap ?
|
2744 | unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
|
2745 | }
|
2746 |
|
2747 | EventEmitter.prototype.listeners = function listeners(type) {
|
2748 | return _listeners(this, type, true);
|
2749 | };
|
2750 |
|
2751 | EventEmitter.prototype.rawListeners = function rawListeners(type) {
|
2752 | return _listeners(this, type, false);
|
2753 | };
|
2754 |
|
2755 | EventEmitter.listenerCount = function(emitter, type) {
|
2756 | if (typeof emitter.listenerCount === 'function') {
|
2757 | return emitter.listenerCount(type);
|
2758 | } else {
|
2759 | return listenerCount.call(emitter, type);
|
2760 | }
|
2761 | };
|
2762 |
|
2763 | EventEmitter.prototype.listenerCount = listenerCount;
|
2764 | function listenerCount(type) {
|
2765 | var events = this._events;
|
2766 |
|
2767 | if (events !== undefined) {
|
2768 | var evlistener = events[type];
|
2769 |
|
2770 | if (typeof evlistener === 'function') {
|
2771 | return 1;
|
2772 | } else if (evlistener !== undefined) {
|
2773 | return evlistener.length;
|
2774 | }
|
2775 | }
|
2776 |
|
2777 | return 0;
|
2778 | }
|
2779 |
|
2780 | EventEmitter.prototype.eventNames = function eventNames() {
|
2781 | return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
|
2782 | };
|
2783 |
|
2784 | function arrayClone(arr, n) {
|
2785 | var copy = new Array(n);
|
2786 | for (var i = 0; i < n; ++i)
|
2787 | copy[i] = arr[i];
|
2788 | return copy;
|
2789 | }
|
2790 |
|
2791 | function spliceOne(list, index) {
|
2792 | for (; index + 1 < list.length; index++)
|
2793 | list[index] = list[index + 1];
|
2794 | list.pop();
|
2795 | }
|
2796 |
|
2797 | function unwrapListeners(arr) {
|
2798 | var ret = new Array(arr.length);
|
2799 | for (var i = 0; i < ret.length; ++i) {
|
2800 | ret[i] = arr[i].listener || arr[i];
|
2801 | }
|
2802 | return ret;
|
2803 | }
|
2804 |
|
2805 | function once(emitter, name) {
|
2806 | return new Promise(function (resolve, reject) {
|
2807 | function errorListener(err) {
|
2808 | emitter.removeListener(name, resolver);
|
2809 | reject(err);
|
2810 | }
|
2811 |
|
2812 | function resolver() {
|
2813 | if (typeof emitter.removeListener === 'function') {
|
2814 | emitter.removeListener('error', errorListener);
|
2815 | }
|
2816 | resolve([].slice.call(arguments));
|
2817 | };
|
2818 |
|
2819 | eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
|
2820 | if (name !== 'error') {
|
2821 | addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
|
2822 | }
|
2823 | });
|
2824 | }
|
2825 |
|
2826 | function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
|
2827 | if (typeof emitter.on === 'function') {
|
2828 | eventTargetAgnosticAddListener(emitter, 'error', handler, flags);
|
2829 | }
|
2830 | }
|
2831 |
|
2832 | function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
2833 | if (typeof emitter.on === 'function') {
|
2834 | if (flags.once) {
|
2835 | emitter.once(name, listener);
|
2836 | } else {
|
2837 | emitter.on(name, listener);
|
2838 | }
|
2839 | } else if (typeof emitter.addEventListener === 'function') {
|
2840 | // EventTarget does not have `error` event semantics like Node
|
2841 | // EventEmitters, we do not listen for `error` events here.
|
2842 | emitter.addEventListener(name, function wrapListener(arg) {
|
2843 | // IE does not have builtin `{ once: true }` support so we
|
2844 | // have to do it manually.
|
2845 | if (flags.once) {
|
2846 | emitter.removeEventListener(name, wrapListener);
|
2847 | }
|
2848 | listener(arg);
|
2849 | });
|
2850 | } else {
|
2851 | throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
|
2852 | }
|
2853 | }
|
2854 |
|
2855 | },{}],8:[function(require,module,exports){
|
2856 | var http = require('http')
|
2857 | var url = require('url')
|
2858 |
|
2859 | var https = module.exports
|
2860 |
|
2861 | for (var key in http) {
|
2862 | if (http.hasOwnProperty(key)) https[key] = http[key]
|
2863 | }
|
2864 |
|
2865 | https.request = function (params, cb) {
|
2866 | params = validateParams(params)
|
2867 | return http.request.call(this, params, cb)
|
2868 | }
|
2869 |
|
2870 | https.get = function (params, cb) {
|
2871 | params = validateParams(params)
|
2872 | return http.get.call(this, params, cb)
|
2873 | }
|
2874 |
|
2875 | function validateParams (params) {
|
2876 | if (typeof params === 'string') {
|
2877 | params = url.parse(params)
|
2878 | }
|
2879 | if (!params.protocol) {
|
2880 | params.protocol = 'https:'
|
2881 | }
|
2882 | if (params.protocol !== 'https:') {
|
2883 | throw new Error('Protocol "' + params.protocol + '" not supported. Expected "https:"')
|
2884 | }
|
2885 | return params
|
2886 | }
|
2887 |
|
2888 | },{"http":32,"url":52}],9:[function(require,module,exports){
|
2889 | /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
2890 | exports.read = function (buffer, offset, isLE, mLen, nBytes) {
|
2891 | var e, m
|
2892 | var eLen = (nBytes * 8) - mLen - 1
|
2893 | var eMax = (1 << eLen) - 1
|
2894 | var eBias = eMax >> 1
|
2895 | var nBits = -7
|
2896 | var i = isLE ? (nBytes - 1) : 0
|
2897 | var d = isLE ? -1 : 1
|
2898 | var s = buffer[offset + i]
|
2899 |
|
2900 | i += d
|
2901 |
|
2902 | e = s & ((1 << (-nBits)) - 1)
|
2903 | s >>= (-nBits)
|
2904 | nBits += eLen
|
2905 | for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
2906 |
|
2907 | m = e & ((1 << (-nBits)) - 1)
|
2908 | e >>= (-nBits)
|
2909 | nBits += mLen
|
2910 | for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
2911 |
|
2912 | if (e === 0) {
|
2913 | e = 1 - eBias
|
2914 | } else if (e === eMax) {
|
2915 | return m ? NaN : ((s ? -1 : 1) * Infinity)
|
2916 | } else {
|
2917 | m = m + Math.pow(2, mLen)
|
2918 | e = e - eBias
|
2919 | }
|
2920 | return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
2921 | }
|
2922 |
|
2923 | exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
|
2924 | var e, m, c
|
2925 | var eLen = (nBytes * 8) - mLen - 1
|
2926 | var eMax = (1 << eLen) - 1
|
2927 | var eBias = eMax >> 1
|
2928 | var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
|
2929 | var i = isLE ? 0 : (nBytes - 1)
|
2930 | var d = isLE ? 1 : -1
|
2931 | var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
|
2932 |
|
2933 | value = Math.abs(value)
|
2934 |
|
2935 | if (isNaN(value) || value === Infinity) {
|
2936 | m = isNaN(value) ? 1 : 0
|
2937 | e = eMax
|
2938 | } else {
|
2939 | e = Math.floor(Math.log(value) / Math.LN2)
|
2940 | if (value * (c = Math.pow(2, -e)) < 1) {
|
2941 | e--
|
2942 | c *= 2
|
2943 | }
|
2944 | if (e + eBias >= 1) {
|
2945 | value += rt / c
|
2946 | } else {
|
2947 | value += rt * Math.pow(2, 1 - eBias)
|
2948 | }
|
2949 | if (value * c >= 2) {
|
2950 | e++
|
2951 | c /= 2
|
2952 | }
|
2953 |
|
2954 | if (e + eBias >= eMax) {
|
2955 | m = 0
|
2956 | e = eMax
|
2957 | } else if (e + eBias >= 1) {
|
2958 | m = ((value * c) - 1) * Math.pow(2, mLen)
|
2959 | e = e + eBias
|
2960 | } else {
|
2961 | m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
|
2962 | e = 0
|
2963 | }
|
2964 | }
|
2965 |
|
2966 | for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
2967 |
|
2968 | e = (e << mLen) | m
|
2969 | eLen += mLen
|
2970 | for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
2971 |
|
2972 | buffer[offset + i - d] |= s * 128
|
2973 | }
|
2974 |
|
2975 | },{}],10:[function(require,module,exports){
|
2976 | if (typeof Object.create === 'function') {
|
2977 | // implementation from standard node.js 'util' module
|
2978 | module.exports = function inherits(ctor, superCtor) {
|
2979 | if (superCtor) {
|
2980 | ctor.super_ = superCtor
|
2981 | ctor.prototype = Object.create(superCtor.prototype, {
|
2982 | constructor: {
|
2983 | value: ctor,
|
2984 | enumerable: false,
|
2985 | writable: true,
|
2986 | configurable: true
|
2987 | }
|
2988 | })
|
2989 | }
|
2990 | };
|
2991 | } else {
|
2992 | // old school shim for old browsers
|
2993 | module.exports = function inherits(ctor, superCtor) {
|
2994 | if (superCtor) {
|
2995 | ctor.super_ = superCtor
|
2996 | var TempCtor = function () {}
|
2997 | TempCtor.prototype = superCtor.prototype
|
2998 | ctor.prototype = new TempCtor()
|
2999 | ctor.prototype.constructor = ctor
|
3000 | }
|
3001 | }
|
3002 | }
|
3003 |
|
3004 | },{}],11:[function(require,module,exports){
|
3005 | // shim for using process in browser
|
3006 | var process = module.exports = {};
|
3007 |
|
3008 | // cached from whatever global is present so that test runners that stub it
|
3009 | // don't break things. But we need to wrap it in a try catch in case it is
|
3010 | // wrapped in strict mode code which doesn't define any globals. It's inside a
|
3011 | // function because try/catches deoptimize in certain engines.
|
3012 |
|
3013 | var cachedSetTimeout;
|
3014 | var cachedClearTimeout;
|
3015 |
|
3016 | function defaultSetTimout() {
|
3017 | throw new Error('setTimeout has not been defined');
|
3018 | }
|
3019 | function defaultClearTimeout () {
|
3020 | throw new Error('clearTimeout has not been defined');
|
3021 | }
|
3022 | (function () {
|
3023 | try {
|
3024 | if (typeof setTimeout === 'function') {
|
3025 | cachedSetTimeout = setTimeout;
|
3026 | } else {
|
3027 | cachedSetTimeout = defaultSetTimout;
|
3028 | }
|
3029 | } catch (e) {
|
3030 | cachedSetTimeout = defaultSetTimout;
|
3031 | }
|
3032 | try {
|
3033 | if (typeof clearTimeout === 'function') {
|
3034 | cachedClearTimeout = clearTimeout;
|
3035 | } else {
|
3036 | cachedClearTimeout = defaultClearTimeout;
|
3037 | }
|
3038 | } catch (e) {
|
3039 | cachedClearTimeout = defaultClearTimeout;
|
3040 | }
|
3041 | } ())
|
3042 | function runTimeout(fun) {
|
3043 | if (cachedSetTimeout === setTimeout) {
|
3044 | //normal enviroments in sane situations
|
3045 | return setTimeout(fun, 0);
|
3046 | }
|
3047 | // if setTimeout wasn't available but was latter defined
|
3048 | if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
3049 | cachedSetTimeout = setTimeout;
|
3050 | return setTimeout(fun, 0);
|
3051 | }
|
3052 | try {
|
3053 | // when when somebody has screwed with setTimeout but no I.E. maddness
|
3054 | return cachedSetTimeout(fun, 0);
|
3055 | } catch(e){
|
3056 | try {
|
3057 | // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
3058 | return cachedSetTimeout.call(null, fun, 0);
|
3059 | } catch(e){
|
3060 | // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
|
3061 | return cachedSetTimeout.call(this, fun, 0);
|
3062 | }
|
3063 | }
|
3064 |
|
3065 |
|
3066 | }
|
3067 | function runClearTimeout(marker) {
|
3068 | if (cachedClearTimeout === clearTimeout) {
|
3069 | //normal enviroments in sane situations
|
3070 | return clearTimeout(marker);
|
3071 | }
|
3072 | // if clearTimeout wasn't available but was latter defined
|
3073 | if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
3074 | cachedClearTimeout = clearTimeout;
|
3075 | return clearTimeout(marker);
|
3076 | }
|
3077 | try {
|
3078 | // when when somebody has screwed with setTimeout but no I.E. maddness
|
3079 | return cachedClearTimeout(marker);
|
3080 | } catch (e){
|
3081 | try {
|
3082 | // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
3083 | return cachedClearTimeout.call(null, marker);
|
3084 | } catch (e){
|
3085 | // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
|
3086 | // Some versions of I.E. have different rules for clearTimeout vs setTimeout
|
3087 | return cachedClearTimeout.call(this, marker);
|
3088 | }
|
3089 | }
|
3090 |
|
3091 |
|
3092 |
|
3093 | }
|
3094 | var queue = [];
|
3095 | var draining = false;
|
3096 | var currentQueue;
|
3097 | var queueIndex = -1;
|
3098 |
|
3099 | function cleanUpNextTick() {
|
3100 | if (!draining || !currentQueue) {
|
3101 | return;
|
3102 | }
|
3103 | draining = false;
|
3104 | if (currentQueue.length) {
|
3105 | queue = currentQueue.concat(queue);
|
3106 | } else {
|
3107 | queueIndex = -1;
|
3108 | }
|
3109 | if (queue.length) {
|
3110 | drainQueue();
|
3111 | }
|
3112 | }
|
3113 |
|
3114 | function drainQueue() {
|
3115 | if (draining) {
|
3116 | return;
|
3117 | }
|
3118 | var timeout = runTimeout(cleanUpNextTick);
|
3119 | draining = true;
|
3120 |
|
3121 | var len = queue.length;
|
3122 | while(len) {
|
3123 | currentQueue = queue;
|
3124 | queue = [];
|
3125 | while (++queueIndex < len) {
|
3126 | if (currentQueue) {
|
3127 | currentQueue[queueIndex].run();
|
3128 | }
|
3129 | }
|
3130 | queueIndex = -1;
|
3131 | len = queue.length;
|
3132 | }
|
3133 | currentQueue = null;
|
3134 | draining = false;
|
3135 | runClearTimeout(timeout);
|
3136 | }
|
3137 |
|
3138 | process.nextTick = function (fun) {
|
3139 | var args = new Array(arguments.length - 1);
|
3140 | if (arguments.length > 1) {
|
3141 | for (var i = 1; i < arguments.length; i++) {
|
3142 | args[i - 1] = arguments[i];
|
3143 | }
|
3144 | }
|
3145 | queue.push(new Item(fun, args));
|
3146 | if (queue.length === 1 && !draining) {
|
3147 | runTimeout(drainQueue);
|
3148 | }
|
3149 | };
|
3150 |
|
3151 | // v8 likes predictible objects
|
3152 | function Item(fun, array) {
|
3153 | this.fun = fun;
|
3154 | this.array = array;
|
3155 | }
|
3156 | Item.prototype.run = function () {
|
3157 | this.fun.apply(null, this.array);
|
3158 | };
|
3159 | process.title = 'browser';
|
3160 | process.browser = true;
|
3161 | process.env = {};
|
3162 | process.argv = [];
|
3163 | process.version = ''; // empty string to avoid regexp issues
|
3164 | process.versions = {};
|
3165 |
|
3166 | function noop() {}
|
3167 |
|
3168 | process.on = noop;
|
3169 | process.addListener = noop;
|
3170 | process.once = noop;
|
3171 | process.off = noop;
|
3172 | process.removeListener = noop;
|
3173 | process.removeAllListeners = noop;
|
3174 | process.emit = noop;
|
3175 | process.prependListener = noop;
|
3176 | process.prependOnceListener = noop;
|
3177 |
|
3178 | process.listeners = function (name) { return [] }
|
3179 |
|
3180 | process.binding = function (name) {
|
3181 | throw new Error('process.binding is not supported');
|
3182 | };
|
3183 |
|
3184 | process.cwd = function () { return '/' };
|
3185 | process.chdir = function (dir) {
|
3186 | throw new Error('process.chdir is not supported');
|
3187 | };
|
3188 | process.umask = function() { return 0; };
|
3189 |
|
3190 | },{}],12:[function(require,module,exports){
|
3191 | (function (global){(function (){
|
3192 | /*! https://mths.be/punycode v1.4.1 by @mathias */
|
3193 | ;(function(root) {
|
3194 |
|
3195 | /** Detect free variables */
|
3196 | var freeExports = typeof exports == 'object' && exports &&
|
3197 | !exports.nodeType && exports;
|
3198 | var freeModule = typeof module == 'object' && module &&
|
3199 | !module.nodeType && module;
|
3200 | var freeGlobal = typeof global == 'object' && global;
|
3201 | if (
|
3202 | freeGlobal.global === freeGlobal ||
|
3203 | freeGlobal.window === freeGlobal ||
|
3204 | freeGlobal.self === freeGlobal
|
3205 | ) {
|
3206 | root = freeGlobal;
|
3207 | }
|
3208 |
|
3209 | /**
|
3210 | * The `punycode` object.
|
3211 | * @name punycode
|
3212 | * @type Object
|
3213 | */
|
3214 | var punycode,
|
3215 |
|
3216 | /** Highest positive signed 32-bit float value */
|
3217 | maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
|
3218 |
|
3219 | /** Bootstring parameters */
|
3220 | base = 36,
|
3221 | tMin = 1,
|
3222 | tMax = 26,
|
3223 | skew = 38,
|
3224 | damp = 700,
|
3225 | initialBias = 72,
|
3226 | initialN = 128, // 0x80
|
3227 | delimiter = '-', // '\x2D'
|
3228 |
|
3229 | /** Regular expressions */
|
3230 | regexPunycode = /^xn--/,
|
3231 | regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars
|
3232 | regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators
|
3233 |
|
3234 | /** Error messages */
|
3235 | errors = {
|
3236 | 'overflow': 'Overflow: input needs wider integers to process',
|
3237 | 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
|
3238 | 'invalid-input': 'Invalid input'
|
3239 | },
|
3240 |
|
3241 | /** Convenience shortcuts */
|
3242 | baseMinusTMin = base - tMin,
|
3243 | floor = Math.floor,
|
3244 | stringFromCharCode = String.fromCharCode,
|
3245 |
|
3246 | /** Temporary variable */
|
3247 | key;
|
3248 |
|
3249 | /*--------------------------------------------------------------------------*/
|
3250 |
|
3251 | /**
|
3252 | * A generic error utility function.
|
3253 | * @private
|
3254 | * @param {String} type The error type.
|
3255 | * @returns {Error} Throws a `RangeError` with the applicable error message.
|
3256 | */
|
3257 | function error(type) {
|
3258 | throw new RangeError(errors[type]);
|
3259 | }
|
3260 |
|
3261 | /**
|
3262 | * A generic `Array#map` utility function.
|
3263 | * @private
|
3264 | * @param {Array} array The array to iterate over.
|
3265 | * @param {Function} callback The function that gets called for every array
|
3266 | * item.
|
3267 | * @returns {Array} A new array of values returned by the callback function.
|
3268 | */
|
3269 | function map(array, fn) {
|
3270 | var length = array.length;
|
3271 | var result = [];
|
3272 | while (length--) {
|
3273 | result[length] = fn(array[length]);
|
3274 | }
|
3275 | return result;
|
3276 | }
|
3277 |
|
3278 | /**
|
3279 | * A simple `Array#map`-like wrapper to work with domain name strings or email
|
3280 | * addresses.
|
3281 | * @private
|
3282 | * @param {String} domain The domain name or email address.
|
3283 | * @param {Function} callback The function that gets called for every
|
3284 | * character.
|
3285 | * @returns {Array} A new string of characters returned by the callback
|
3286 | * function.
|
3287 | */
|
3288 | function mapDomain(string, fn) {
|
3289 | var parts = string.split('@');
|
3290 | var result = '';
|
3291 | if (parts.length > 1) {
|
3292 | // In email addresses, only the domain name should be punycoded. Leave
|
3293 | // the local part (i.e. everything up to `@`) intact.
|
3294 | result = parts[0] + '@';
|
3295 | string = parts[1];
|
3296 | }
|
3297 | // Avoid `split(regex)` for IE8 compatibility. See #17.
|
3298 | string = string.replace(regexSeparators, '\x2E');
|
3299 | var labels = string.split('.');
|
3300 | var encoded = map(labels, fn).join('.');
|
3301 | return result + encoded;
|
3302 | }
|
3303 |
|
3304 | /**
|
3305 | * Creates an array containing the numeric code points of each Unicode
|
3306 | * character in the string. While JavaScript uses UCS-2 internally,
|
3307 | * this function will convert a pair of surrogate halves (each of which
|
3308 | * UCS-2 exposes as separate characters) into a single code point,
|
3309 | * matching UTF-16.
|
3310 | * @see `punycode.ucs2.encode`
|
3311 | * @see <https://mathiasbynens.be/notes/javascript-encoding>
|
3312 | * @memberOf punycode.ucs2
|
3313 | * @name decode
|
3314 | * @param {String} string The Unicode input string (UCS-2).
|
3315 | * @returns {Array} The new array of code points.
|
3316 | */
|
3317 | function ucs2decode(string) {
|
3318 | var output = [],
|
3319 | counter = 0,
|
3320 | length = string.length,
|
3321 | value,
|
3322 | extra;
|
3323 | while (counter < length) {
|
3324 | value = string.charCodeAt(counter++);
|
3325 | if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
|
3326 | // high surrogate, and there is a next character
|
3327 | extra = string.charCodeAt(counter++);
|
3328 | if ((extra & 0xFC00) == 0xDC00) { // low surrogate
|
3329 | output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
|
3330 | } else {
|
3331 | // unmatched surrogate; only append this code unit, in case the next
|
3332 | // code unit is the high surrogate of a surrogate pair
|
3333 | output.push(value);
|
3334 | counter--;
|
3335 | }
|
3336 | } else {
|
3337 | output.push(value);
|
3338 | }
|
3339 | }
|
3340 | return output;
|
3341 | }
|
3342 |
|
3343 | /**
|
3344 | * Creates a string based on an array of numeric code points.
|
3345 | * @see `punycode.ucs2.decode`
|
3346 | * @memberOf punycode.ucs2
|
3347 | * @name encode
|
3348 | * @param {Array} codePoints The array of numeric code points.
|
3349 | * @returns {String} The new Unicode string (UCS-2).
|
3350 | */
|
3351 | function ucs2encode(array) {
|
3352 | return map(array, function(value) {
|
3353 | var output = '';
|
3354 | if (value > 0xFFFF) {
|
3355 | value -= 0x10000;
|
3356 | output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
|
3357 | value = 0xDC00 | value & 0x3FF;
|
3358 | }
|
3359 | output += stringFromCharCode(value);
|
3360 | return output;
|
3361 | }).join('');
|
3362 | }
|
3363 |
|
3364 | /**
|
3365 | * Converts a basic code point into a digit/integer.
|
3366 | * @see `digitToBasic()`
|
3367 | * @private
|
3368 | * @param {Number} codePoint The basic numeric code point value.
|
3369 | * @returns {Number} The numeric value of a basic code point (for use in
|
3370 | * representing integers) in the range `0` to `base - 1`, or `base` if
|
3371 | * the code point does not represent a value.
|
3372 | */
|
3373 | function basicToDigit(codePoint) {
|
3374 | if (codePoint - 48 < 10) {
|
3375 | return codePoint - 22;
|
3376 | }
|
3377 | if (codePoint - 65 < 26) {
|
3378 | return codePoint - 65;
|
3379 | }
|
3380 | if (codePoint - 97 < 26) {
|
3381 | return codePoint - 97;
|
3382 | }
|
3383 | return base;
|
3384 | }
|
3385 |
|
3386 | /**
|
3387 | * Converts a digit/integer into a basic code point.
|
3388 | * @see `basicToDigit()`
|
3389 | * @private
|
3390 | * @param {Number} digit The numeric value of a basic code point.
|
3391 | * @returns {Number} The basic code point whose value (when used for
|
3392 | * representing integers) is `digit`, which needs to be in the range
|
3393 | * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
|
3394 | * used; else, the lowercase form is used. The behavior is undefined
|
3395 | * if `flag` is non-zero and `digit` has no uppercase form.
|
3396 | */
|
3397 | function digitToBasic(digit, flag) {
|
3398 | // 0..25 map to ASCII a..z or A..Z
|
3399 | // 26..35 map to ASCII 0..9
|
3400 | return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
|
3401 | }
|
3402 |
|
3403 | /**
|
3404 | * Bias adaptation function as per section 3.4 of RFC 3492.
|
3405 | * https://tools.ietf.org/html/rfc3492#section-3.4
|
3406 | * @private
|
3407 | */
|
3408 | function adapt(delta, numPoints, firstTime) {
|
3409 | var k = 0;
|
3410 | delta = firstTime ? floor(delta / damp) : delta >> 1;
|
3411 | delta += floor(delta / numPoints);
|
3412 | for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
|
3413 | delta = floor(delta / baseMinusTMin);
|
3414 | }
|
3415 | return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
|
3416 | }
|
3417 |
|
3418 | /**
|
3419 | * Converts a Punycode string of ASCII-only symbols to a string of Unicode
|
3420 | * symbols.
|
3421 | * @memberOf punycode
|
3422 | * @param {String} input The Punycode string of ASCII-only symbols.
|
3423 | * @returns {String} The resulting string of Unicode symbols.
|
3424 | */
|
3425 | function decode(input) {
|
3426 | // Don't use UCS-2
|
3427 | var output = [],
|
3428 | inputLength = input.length,
|
3429 | out,
|
3430 | i = 0,
|
3431 | n = initialN,
|
3432 | bias = initialBias,
|
3433 | basic,
|
3434 | j,
|
3435 | index,
|
3436 | oldi,
|
3437 | w,
|
3438 | k,
|
3439 | digit,
|
3440 | t,
|
3441 | /** Cached calculation results */
|
3442 | baseMinusT;
|
3443 |
|
3444 | // Handle the basic code points: let `basic` be the number of input code
|
3445 | // points before the last delimiter, or `0` if there is none, then copy
|
3446 | // the first basic code points to the output.
|
3447 |
|
3448 | basic = input.lastIndexOf(delimiter);
|
3449 | if (basic < 0) {
|
3450 | basic = 0;
|
3451 | }
|
3452 |
|
3453 | for (j = 0; j < basic; ++j) {
|
3454 | // if it's not a basic code point
|
3455 | if (input.charCodeAt(j) >= 0x80) {
|
3456 | error('not-basic');
|
3457 | }
|
3458 | output.push(input.charCodeAt(j));
|
3459 | }
|
3460 |
|
3461 | // Main decoding loop: start just after the last delimiter if any basic code
|
3462 | // points were copied; start at the beginning otherwise.
|
3463 |
|
3464 | for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
|
3465 |
|
3466 | // `index` is the index of the next character to be consumed.
|
3467 | // Decode a generalized variable-length integer into `delta`,
|
3468 | // which gets added to `i`. The overflow checking is easier
|
3469 | // if we increase `i` as we go, then subtract off its starting
|
3470 | // value at the end to obtain `delta`.
|
3471 | for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
|
3472 |
|
3473 | if (index >= inputLength) {
|
3474 | error('invalid-input');
|
3475 | }
|
3476 |
|
3477 | digit = basicToDigit(input.charCodeAt(index++));
|
3478 |
|
3479 | if (digit >= base || digit > floor((maxInt - i) / w)) {
|
3480 | error('overflow');
|
3481 | }
|
3482 |
|
3483 | i += digit * w;
|
3484 | t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
|
3485 |
|
3486 | if (digit < t) {
|
3487 | break;
|
3488 | }
|
3489 |
|
3490 | baseMinusT = base - t;
|
3491 | if (w > floor(maxInt / baseMinusT)) {
|
3492 | error('overflow');
|
3493 | }
|
3494 |
|
3495 | w *= baseMinusT;
|
3496 |
|
3497 | }
|
3498 |
|
3499 | out = output.length + 1;
|
3500 | bias = adapt(i - oldi, out, oldi == 0);
|
3501 |
|
3502 | // `i` was supposed to wrap around from `out` to `0`,
|
3503 | // incrementing `n` each time, so we'll fix that now:
|
3504 | if (floor(i / out) > maxInt - n) {
|
3505 | error('overflow');
|
3506 | }
|
3507 |
|
3508 | n += floor(i / out);
|
3509 | i %= out;
|
3510 |
|
3511 | // Insert `n` at position `i` of the output
|
3512 | output.splice(i++, 0, n);
|
3513 |
|
3514 | }
|
3515 |
|
3516 | return ucs2encode(output);
|
3517 | }
|
3518 |
|
3519 | /**
|
3520 | * Converts a string of Unicode symbols (e.g. a domain name label) to a
|
3521 | * Punycode string of ASCII-only symbols.
|
3522 | * @memberOf punycode
|
3523 | * @param {String} input The string of Unicode symbols.
|
3524 | * @returns {String} The resulting Punycode string of ASCII-only symbols.
|
3525 | */
|
3526 | function encode(input) {
|
3527 | var n,
|
3528 | delta,
|
3529 | handledCPCount,
|
3530 | basicLength,
|
3531 | bias,
|
3532 | j,
|
3533 | m,
|
3534 | q,
|
3535 | k,
|
3536 | t,
|
3537 | currentValue,
|
3538 | output = [],
|
3539 | /** `inputLength` will hold the number of code points in `input`. */
|
3540 | inputLength,
|
3541 | /** Cached calculation results */
|
3542 | handledCPCountPlusOne,
|
3543 | baseMinusT,
|
3544 | qMinusT;
|
3545 |
|
3546 | // Convert the input in UCS-2 to Unicode
|
3547 | input = ucs2decode(input);
|
3548 |
|
3549 | // Cache the length
|
3550 | inputLength = input.length;
|
3551 |
|
3552 | // Initialize the state
|
3553 | n = initialN;
|
3554 | delta = 0;
|
3555 | bias = initialBias;
|
3556 |
|
3557 | // Handle the basic code points
|
3558 | for (j = 0; j < inputLength; ++j) {
|
3559 | currentValue = input[j];
|
3560 | if (currentValue < 0x80) {
|
3561 | output.push(stringFromCharCode(currentValue));
|
3562 | }
|
3563 | }
|
3564 |
|
3565 | handledCPCount = basicLength = output.length;
|
3566 |
|
3567 | // `handledCPCount` is the number of code points that have been handled;
|
3568 | // `basicLength` is the number of basic code points.
|
3569 |
|
3570 | // Finish the basic string - if it is not empty - with a delimiter
|
3571 | if (basicLength) {
|
3572 | output.push(delimiter);
|
3573 | }
|
3574 |
|
3575 | // Main encoding loop:
|
3576 | while (handledCPCount < inputLength) {
|
3577 |
|
3578 | // All non-basic code points < n have been handled already. Find the next
|
3579 | // larger one:
|
3580 | for (m = maxInt, j = 0; j < inputLength; ++j) {
|
3581 | currentValue = input[j];
|
3582 | if (currentValue >= n && currentValue < m) {
|
3583 | m = currentValue;
|
3584 | }
|
3585 | }
|
3586 |
|
3587 | // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
|
3588 | // but guard against overflow
|
3589 | handledCPCountPlusOne = handledCPCount + 1;
|
3590 | if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
|
3591 | error('overflow');
|
3592 | }
|
3593 |
|
3594 | delta += (m - n) * handledCPCountPlusOne;
|
3595 | n = m;
|
3596 |
|
3597 | for (j = 0; j < inputLength; ++j) {
|
3598 | currentValue = input[j];
|
3599 |
|
3600 | if (currentValue < n && ++delta > maxInt) {
|
3601 | error('overflow');
|
3602 | }
|
3603 |
|
3604 | if (currentValue == n) {
|
3605 | // Represent delta as a generalized variable-length integer
|
3606 | for (q = delta, k = base; /* no condition */; k += base) {
|
3607 | t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
|
3608 | if (q < t) {
|
3609 | break;
|
3610 | }
|
3611 | qMinusT = q - t;
|
3612 | baseMinusT = base - t;
|
3613 | output.push(
|
3614 | stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
|
3615 | );
|
3616 | q = floor(qMinusT / baseMinusT);
|
3617 | }
|
3618 |
|
3619 | output.push(stringFromCharCode(digitToBasic(q, 0)));
|
3620 | bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
|
3621 | delta = 0;
|
3622 | ++handledCPCount;
|
3623 | }
|
3624 | }
|
3625 |
|
3626 | ++delta;
|
3627 | ++n;
|
3628 |
|
3629 | }
|
3630 | return output.join('');
|
3631 | }
|
3632 |
|
3633 | /**
|
3634 | * Converts a Punycode string representing a domain name or an email address
|
3635 | * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
|
3636 | * it doesn't matter if you call it on a string that has already been
|
3637 | * converted to Unicode.
|
3638 | * @memberOf punycode
|
3639 | * @param {String} input The Punycoded domain name or email address to
|
3640 | * convert to Unicode.
|
3641 | * @returns {String} The Unicode representation of the given Punycode
|
3642 | * string.
|
3643 | */
|
3644 | function toUnicode(input) {
|
3645 | return mapDomain(input, function(string) {
|
3646 | return regexPunycode.test(string)
|
3647 | ? decode(string.slice(4).toLowerCase())
|
3648 | : string;
|
3649 | });
|
3650 | }
|
3651 |
|
3652 | /**
|
3653 | * Converts a Unicode string representing a domain name or an email address to
|
3654 | * Punycode. Only the non-ASCII parts of the domain name will be converted,
|
3655 | * i.e. it doesn't matter if you call it with a domain that's already in
|
3656 | * ASCII.
|
3657 | * @memberOf punycode
|
3658 | * @param {String} input The domain name or email address to convert, as a
|
3659 | * Unicode string.
|
3660 | * @returns {String} The Punycode representation of the given domain name or
|
3661 | * email address.
|
3662 | */
|
3663 | function toASCII(input) {
|
3664 | return mapDomain(input, function(string) {
|
3665 | return regexNonASCII.test(string)
|
3666 | ? 'xn--' + encode(string)
|
3667 | : string;
|
3668 | });
|
3669 | }
|
3670 |
|
3671 | /*--------------------------------------------------------------------------*/
|
3672 |
|
3673 | /** Define the public API */
|
3674 | punycode = {
|
3675 | /**
|
3676 | * A string representing the current Punycode.js version number.
|
3677 | * @memberOf punycode
|
3678 | * @type String
|
3679 | */
|
3680 | 'version': '1.4.1',
|
3681 | /**
|
3682 | * An object of methods to convert from JavaScript's internal character
|
3683 | * representation (UCS-2) to Unicode code points, and back.
|
3684 | * @see <https://mathiasbynens.be/notes/javascript-encoding>
|
3685 | * @memberOf punycode
|
3686 | * @type Object
|
3687 | */
|
3688 | 'ucs2': {
|
3689 | 'decode': ucs2decode,
|
3690 | 'encode': ucs2encode
|
3691 | },
|
3692 | 'decode': decode,
|
3693 | 'encode': encode,
|
3694 | 'toASCII': toASCII,
|
3695 | 'toUnicode': toUnicode
|
3696 | };
|
3697 |
|
3698 | /** Expose `punycode` */
|
3699 | // Some AMD build optimizers, like r.js, check for specific condition patterns
|
3700 | // like the following:
|
3701 | if (
|
3702 | typeof define == 'function' &&
|
3703 | typeof define.amd == 'object' &&
|
3704 | define.amd
|
3705 | ) {
|
3706 | define('punycode', function() {
|
3707 | return punycode;
|
3708 | });
|
3709 | } else if (freeExports && freeModule) {
|
3710 | if (module.exports == freeExports) {
|
3711 | // in Node.js, io.js, or RingoJS v0.8.0+
|
3712 | freeModule.exports = punycode;
|
3713 | } else {
|
3714 | // in Narwhal or RingoJS v0.7.0-
|
3715 | for (key in punycode) {
|
3716 | punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
|
3717 | }
|
3718 | }
|
3719 | } else {
|
3720 | // in Rhino or a web browser
|
3721 | root.punycode = punycode;
|
3722 | }
|
3723 |
|
3724 | }(this));
|
3725 |
|
3726 | }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
3727 | },{}],13:[function(require,module,exports){
|
3728 | // Copyright Joyent, Inc. and other Node contributors.
|
3729 | //
|
3730 | // Permission is hereby granted, free of charge, to any person obtaining a
|
3731 | // copy of this software and associated documentation files (the
|
3732 | // "Software"), to deal in the Software without restriction, including
|
3733 | // without limitation the rights to use, copy, modify, merge, publish,
|
3734 | // distribute, sublicense, and/or sell copies of the Software, and to permit
|
3735 | // persons to whom the Software is furnished to do so, subject to the
|
3736 | // following conditions:
|
3737 | //
|
3738 | // The above copyright notice and this permission notice shall be included
|
3739 | // in all copies or substantial portions of the Software.
|
3740 | //
|
3741 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
3742 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
3743 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
3744 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
3745 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
3746 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
3747 | // USE OR OTHER DEALINGS IN THE SOFTWARE.
|
3748 |
|
3749 | 'use strict';
|
3750 |
|
3751 | // If obj.hasOwnProperty has been overridden, then calling
|
3752 | // obj.hasOwnProperty(prop) will break.
|
3753 | // See: https://github.com/joyent/node/issues/1707
|
3754 | function hasOwnProperty(obj, prop) {
|
3755 | return Object.prototype.hasOwnProperty.call(obj, prop);
|
3756 | }
|
3757 |
|
3758 | module.exports = function(qs, sep, eq, options) {
|
3759 | sep = sep || '&';
|
3760 | eq = eq || '=';
|
3761 | var obj = {};
|
3762 |
|
3763 | if (typeof qs !== 'string' || qs.length === 0) {
|
3764 | return obj;
|
3765 | }
|
3766 |
|
3767 | var regexp = /\+/g;
|
3768 | qs = qs.split(sep);
|
3769 |
|
3770 | var maxKeys = 1000;
|
3771 | if (options && typeof options.maxKeys === 'number') {
|
3772 | maxKeys = options.maxKeys;
|
3773 | }
|
3774 |
|
3775 | var len = qs.length;
|
3776 | // maxKeys <= 0 means that we should not limit keys count
|
3777 | if (maxKeys > 0 && len > maxKeys) {
|
3778 | len = maxKeys;
|
3779 | }
|
3780 |
|
3781 | for (var i = 0; i < len; ++i) {
|
3782 | var x = qs[i].replace(regexp, '%20'),
|
3783 | idx = x.indexOf(eq),
|
3784 | kstr, vstr, k, v;
|
3785 |
|
3786 | if (idx >= 0) {
|
3787 | kstr = x.substr(0, idx);
|
3788 | vstr = x.substr(idx + 1);
|
3789 | } else {
|
3790 | kstr = x;
|
3791 | vstr = '';
|
3792 | }
|
3793 |
|
3794 | k = decodeURIComponent(kstr);
|
3795 | v = decodeURIComponent(vstr);
|
3796 |
|
3797 | if (!hasOwnProperty(obj, k)) {
|
3798 | obj[k] = v;
|
3799 | } else if (isArray(obj[k])) {
|
3800 | obj[k].push(v);
|
3801 | } else {
|
3802 | obj[k] = [obj[k], v];
|
3803 | }
|
3804 | }
|
3805 |
|
3806 | return obj;
|
3807 | };
|
3808 |
|
3809 | var isArray = Array.isArray || function (xs) {
|
3810 | return Object.prototype.toString.call(xs) === '[object Array]';
|
3811 | };
|
3812 |
|
3813 | },{}],14:[function(require,module,exports){
|
3814 | // Copyright Joyent, Inc. and other Node contributors.
|
3815 | //
|
3816 | // Permission is hereby granted, free of charge, to any person obtaining a
|
3817 | // copy of this software and associated documentation files (the
|
3818 | // "Software"), to deal in the Software without restriction, including
|
3819 | // without limitation the rights to use, copy, modify, merge, publish,
|
3820 | // distribute, sublicense, and/or sell copies of the Software, and to permit
|
3821 | // persons to whom the Software is furnished to do so, subject to the
|
3822 | // following conditions:
|
3823 | //
|
3824 | // The above copyright notice and this permission notice shall be included
|
3825 | // in all copies or substantial portions of the Software.
|
3826 | //
|
3827 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
3828 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
3829 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
3830 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
3831 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
3832 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
3833 | // USE OR OTHER DEALINGS IN THE SOFTWARE.
|
3834 |
|
3835 | 'use strict';
|
3836 |
|
3837 | var stringifyPrimitive = function(v) {
|
3838 | switch (typeof v) {
|
3839 | case 'string':
|
3840 | return v;
|
3841 |
|
3842 | case 'boolean':
|
3843 | return v ? 'true' : 'false';
|
3844 |
|
3845 | case 'number':
|
3846 | return isFinite(v) ? v : '';
|
3847 |
|
3848 | default:
|
3849 | return '';
|
3850 | }
|
3851 | };
|
3852 |
|
3853 | module.exports = function(obj, sep, eq, name) {
|
3854 | sep = sep || '&';
|
3855 | eq = eq || '=';
|
3856 | if (obj === null) {
|
3857 | obj = undefined;
|
3858 | }
|
3859 |
|
3860 | if (typeof obj === 'object') {
|
3861 | return map(objectKeys(obj), function(k) {
|
3862 | var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
|
3863 | if (isArray(obj[k])) {
|
3864 | return map(obj[k], function(v) {
|
3865 | return ks + encodeURIComponent(stringifyPrimitive(v));
|
3866 | }).join(sep);
|
3867 | } else {
|
3868 | return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
|
3869 | }
|
3870 | }).join(sep);
|
3871 |
|
3872 | }
|
3873 |
|
3874 | if (!name) return '';
|
3875 | return encodeURIComponent(stringifyPrimitive(name)) + eq +
|
3876 | encodeURIComponent(stringifyPrimitive(obj));
|
3877 | };
|
3878 |
|
3879 | var isArray = Array.isArray || function (xs) {
|
3880 | return Object.prototype.toString.call(xs) === '[object Array]';
|
3881 | };
|
3882 |
|
3883 | function map (xs, f) {
|
3884 | if (xs.map) return xs.map(f);
|
3885 | var res = [];
|
3886 | for (var i = 0; i < xs.length; i++) {
|
3887 | res.push(f(xs[i], i));
|
3888 | }
|
3889 | return res;
|
3890 | }
|
3891 |
|
3892 | var objectKeys = Object.keys || function (obj) {
|
3893 | var res = [];
|
3894 | for (var key in obj) {
|
3895 | if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
|
3896 | }
|
3897 | return res;
|
3898 | };
|
3899 |
|
3900 | },{}],15:[function(require,module,exports){
|
3901 | 'use strict';
|
3902 |
|
3903 | exports.decode = exports.parse = require('./decode');
|
3904 | exports.encode = exports.stringify = require('./encode');
|
3905 |
|
3906 | },{"./decode":13,"./encode":14}],16:[function(require,module,exports){
|
3907 | /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
3908 | /* eslint-disable node/no-deprecated-api */
|
3909 | var buffer = require('buffer')
|
3910 | var Buffer = buffer.Buffer
|
3911 |
|
3912 | // alternative to using Object.keys for old browsers
|
3913 | function copyProps (src, dst) {
|
3914 | for (var key in src) {
|
3915 | dst[key] = src[key]
|
3916 | }
|
3917 | }
|
3918 | if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
|
3919 | module.exports = buffer
|
3920 | } else {
|
3921 | // Copy properties from require('buffer')
|
3922 | copyProps(buffer, exports)
|
3923 | exports.Buffer = SafeBuffer
|
3924 | }
|
3925 |
|
3926 | function SafeBuffer (arg, encodingOrOffset, length) {
|
3927 | return Buffer(arg, encodingOrOffset, length)
|
3928 | }
|
3929 |
|
3930 | SafeBuffer.prototype = Object.create(Buffer.prototype)
|
3931 |
|
3932 | // Copy static methods from Buffer
|
3933 | copyProps(Buffer, SafeBuffer)
|
3934 |
|
3935 | SafeBuffer.from = function (arg, encodingOrOffset, length) {
|
3936 | if (typeof arg === 'number') {
|
3937 | throw new TypeError('Argument must not be a number')
|
3938 | }
|
3939 | return Buffer(arg, encodingOrOffset, length)
|
3940 | }
|
3941 |
|
3942 | SafeBuffer.alloc = function (size, fill, encoding) {
|
3943 | if (typeof size !== 'number') {
|
3944 | throw new TypeError('Argument must be a number')
|
3945 | }
|
3946 | var buf = Buffer(size)
|
3947 | if (fill !== undefined) {
|
3948 | if (typeof encoding === 'string') {
|
3949 | buf.fill(fill, encoding)
|
3950 | } else {
|
3951 | buf.fill(fill)
|
3952 | }
|
3953 | } else {
|
3954 | buf.fill(0)
|
3955 | }
|
3956 | return buf
|
3957 | }
|
3958 |
|
3959 | SafeBuffer.allocUnsafe = function (size) {
|
3960 | if (typeof size !== 'number') {
|
3961 | throw new TypeError('Argument must be a number')
|
3962 | }
|
3963 | return Buffer(size)
|
3964 | }
|
3965 |
|
3966 | SafeBuffer.allocUnsafeSlow = function (size) {
|
3967 | if (typeof size !== 'number') {
|
3968 | throw new TypeError('Argument must be a number')
|
3969 | }
|
3970 | return buffer.SlowBuffer(size)
|
3971 | }
|
3972 |
|
3973 | },{"buffer":5}],17:[function(require,module,exports){
|
3974 | // Copyright Joyent, Inc. and other Node contributors.
|
3975 | //
|
3976 | // Permission is hereby granted, free of charge, to any person obtaining a
|
3977 | // copy of this software and associated documentation files (the
|
3978 | // "Software"), to deal in the Software without restriction, including
|
3979 | // without limitation the rights to use, copy, modify, merge, publish,
|
3980 | // distribute, sublicense, and/or sell copies of the Software, and to permit
|
3981 | // persons to whom the Software is furnished to do so, subject to the
|
3982 | // following conditions:
|
3983 | //
|
3984 | // The above copyright notice and this permission notice shall be included
|
3985 | // in all copies or substantial portions of the Software.
|
3986 | //
|
3987 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
3988 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
3989 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
3990 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
3991 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
3992 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
3993 | // USE OR OTHER DEALINGS IN THE SOFTWARE.
|
3994 |
|
3995 | module.exports = Stream;
|
3996 |
|
3997 | var EE = require('events').EventEmitter;
|
3998 | var inherits = require('inherits');
|
3999 |
|
4000 | inherits(Stream, EE);
|
4001 | Stream.Readable = require('readable-stream/lib/_stream_readable.js');
|
4002 | Stream.Writable = require('readable-stream/lib/_stream_writable.js');
|
4003 | Stream.Duplex = require('readable-stream/lib/_stream_duplex.js');
|
4004 | Stream.Transform = require('readable-stream/lib/_stream_transform.js');
|
4005 | Stream.PassThrough = require('readable-stream/lib/_stream_passthrough.js');
|
4006 | Stream.finished = require('readable-stream/lib/internal/streams/end-of-stream.js')
|
4007 | Stream.pipeline = require('readable-stream/lib/internal/streams/pipeline.js')
|
4008 |
|
4009 | // Backwards-compat with node 0.4.x
|
4010 | Stream.Stream = Stream;
|
4011 |
|
4012 |
|
4013 |
|
4014 | // old-style streams. Note that the pipe method (the only relevant
|
4015 | // part of this class) is overridden in the Readable class.
|
4016 |
|
4017 | function Stream() {
|
4018 | EE.call(this);
|
4019 | }
|
4020 |
|
4021 | Stream.prototype.pipe = function(dest, options) {
|
4022 | var source = this;
|
4023 |
|
4024 | function ondata(chunk) {
|
4025 | if (dest.writable) {
|
4026 | if (false === dest.write(chunk) && source.pause) {
|
4027 | source.pause();
|
4028 | }
|
4029 | }
|
4030 | }
|
4031 |
|
4032 | source.on('data', ondata);
|
4033 |
|
4034 | function ondrain() {
|
4035 | if (source.readable && source.resume) {
|
4036 | source.resume();
|
4037 | }
|
4038 | }
|
4039 |
|
4040 | dest.on('drain', ondrain);
|
4041 |
|
4042 | // If the 'end' option is not supplied, dest.end() will be called when
|
4043 | // source gets the 'end' or 'close' events. Only dest.end() once.
|
4044 | if (!dest._isStdio && (!options || options.end !== false)) {
|
4045 | source.on('end', onend);
|
4046 | source.on('close', onclose);
|
4047 | }
|
4048 |
|
4049 | var didOnEnd = false;
|
4050 | function onend() {
|
4051 | if (didOnEnd) return;
|
4052 | didOnEnd = true;
|
4053 |
|
4054 | dest.end();
|
4055 | }
|
4056 |
|
4057 |
|
4058 | function onclose() {
|
4059 | if (didOnEnd) return;
|
4060 | didOnEnd = true;
|
4061 |
|
4062 | if (typeof dest.destroy === 'function') dest.destroy();
|
4063 | }
|
4064 |
|
4065 | // don't leave dangling pipes when there are errors.
|
4066 | function onerror(er) {
|
4067 | cleanup();
|
4068 | if (EE.listenerCount(this, 'error') === 0) {
|
4069 | throw er; // Unhandled stream error in pipe.
|
4070 | }
|
4071 | }
|
4072 |
|
4073 | source.on('error', onerror);
|
4074 | dest.on('error', onerror);
|
4075 |
|
4076 | // remove all the event listeners that were added.
|
4077 | function cleanup() {
|
4078 | source.removeListener('data', ondata);
|
4079 | dest.removeListener('drain', ondrain);
|
4080 |
|
4081 | source.removeListener('end', onend);
|
4082 | source.removeListener('close', onclose);
|
4083 |
|
4084 | source.removeListener('error', onerror);
|
4085 | dest.removeListener('error', onerror);
|
4086 |
|
4087 | source.removeListener('end', cleanup);
|
4088 | source.removeListener('close', cleanup);
|
4089 |
|
4090 | dest.removeListener('close', cleanup);
|
4091 | }
|
4092 |
|
4093 | source.on('end', cleanup);
|
4094 | source.on('close', cleanup);
|
4095 |
|
4096 | dest.on('close', cleanup);
|
4097 |
|
4098 | dest.emit('pipe', source);
|
4099 |
|
4100 | // Allow for unix-like usage: A.pipe(B).pipe(C)
|
4101 | return dest;
|
4102 | };
|
4103 |
|
4104 | },{"events":7,"inherits":10,"readable-stream/lib/_stream_duplex.js":19,"readable-stream/lib/_stream_passthrough.js":20,"readable-stream/lib/_stream_readable.js":21,"readable-stream/lib/_stream_transform.js":22,"readable-stream/lib/_stream_writable.js":23,"readable-stream/lib/internal/streams/end-of-stream.js":27,"readable-stream/lib/internal/streams/pipeline.js":29}],18:[function(require,module,exports){
|
4105 | 'use strict';
|
4106 |
|
4107 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
|
4108 |
|
4109 | var codes = {};
|
4110 |
|
4111 | function createErrorType(code, message, Base) {
|
4112 | if (!Base) {
|
4113 | Base = Error;
|
4114 | }
|
4115 |
|
4116 | function getMessage(arg1, arg2, arg3) {
|
4117 | if (typeof message === 'string') {
|
4118 | return message;
|
4119 | } else {
|
4120 | return message(arg1, arg2, arg3);
|
4121 | }
|
4122 | }
|
4123 |
|
4124 | var NodeError =
|
4125 | /*#__PURE__*/
|
4126 | function (_Base) {
|
4127 | _inheritsLoose(NodeError, _Base);
|
4128 |
|
4129 | function NodeError(arg1, arg2, arg3) {
|
4130 | return _Base.call(this, getMessage(arg1, arg2, arg3)) || this;
|
4131 | }
|
4132 |
|
4133 | return NodeError;
|
4134 | }(Base);
|
4135 |
|
4136 | NodeError.prototype.name = Base.name;
|
4137 | NodeError.prototype.code = code;
|
4138 | codes[code] = NodeError;
|
4139 | } // https://github.com/nodejs/node/blob/v10.8.0/lib/internal/errors.js
|
4140 |
|
4141 |
|
4142 | function oneOf(expected, thing) {
|
4143 | if (Array.isArray(expected)) {
|
4144 | var len = expected.length;
|
4145 | expected = expected.map(function (i) {
|
4146 | return String(i);
|
4147 | });
|
4148 |
|
4149 | if (len > 2) {
|
4150 | return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(', '), ", or ") + expected[len - 1];
|
4151 | } else if (len === 2) {
|
4152 | return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]);
|
4153 | } else {
|
4154 | return "of ".concat(thing, " ").concat(expected[0]);
|
4155 | }
|
4156 | } else {
|
4157 | return "of ".concat(thing, " ").concat(String(expected));
|
4158 | }
|
4159 | } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
|
4160 |
|
4161 |
|
4162 | function startsWith(str, search, pos) {
|
4163 | return str.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
|
4164 | } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
|
4165 |
|
4166 |
|
4167 | function endsWith(str, search, this_len) {
|
4168 | if (this_len === undefined || this_len > str.length) {
|
4169 | this_len = str.length;
|
4170 | }
|
4171 |
|
4172 | return str.substring(this_len - search.length, this_len) === search;
|
4173 | } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
|
4174 |
|
4175 |
|
4176 | function includes(str, search, start) {
|
4177 | if (typeof start !== 'number') {
|
4178 | start = 0;
|
4179 | }
|
4180 |
|
4181 | if (start + search.length > str.length) {
|
4182 | return false;
|
4183 | } else {
|
4184 | return str.indexOf(search, start) !== -1;
|
4185 | }
|
4186 | }
|
4187 |
|
4188 | createErrorType('ERR_INVALID_OPT_VALUE', function (name, value) {
|
4189 | return 'The value "' + value + '" is invalid for option "' + name + '"';
|
4190 | }, TypeError);
|
4191 | createErrorType('ERR_INVALID_ARG_TYPE', function (name, expected, actual) {
|
4192 | // determiner: 'must be' or 'must not be'
|
4193 | var determiner;
|
4194 |
|
4195 | if (typeof expected === 'string' && startsWith(expected, 'not ')) {
|
4196 | determiner = 'must not be';
|
4197 | expected = expected.replace(/^not /, '');
|
4198 | } else {
|
4199 | determiner = 'must be';
|
4200 | }
|
4201 |
|
4202 | var msg;
|
4203 |
|
4204 | if (endsWith(name, ' argument')) {
|
4205 | // For cases like 'first argument'
|
4206 | msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
|
4207 | } else {
|
4208 | var type = includes(name, '.') ? 'property' : 'argument';
|
4209 | msg = "The \"".concat(name, "\" ").concat(type, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
|
4210 | }
|
4211 |
|
4212 | msg += ". Received type ".concat(typeof actual);
|
4213 | return msg;
|
4214 | }, TypeError);
|
4215 | createErrorType('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF');
|
4216 | createErrorType('ERR_METHOD_NOT_IMPLEMENTED', function (name) {
|
4217 | return 'The ' + name + ' method is not implemented';
|
4218 | });
|
4219 | createErrorType('ERR_STREAM_PREMATURE_CLOSE', 'Premature close');
|
4220 | createErrorType('ERR_STREAM_DESTROYED', function (name) {
|
4221 | return 'Cannot call ' + name + ' after a stream was destroyed';
|
4222 | });
|
4223 | createErrorType('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times');
|
4224 | createErrorType('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable');
|
4225 | createErrorType('ERR_STREAM_WRITE_AFTER_END', 'write after end');
|
4226 | createErrorType('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError);
|
4227 | createErrorType('ERR_UNKNOWN_ENCODING', function (arg) {
|
4228 | return 'Unknown encoding: ' + arg;
|
4229 | }, TypeError);
|
4230 | createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
|
4231 | module.exports.codes = codes;
|
4232 |
|
4233 | },{}],19:[function(require,module,exports){
|
4234 | (function (process){(function (){
|
4235 | // Copyright Joyent, Inc. and other Node contributors.
|
4236 | //
|
4237 | // Permission is hereby granted, free of charge, to any person obtaining a
|
4238 | // copy of this software and associated documentation files (the
|
4239 | // "Software"), to deal in the Software without restriction, including
|
4240 | // without limitation the rights to use, copy, modify, merge, publish,
|
4241 | // distribute, sublicense, and/or sell copies of the Software, and to permit
|
4242 | // persons to whom the Software is furnished to do so, subject to the
|
4243 | // following conditions:
|
4244 | //
|
4245 | // The above copyright notice and this permission notice shall be included
|
4246 | // in all copies or substantial portions of the Software.
|
4247 | //
|
4248 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
4249 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
4250 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
4251 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
4252 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
4253 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
4254 | // USE OR OTHER DEALINGS IN THE SOFTWARE.
|
4255 | // a duplex stream is just a stream that is both readable and writable.
|
4256 | // Since JS doesn't have multiple prototypal inheritance, this class
|
4257 | // prototypally inherits from Readable, and then parasitically from
|
4258 | // Writable.
|
4259 | 'use strict';
|
4260 | /*<replacement>*/
|
4261 |
|
4262 | var objectKeys = Object.keys || function (obj) {
|
4263 | var keys = [];
|
4264 |
|
4265 | for (var key in obj) {
|
4266 | keys.push(key);
|
4267 | }
|
4268 |
|
4269 | return keys;
|
4270 | };
|
4271 | /*</replacement>*/
|
4272 |
|
4273 |
|
4274 | module.exports = Duplex;
|
4275 |
|
4276 | var Readable = require('./_stream_readable');
|
4277 |
|
4278 | var Writable = require('./_stream_writable');
|
4279 |
|
4280 | require('inherits')(Duplex, Readable);
|
4281 |
|
4282 | {
|
4283 | // Allow the keys array to be GC'ed.
|
4284 | var keys = objectKeys(Writable.prototype);
|
4285 |
|
4286 | for (var v = 0; v < keys.length; v++) {
|
4287 | var method = keys[v];
|
4288 | if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
|
4289 | }
|
4290 | }
|
4291 |
|
4292 | function Duplex(options) {
|
4293 | if (!(this instanceof Duplex)) return new Duplex(options);
|
4294 | Readable.call(this, options);
|
4295 | Writable.call(this, options);
|
4296 | this.allowHalfOpen = true;
|
4297 |
|
4298 | if (options) {
|
4299 | if (options.readable === false) this.readable = false;
|
4300 | if (options.writable === false) this.writable = false;
|
4301 |
|
4302 | if (options.allowHalfOpen === false) {
|
4303 | this.allowHalfOpen = false;
|
4304 | this.once('end', onend);
|
4305 | }
|
4306 | }
|
4307 | }
|
4308 |
|
4309 | Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
|
4310 | // making it explicit this property is not enumerable
|
4311 | // because otherwise some prototype manipulation in
|
4312 | // userland will fail
|
4313 | enumerable: false,
|
4314 | get: function get() {
|
4315 | return this._writableState.highWaterMark;
|
4316 | }
|
4317 | });
|
4318 | Object.defineProperty(Duplex.prototype, 'writableBuffer', {
|
4319 | // making it explicit this property is not enumerable
|
4320 | // because otherwise some prototype manipulation in
|
4321 | // userland will fail
|
4322 | enumerable: false,
|
4323 | get: function get() {
|
4324 | return this._writableState && this._writableState.getBuffer();
|
4325 | }
|
4326 | });
|
4327 | Object.defineProperty(Duplex.prototype, 'writableLength', {
|
4328 | // making it explicit this property is not enumerable
|
4329 | // because otherwise some prototype manipulation in
|
4330 | // userland will fail
|
4331 | enumerable: false,
|
4332 | get: function get() {
|
4333 | return this._writableState.length;
|
4334 | }
|
4335 | }); // the no-half-open enforcer
|
4336 |
|
4337 | function onend() {
|
4338 | // If the writable side ended, then we're ok.
|
4339 | if (this._writableState.ended) return; // no more data can be written.
|
4340 | // But allow more writes to happen in this tick.
|
4341 |
|
4342 | process.nextTick(onEndNT, this);
|
4343 | }
|
4344 |
|
4345 | function onEndNT(self) {
|
4346 | self.end();
|
4347 | }
|
4348 |
|
4349 | Object.defineProperty(Duplex.prototype, 'destroyed', {
|
4350 | // making it explicit this property is not enumerable
|
4351 | // because otherwise some prototype manipulation in
|
4352 | // userland will fail
|
4353 | enumerable: false,
|
4354 | get: function get() {
|
4355 | if (this._readableState === undefined || this._writableState === undefined) {
|
4356 | return false;
|
4357 | }
|
4358 |
|
4359 | return this._readableState.destroyed && this._writableState.destroyed;
|
4360 | },
|
4361 | set: function set(value) {
|
4362 | // we ignore the value if the stream
|
4363 | // has not been initialized yet
|
4364 | if (this._readableState === undefined || this._writableState === undefined) {
|
4365 | return;
|
4366 | } // backward compatibility, the user is explicitly
|
4367 | // managing destroyed
|
4368 |
|
4369 |
|
4370 | this._readableState.destroyed = value;
|
4371 | this._writableState.destroyed = value;
|
4372 | }
|
4373 | });
|
4374 | }).call(this)}).call(this,require('_process'))
|
4375 | },{"./_stream_readable":21,"./_stream_writable":23,"_process":11,"inherits":10}],20:[function(require,module,exports){
|
4376 | // Copyright Joyent, Inc. and other Node contributors.
|
4377 | //
|
4378 | // Permission is hereby granted, free of charge, to any person obtaining a
|
4379 | // copy of this software and associated documentation files (the
|
4380 | // "Software"), to deal in the Software without restriction, including
|
4381 | // without limitation the rights to use, copy, modify, merge, publish,
|
4382 | // distribute, sublicense, and/or sell copies of the Software, and to permit
|
4383 | // persons to whom the Software is furnished to do so, subject to the
|
4384 | // following conditions:
|
4385 | //
|
4386 | // The above copyright notice and this permission notice shall be included
|
4387 | // in all copies or substantial portions of the Software.
|
4388 | //
|
4389 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
4390 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
4391 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
4392 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
4393 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
4394 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
4395 | // USE OR OTHER DEALINGS IN THE SOFTWARE.
|
4396 | // a passthrough stream.
|
4397 | // basically just the most minimal sort of Transform stream.
|
4398 | // Every written chunk gets output as-is.
|
4399 | 'use strict';
|
4400 |
|
4401 | module.exports = PassThrough;
|
4402 |
|
4403 | var Transform = require('./_stream_transform');
|
4404 |
|
4405 | require('inherits')(PassThrough, Transform);
|
4406 |
|
4407 | function PassThrough(options) {
|
4408 | if (!(this instanceof PassThrough)) return new PassThrough(options);
|
4409 | Transform.call(this, options);
|
4410 | }
|
4411 |
|
4412 | PassThrough.prototype._transform = function (chunk, encoding, cb) {
|
4413 | cb(null, chunk);
|
4414 | };
|
4415 | },{"./_stream_transform":22,"inherits":10}],21:[function(require,module,exports){
|
4416 | (function (process,global){(function (){
|
4417 | // Copyright Joyent, Inc. and other Node contributors.
|
4418 | //
|
4419 | // Permission is hereby granted, free of charge, to any person obtaining a
|
4420 | // copy of this software and associated documentation files (the
|
4421 | // "Software"), to deal in the Software without restriction, including
|
4422 | // without limitation the rights to use, copy, modify, merge, publish,
|
4423 | // distribute, sublicense, and/or sell copies of the Software, and to permit
|
4424 | // persons to whom the Software is furnished to do so, subject to the
|
4425 | // following conditions:
|
4426 | //
|
4427 | // The above copyright notice and this permission notice shall be included
|
4428 | // in all copies or substantial portions of the Software.
|
4429 | //
|
4430 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
4431 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
4432 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
4433 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
4434 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
4435 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
4436 | // USE OR OTHER DEALINGS IN THE SOFTWARE.
|
4437 | 'use strict';
|
4438 |
|
4439 | module.exports = Readable;
|
4440 | /*<replacement>*/
|
4441 |
|
4442 | var Duplex;
|
4443 | /*</replacement>*/
|
4444 |
|
4445 | Readable.ReadableState = ReadableState;
|
4446 | /*<replacement>*/
|
4447 |
|
4448 | var EE = require('events').EventEmitter;
|
4449 |
|
4450 | var EElistenerCount = function EElistenerCount(emitter, type) {
|
4451 | return emitter.listeners(type).length;
|
4452 | };
|
4453 | /*</replacement>*/
|
4454 |
|
4455 | /*<replacement>*/
|
4456 |
|
4457 |
|
4458 | var Stream = require('./internal/streams/stream');
|
4459 | /*</replacement>*/
|
4460 |
|
4461 |
|
4462 | var Buffer = require('buffer').Buffer;
|
4463 |
|
4464 | var OurUint8Array = global.Uint8Array || function () {};
|
4465 |
|
4466 | function _uint8ArrayToBuffer(chunk) {
|
4467 | return Buffer.from(chunk);
|
4468 | }
|
4469 |
|
4470 | function _isUint8Array(obj) {
|
4471 | return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
|
4472 | }
|
4473 | /*<replacement>*/
|
4474 |
|
4475 |
|
4476 | var debugUtil = require('util');
|
4477 |
|
4478 | var debug;
|
4479 |
|
4480 | if (debugUtil && debugUtil.debuglog) {
|
4481 | debug = debugUtil.debuglog('stream');
|
4482 | } else {
|
4483 | debug = function debug() {};
|
4484 | }
|
4485 | /*</replacement>*/
|
4486 |
|
4487 |
|
4488 | var BufferList = require('./internal/streams/buffer_list');
|
4489 |
|
4490 | var destroyImpl = require('./internal/streams/destroy');
|
4491 |
|
4492 | var _require = require('./internal/streams/state'),
|
4493 | getHighWaterMark = _require.getHighWaterMark;
|
4494 |
|
4495 | var _require$codes = require('../errors').codes,
|
4496 | ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
|
4497 | ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF,
|
4498 | ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
|
4499 | ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT; // Lazy loaded to improve the startup performance.
|
4500 |
|
4501 |
|
4502 | var StringDecoder;
|
4503 | var createReadableStreamAsyncIterator;
|
4504 | var from;
|
4505 |
|
4506 | require('inherits')(Readable, Stream);
|
4507 |
|
4508 | var errorOrDestroy = destroyImpl.errorOrDestroy;
|
4509 | var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
|
4510 |
|
4511 | function prependListener(emitter, event, fn) {
|
4512 | // Sadly this is not cacheable as some libraries bundle their own
|
4513 | // event emitter implementation with them.
|
4514 | if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn); // This is a hack to make sure that our error handler is attached before any
|
4515 | // userland ones. NEVER DO THIS. This is here only because this code needs
|
4516 | // to continue to work with older versions of Node.js that do not include
|
4517 | // the prependListener() method. The goal is to eventually remove this hack.
|
4518 |
|
4519 | if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (Array.isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
|
4520 | }
|
4521 |
|
4522 | function ReadableState(options, stream, isDuplex) {
|
4523 | Duplex = Duplex || require('./_stream_duplex');
|
4524 | options = options || {}; // Duplex streams are both readable and writable, but share
|
4525 | // the same options object.
|
4526 | // However, some cases require setting options to different
|
4527 | // values for the readable and the writable sides of the duplex stream.
|
4528 | // These options can be provided separately as readableXXX and writableXXX.
|
4529 |
|
4530 | if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; // object stream flag. Used to make read(n) ignore n and to
|
4531 | // make all the buffer merging and length checks go away
|
4532 |
|
4533 | this.objectMode = !!options.objectMode;
|
4534 | if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode; // the point at which it stops calling _read() to fill the buffer
|
4535 | // Note: 0 is a valid value, means "don't call _read preemptively ever"
|
4536 |
|
4537 | this.highWaterMark = getHighWaterMark(this, options, 'readableHighWaterMark', isDuplex); // A linked list is used to store data chunks instead of an array because the
|
4538 | // linked list can remove elements from the beginning faster than
|
4539 | // array.shift()
|
4540 |
|
4541 | this.buffer = new BufferList();
|
4542 | this.length = 0;
|
4543 | this.pipes = null;
|
4544 | this.pipesCount = 0;
|
4545 | this.flowing = null;
|
4546 | this.ended = false;
|
4547 | this.endEmitted = false;
|
4548 | this.reading = false; // a flag to be able to tell if the event 'readable'/'data' is emitted
|
4549 | // immediately, or on a later tick. We set this to true at first, because
|
4550 | // any actions that shouldn't happen until "later" should generally also
|
4551 | // not happen before the first read call.
|
4552 |
|
4553 | this.sync = true; // whenever we return null, then we set a flag to say
|
4554 | // that we're awaiting a 'readable' event emission.
|
4555 |
|
4556 | this.needReadable = false;
|
4557 | this.emittedReadable = false;
|
4558 | this.readableListening = false;
|
4559 | this.resumeScheduled = false;
|
4560 | this.paused = true; // Should close be emitted on destroy. Defaults to true.
|
4561 |
|
4562 | this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'end' (and potentially 'finish')
|
4563 |
|
4564 | this.autoDestroy = !!options.autoDestroy; // has it been destroyed
|
4565 |
|
4566 | this.destroyed = false; // Crypto is kind of old and crusty. Historically, its default string
|
4567 | // encoding is 'binary' so we have to make this configurable.
|
4568 | // Everything else in the universe uses 'utf8', though.
|
4569 |
|
4570 | this.defaultEncoding = options.defaultEncoding || 'utf8'; // the number of writers that are awaiting a drain event in .pipe()s
|
4571 |
|
4572 | this.awaitDrain = 0; // if true, a maybeReadMore has been scheduled
|
4573 |
|
4574 | this.readingMore = false;
|
4575 | this.decoder = null;
|
4576 | this.encoding = null;
|
4577 |
|
4578 | if (options.encoding) {
|
4579 | if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
|
4580 | this.decoder = new StringDecoder(options.encoding);
|
4581 | this.encoding = options.encoding;
|
4582 | }
|
4583 | }
|
4584 |
|
4585 | function Readable(options) {
|
4586 | Duplex = Duplex || require('./_stream_duplex');
|
4587 | if (!(this instanceof Readable)) return new Readable(options); // Checking for a Stream.Duplex instance is faster here instead of inside
|
4588 | // the ReadableState constructor, at least with V8 6.5
|
4589 |
|
4590 | var isDuplex = this instanceof Duplex;
|
4591 | this._readableState = new ReadableState(options, this, isDuplex); // legacy
|
4592 |
|
4593 | this.readable = true;
|
4594 |
|
4595 | if (options) {
|
4596 | if (typeof options.read === 'function') this._read = options.read;
|
4597 | if (typeof options.destroy === 'function') this._destroy = options.destroy;
|
4598 | }
|
4599 |
|
4600 | Stream.call(this);
|
4601 | }
|
4602 |
|
4603 | Object.defineProperty(Readable.prototype, 'destroyed', {
|
4604 | // making it explicit this property is not enumerable
|
4605 | // because otherwise some prototype manipulation in
|
4606 | // userland will fail
|
4607 | enumerable: false,
|
4608 | get: function get() {
|
4609 | if (this._readableState === undefined) {
|
4610 | return false;
|
4611 | }
|
4612 |
|
4613 | return this._readableState.destroyed;
|
4614 | },
|
4615 | set: function set(value) {
|
4616 | // we ignore the value if the stream
|
4617 | // has not been initialized yet
|
4618 | if (!this._readableState) {
|
4619 | return;
|
4620 | } // backward compatibility, the user is explicitly
|
4621 | // managing destroyed
|
4622 |
|
4623 |
|
4624 | this._readableState.destroyed = value;
|
4625 | }
|
4626 | });
|
4627 | Readable.prototype.destroy = destroyImpl.destroy;
|
4628 | Readable.prototype._undestroy = destroyImpl.undestroy;
|
4629 |
|
4630 | Readable.prototype._destroy = function (err, cb) {
|
4631 | cb(err);
|
4632 | }; // Manually shove something into the read() buffer.
|
4633 | // This returns true if the highWaterMark has not been hit yet,
|
4634 | // similar to how Writable.write() returns true if you should
|
4635 | // write() some more.
|
4636 |
|
4637 |
|
4638 | Readable.prototype.push = function (chunk, encoding) {
|
4639 | var state = this._readableState;
|
4640 | var skipChunkCheck;
|
4641 |
|
4642 | if (!state.objectMode) {
|
4643 | if (typeof chunk === 'string') {
|
4644 | encoding = encoding || state.defaultEncoding;
|
4645 |
|
4646 | if (encoding !== state.encoding) {
|
4647 | chunk = Buffer.from(chunk, encoding);
|
4648 | encoding = '';
|
4649 | }
|
4650 |
|
4651 | skipChunkCheck = true;
|
4652 | }
|
4653 | } else {
|
4654 | skipChunkCheck = true;
|
4655 | }
|
4656 |
|
4657 | return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
|
4658 | }; // Unshift should *always* be something directly out of read()
|
4659 |
|
4660 |
|
4661 | Readable.prototype.unshift = function (chunk) {
|
4662 | return readableAddChunk(this, chunk, null, true, false);
|
4663 | };
|
4664 |
|
4665 | function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
|
4666 | debug('readableAddChunk', chunk);
|
4667 | var state = stream._readableState;
|
4668 |
|
4669 | if (chunk === null) {
|
4670 | state.reading = false;
|
4671 | onEofChunk(stream, state);
|
4672 | } else {
|
4673 | var er;
|
4674 | if (!skipChunkCheck) er = chunkInvalid(state, chunk);
|
4675 |
|
4676 | if (er) {
|
4677 | errorOrDestroy(stream, er);
|
4678 | } else if (state.objectMode || chunk && chunk.length > 0) {
|
4679 | if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
|
4680 | chunk = _uint8ArrayToBuffer(chunk);
|
4681 | }
|
4682 |
|
4683 | if (addToFront) {
|
4684 | if (state.endEmitted) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else addChunk(stream, state, chunk, true);
|
4685 | } else if (state.ended) {
|
4686 | errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF());
|
4687 | } else if (state.destroyed) {
|
4688 | return false;
|
4689 | } else {
|
4690 | state.reading = false;
|
4691 |
|
4692 | if (state.decoder && !encoding) {
|
4693 | chunk = state.decoder.write(chunk);
|
4694 | if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
|
4695 | } else {
|
4696 | addChunk(stream, state, chunk, false);
|
4697 | }
|
4698 | }
|
4699 | } else if (!addToFront) {
|
4700 | state.reading = false;
|
4701 | maybeReadMore(stream, state);
|
4702 | }
|
4703 | } // We can push more data if we are below the highWaterMark.
|
4704 | // Also, if we have no data yet, we can stand some more bytes.
|
4705 | // This is to work around cases where hwm=0, such as the repl.
|
4706 |
|
4707 |
|
4708 | return !state.ended && (state.length < state.highWaterMark || state.length === 0);
|
4709 | }
|
4710 |
|
4711 | function addChunk(stream, state, chunk, addToFront) {
|
4712 | if (state.flowing && state.length === 0 && !state.sync) {
|
4713 | state.awaitDrain = 0;
|
4714 | stream.emit('data', chunk);
|
4715 | } else {
|
4716 | // update the buffer info.
|
4717 | state.length += state.objectMode ? 1 : chunk.length;
|
4718 | if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
|
4719 | if (state.needReadable) emitReadable(stream);
|
4720 | }
|
4721 |
|
4722 | maybeReadMore(stream, state);
|
4723 | }
|
4724 |
|
4725 | function chunkInvalid(state, chunk) {
|
4726 | var er;
|
4727 |
|
4728 | if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
|
4729 | er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer', 'Uint8Array'], chunk);
|
4730 | }
|
4731 |
|
4732 | return er;
|
4733 | }
|
4734 |
|
4735 | Readable.prototype.isPaused = function () {
|
4736 | return this._readableState.flowing === false;
|
4737 | }; // backwards compatibility.
|
4738 |
|
4739 |
|
4740 | Readable.prototype.setEncoding = function (enc) {
|
4741 | if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
|
4742 | var decoder = new StringDecoder(enc);
|
4743 | this._readableState.decoder = decoder; // If setEncoding(null), decoder.encoding equals utf8
|
4744 |
|
4745 | this._readableState.encoding = this._readableState.decoder.encoding; // Iterate over current buffer to convert already stored Buffers:
|
4746 |
|
4747 | var p = this._readableState.buffer.head;
|
4748 | var content = '';
|
4749 |
|
4750 | while (p !== null) {
|
4751 | content += decoder.write(p.data);
|
4752 | p = p.next;
|
4753 | }
|
4754 |
|
4755 | this._readableState.buffer.clear();
|
4756 |
|
4757 | if (content !== '') this._readableState.buffer.push(content);
|
4758 | this._readableState.length = content.length;
|
4759 | return this;
|
4760 | }; // Don't raise the hwm > 1GB
|
4761 |
|
4762 |
|
4763 | var MAX_HWM = 0x40000000;
|
4764 |
|
4765 | function computeNewHighWaterMark(n) {
|
4766 | if (n >= MAX_HWM) {
|
4767 | // TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE.
|
4768 | n = MAX_HWM;
|
4769 | } else {
|
4770 | // Get the next highest power of 2 to prevent increasing hwm excessively in
|
4771 | // tiny amounts
|
4772 | n--;
|
4773 | n |= n >>> 1;
|
4774 | n |= n >>> 2;
|
4775 | n |= n >>> 4;
|
4776 | n |= n >>> 8;
|
4777 | n |= n >>> 16;
|
4778 | n++;
|
4779 | }
|
4780 |
|
4781 | return n;
|
4782 | } // This function is designed to be inlinable, so please take care when making
|
4783 | // changes to the function body.
|
4784 |
|
4785 |
|
4786 | function howMuchToRead(n, state) {
|
4787 | if (n <= 0 || state.length === 0 && state.ended) return 0;
|
4788 | if (state.objectMode) return 1;
|
4789 |
|
4790 | if (n !== n) {
|
4791 | // Only flow one buffer at a time
|
4792 | if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
|
4793 | } // If we're asking for more than the current hwm, then raise the hwm.
|
4794 |
|
4795 |
|
4796 | if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
|
4797 | if (n <= state.length) return n; // Don't have enough
|
4798 |
|
4799 | if (!state.ended) {
|
4800 | state.needReadable = true;
|
4801 | return 0;
|
4802 | }
|
4803 |
|
4804 | return state.length;
|
4805 | } // you can override either this method, or the async _read(n) below.
|
4806 |
|
4807 |
|
4808 | Readable.prototype.read = function (n) {
|
4809 | debug('read', n);
|
4810 | n = parseInt(n, 10);
|
4811 | var state = this._readableState;
|
4812 | var nOrig = n;
|
4813 | if (n !== 0) state.emittedReadable = false; // if we're doing read(0) to trigger a readable event, but we
|
4814 | // already have a bunch of data in the buffer, then just trigger
|
4815 | // the 'readable' event and move on.
|
4816 |
|
4817 | if (n === 0 && state.needReadable && ((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)) {
|
4818 | debug('read: emitReadable', state.length, state.ended);
|
4819 | if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
|
4820 | return null;
|
4821 | }
|
4822 |
|
4823 | n = howMuchToRead(n, state); // if we've ended, and we're now clear, then finish it up.
|
4824 |
|
4825 | if (n === 0 && state.ended) {
|
4826 | if (state.length === 0) endReadable(this);
|
4827 | return null;
|
4828 | } // All the actual chunk generation logic needs to be
|
4829 | // *below* the call to _read. The reason is that in certain
|
4830 | // synthetic stream cases, such as passthrough streams, _read
|
4831 | // may be a completely synchronous operation which may change
|
4832 | // the state of the read buffer, providing enough data when
|
4833 | // before there was *not* enough.
|
4834 | //
|
4835 | // So, the steps are:
|
4836 | // 1. Figure out what the state of things will be after we do
|
4837 | // a read from the buffer.
|
4838 | //
|
4839 | // 2. If that resulting state will trigger a _read, then call _read.
|
4840 | // Note that this may be asynchronous, or synchronous. Yes, it is
|
4841 | // deeply ugly to write APIs this way, but that still doesn't mean
|
4842 | // that the Readable class should behave improperly, as streams are
|
4843 | // designed to be sync/async agnostic.
|
4844 | // Take note if the _read call is sync or async (ie, if the read call
|
4845 | // has returned yet), so that we know whether or not it's safe to emit
|
4846 | // 'readable' etc.
|
4847 | //
|
4848 | // 3. Actually pull the requested chunks out of the buffer and return.
|
4849 | // if we need a readable event, then we need to do some reading.
|
4850 |
|
4851 |
|
4852 | var doRead = state.needReadable;
|
4853 | debug('need readable', doRead); // if we currently have less than the highWaterMark, then also read some
|
4854 |
|
4855 | if (state.length === 0 || state.length - n < state.highWaterMark) {
|
4856 | doRead = true;
|
4857 | debug('length less than watermark', doRead);
|
4858 | } // however, if we've ended, then there's no point, and if we're already
|
4859 | // reading, then it's unnecessary.
|
4860 |
|
4861 |
|
4862 | if (state.ended || state.reading) {
|
4863 | doRead = false;
|
4864 | debug('reading or ended', doRead);
|
4865 | } else if (doRead) {
|
4866 | debug('do read');
|
4867 | state.reading = true;
|
4868 | state.sync = true; // if the length is currently zero, then we *need* a readable event.
|
4869 |
|
4870 | if (state.length === 0) state.needReadable = true; // call internal read method
|
4871 |
|
4872 | this._read(state.highWaterMark);
|
4873 |
|
4874 | state.sync = false; // If _read pushed data synchronously, then `reading` will be false,
|
4875 | // and we need to re-evaluate how much data we can return to the user.
|
4876 |
|
4877 | if (!state.reading) n = howMuchToRead(nOrig, state);
|
4878 | }
|
4879 |
|
4880 | var ret;
|
4881 | if (n > 0) ret = fromList(n, state);else ret = null;
|
4882 |
|
4883 | if (ret === null) {
|
4884 | state.needReadable = state.length <= state.highWaterMark;
|
4885 | n = 0;
|
4886 | } else {
|
4887 | state.length -= n;
|
4888 | state.awaitDrain = 0;
|
4889 | }
|
4890 |
|
4891 | if (state.length === 0) {
|
4892 | // If we have nothing in the buffer, then we want to know
|
4893 | // as soon as we *do* get something into the buffer.
|
4894 | if (!state.ended) state.needReadable = true; // If we tried to read() past the EOF, then emit end on the next tick.
|
4895 |
|
4896 | if (nOrig !== n && state.ended) endReadable(this);
|
4897 | }
|
4898 |
|
4899 | if (ret !== null) this.emit('data', ret);
|
4900 | return ret;
|
4901 | };
|
4902 |
|
4903 | function onEofChunk(stream, state) {
|
4904 | debug('onEofChunk');
|
4905 | if (state.ended) return;
|
4906 |
|
4907 | if (state.decoder) {
|
4908 | var chunk = state.decoder.end();
|
4909 |
|
4910 | if (chunk && chunk.length) {
|
4911 | state.buffer.push(chunk);
|
4912 | state.length += state.objectMode ? 1 : chunk.length;
|
4913 | }
|
4914 | }
|
4915 |
|
4916 | state.ended = true;
|
4917 |
|
4918 | if (state.sync) {
|
4919 | // if we are sync, wait until next tick to emit the data.
|
4920 | // Otherwise we risk emitting data in the flow()
|
4921 | // the readable code triggers during a read() call
|
4922 | emitReadable(stream);
|
4923 | } else {
|
4924 | // emit 'readable' now to make sure it gets picked up.
|
4925 | state.needReadable = false;
|
4926 |
|
4927 | if (!state.emittedReadable) {
|
4928 | state.emittedReadable = true;
|
4929 | emitReadable_(stream);
|
4930 | }
|
4931 | }
|
4932 | } // Don't emit readable right away in sync mode, because this can trigger
|
4933 | // another read() call => stack overflow. This way, it might trigger
|
4934 | // a nextTick recursion warning, but that's not so bad.
|
4935 |
|
4936 |
|
4937 | function emitReadable(stream) {
|
4938 | var state = stream._readableState;
|
4939 | debug('emitReadable', state.needReadable, state.emittedReadable);
|
4940 | state.needReadable = false;
|
4941 |
|
4942 | if (!state.emittedReadable) {
|
4943 | debug('emitReadable', state.flowing);
|
4944 | state.emittedReadable = true;
|
4945 | process.nextTick(emitReadable_, stream);
|
4946 | }
|
4947 | }
|
4948 |
|
4949 | function emitReadable_(stream) {
|
4950 | var state = stream._readableState;
|
4951 | debug('emitReadable_', state.destroyed, state.length, state.ended);
|
4952 |
|
4953 | if (!state.destroyed && (state.length || state.ended)) {
|
4954 | stream.emit('readable');
|
4955 | state.emittedReadable = false;
|
4956 | } // The stream needs another readable event if
|
4957 | // 1. It is not flowing, as the flow mechanism will take
|
4958 | // care of it.
|
4959 | // 2. It is not ended.
|
4960 | // 3. It is below the highWaterMark, so we can schedule
|
4961 | // another readable later.
|
4962 |
|
4963 |
|
4964 | state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark;
|
4965 | flow(stream);
|
4966 | } // at this point, the user has presumably seen the 'readable' event,
|
4967 | // and called read() to consume some data. that may have triggered
|
4968 | // in turn another _read(n) call, in which case reading = true if
|
4969 | // it's in progress.
|
4970 | // However, if we're not ended, or reading, and the length < hwm,
|
4971 | // then go ahead and try to read some more preemptively.
|
4972 |
|
4973 |
|
4974 | function maybeReadMore(stream, state) {
|
4975 | if (!state.readingMore) {
|
4976 | state.readingMore = true;
|
4977 | process.nextTick(maybeReadMore_, stream, state);
|
4978 | }
|
4979 | }
|
4980 |
|
4981 | function maybeReadMore_(stream, state) {
|
4982 | // Attempt to read more data if we should.
|
4983 | //
|
4984 | // The conditions for reading more data are (one of):
|
4985 | // - Not enough data buffered (state.length < state.highWaterMark). The loop
|
4986 | // is responsible for filling the buffer with enough data if such data
|
4987 | // is available. If highWaterMark is 0 and we are not in the flowing mode
|
4988 | // we should _not_ attempt to buffer any extra data. We'll get more data
|
4989 | // when the stream consumer calls read() instead.
|
4990 | // - No data in the buffer, and the stream is in flowing mode. In this mode
|
4991 | // the loop below is responsible for ensuring read() is called. Failing to
|
4992 | // call read here would abort the flow and there's no other mechanism for
|
4993 | // continuing the flow if the stream consumer has just subscribed to the
|
4994 | // 'data' event.
|
4995 | //
|
4996 | // In addition to the above conditions to keep reading data, the following
|
4997 | // conditions prevent the data from being read:
|
4998 | // - The stream has ended (state.ended).
|
4999 | // - There is already a pending 'read' operation (state.reading). This is a
|
5000 | // case where the the stream has called the implementation defined _read()
|
5001 | // method, but they are processing the call asynchronously and have _not_
|
5002 | // called push() with new data. In this case we skip performing more
|
5003 | // read()s. The execution ends in this method again after the _read() ends
|
5004 | // up calling push() with more data.
|
5005 | while (!state.reading && !state.ended && (state.length < state.highWaterMark || state.flowing && state.length === 0)) {
|
5006 | var len = state.length;
|
5007 | debug('maybeReadMore read 0');
|
5008 | stream.read(0);
|
5009 | if (len === state.length) // didn't get any data, stop spinning.
|
5010 | break;
|
5011 | }
|
5012 |
|
5013 | state.readingMore = false;
|
5014 | } // abstract method. to be overridden in specific implementation classes.
|
5015 | // call cb(er, data) where data is <= n in length.
|
5016 | // for virtual (non-string, non-buffer) streams, "length" is somewhat
|
5017 | // arbitrary, and perhaps not very meaningful.
|
5018 |
|
5019 |
|
5020 | Readable.prototype._read = function (n) {
|
5021 | errorOrDestroy(this, new ERR_METHOD_NOT_IMPLEMENTED('_read()'));
|
5022 | };
|
5023 |
|
5024 | Readable.prototype.pipe = function (dest, pipeOpts) {
|
5025 | var src = this;
|
5026 | var state = this._readableState;
|
5027 |
|
5028 | switch (state.pipesCount) {
|
5029 | case 0:
|
5030 | state.pipes = dest;
|
5031 | break;
|
5032 |
|
5033 | case 1:
|
5034 | state.pipes = [state.pipes, dest];
|
5035 | break;
|
5036 |
|
5037 | default:
|
5038 | state.pipes.push(dest);
|
5039 | break;
|
5040 | }
|
5041 |
|
5042 | state.pipesCount += 1;
|
5043 | debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
|
5044 | var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
|
5045 | var endFn = doEnd ? onend : unpipe;
|
5046 | if (state.endEmitted) process.nextTick(endFn);else src.once('end', endFn);
|
5047 | dest.on('unpipe', onunpipe);
|
5048 |
|
5049 | function onunpipe(readable, unpipeInfo) {
|
5050 | debug('onunpipe');
|
5051 |
|
5052 | if (readable === src) {
|
5053 | if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
|
5054 | unpipeInfo.hasUnpiped = true;
|
5055 | cleanup();
|
5056 | }
|
5057 | }
|
5058 | }
|
5059 |
|
5060 | function onend() {
|
5061 | debug('onend');
|
5062 | dest.end();
|
5063 | } // when the dest drains, it reduces the awaitDrain counter
|
5064 | // on the source. This would be more elegant with a .once()
|
5065 | // handler in flow(), but adding and removing repeatedly is
|
5066 | // too slow.
|
5067 |
|
5068 |
|
5069 | var ondrain = pipeOnDrain(src);
|
5070 | dest.on('drain', ondrain);
|
5071 | var cleanedUp = false;
|
5072 |
|
5073 | function cleanup() {
|
5074 | debug('cleanup'); // cleanup event handlers once the pipe is broken
|
5075 |
|
5076 | dest.removeListener('close', onclose);
|
5077 | dest.removeListener('finish', onfinish);
|
5078 | dest.removeListener('drain', ondrain);
|
5079 | dest.removeListener('error', onerror);
|
5080 | dest.removeListener('unpipe', onunpipe);
|
5081 | src.removeListener('end', onend);
|
5082 | src.removeListener('end', unpipe);
|
5083 | src.removeListener('data', ondata);
|
5084 | cleanedUp = true; // if the reader is waiting for a drain event from this
|
5085 | // specific writer, then it would cause it to never start
|
5086 | // flowing again.
|
5087 | // So, if this is awaiting a drain, then we just call it now.
|
5088 | // If we don't know, then assume that we are waiting for one.
|
5089 |
|
5090 | if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
|
5091 | }
|
5092 |
|
5093 | src.on('data', ondata);
|
5094 |
|
5095 | function ondata(chunk) {
|
5096 | debug('ondata');
|
5097 | var ret = dest.write(chunk);
|
5098 | debug('dest.write', ret);
|
5099 |
|
5100 | if (ret === false) {
|
5101 | // If the user unpiped during `dest.write()`, it is possible
|
5102 | // to get stuck in a permanently paused state if that write
|
5103 | // also returned false.
|
5104 | // => Check whether `dest` is still a piping destination.
|
5105 | if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
|
5106 | debug('false write response, pause', state.awaitDrain);
|
5107 | state.awaitDrain++;
|
5108 | }
|
5109 |
|
5110 | src.pause();
|
5111 | }
|
5112 | } // if the dest has an error, then stop piping into it.
|
5113 | // however, don't suppress the throwing behavior for this.
|
5114 |
|
5115 |
|
5116 | function onerror(er) {
|
5117 | debug('onerror', er);
|
5118 | unpipe();
|
5119 | dest.removeListener('error', onerror);
|
5120 | if (EElistenerCount(dest, 'error') === 0) errorOrDestroy(dest, er);
|
5121 | } // Make sure our error handler is attached before userland ones.
|
5122 |
|
5123 |
|
5124 | prependListener(dest, 'error', onerror); // Both close and finish should trigger unpipe, but only once.
|
5125 |
|
5126 | function onclose() {
|
5127 | dest.removeListener('finish', onfinish);
|
5128 | unpipe();
|
5129 | }
|
5130 |
|
5131 | dest.once('close', onclose);
|
5132 |
|
5133 | function onfinish() {
|
5134 | debug('onfinish');
|
5135 | dest.removeListener('close', onclose);
|
5136 | unpipe();
|
5137 | }
|
5138 |
|
5139 | dest.once('finish', onfinish);
|
5140 |
|
5141 | function unpipe() {
|
5142 | debug('unpipe');
|
5143 | src.unpipe(dest);
|
5144 | } // tell the dest that it's being piped to
|
5145 |
|
5146 |
|
5147 | dest.emit('pipe', src); // start the flow if it hasn't been started already.
|
5148 |
|
5149 | if (!state.flowing) {
|
5150 | debug('pipe resume');
|
5151 | src.resume();
|
5152 | }
|
5153 |
|
5154 | return dest;
|
5155 | };
|
5156 |
|
5157 | function pipeOnDrain(src) {
|
5158 | return function pipeOnDrainFunctionResult() {
|
5159 | var state = src._readableState;
|
5160 | debug('pipeOnDrain', state.awaitDrain);
|
5161 | if (state.awaitDrain) state.awaitDrain--;
|
5162 |
|
5163 | if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
|
5164 | state.flowing = true;
|
5165 | flow(src);
|
5166 | }
|
5167 | };
|
5168 | }
|
5169 |
|
5170 | Readable.prototype.unpipe = function (dest) {
|
5171 | var state = this._readableState;
|
5172 | var unpipeInfo = {
|
5173 | hasUnpiped: false
|
5174 | }; // if we're not piping anywhere, then do nothing.
|
5175 |
|
5176 | if (state.pipesCount === 0) return this; // just one destination. most common case.
|
5177 |
|
5178 | if (state.pipesCount === 1) {
|
5179 | // passed in one, but it's not the right one.
|
5180 | if (dest && dest !== state.pipes) return this;
|
5181 | if (!dest) dest = state.pipes; // got a match.
|
5182 |
|
5183 | state.pipes = null;
|
5184 | state.pipesCount = 0;
|
5185 | state.flowing = false;
|
5186 | if (dest) dest.emit('unpipe', this, unpipeInfo);
|
5187 | return this;
|
5188 | } // slow case. multiple pipe destinations.
|
5189 |
|
5190 |
|
5191 | if (!dest) {
|
5192 | // remove all.
|
5193 | var dests = state.pipes;
|
5194 | var len = state.pipesCount;
|
5195 | state.pipes = null;
|
5196 | state.pipesCount = 0;
|
5197 | state.flowing = false;
|
5198 |
|
5199 | for (var i = 0; i < len; i++) {
|
5200 | dests[i].emit('unpipe', this, {
|
5201 | hasUnpiped: false
|
5202 | });
|
5203 | }
|
5204 |
|
5205 | return this;
|
5206 | } // try to find the right one.
|
5207 |
|
5208 |
|
5209 | var index = indexOf(state.pipes, dest);
|
5210 | if (index === -1) return this;
|
5211 | state.pipes.splice(index, 1);
|
5212 | state.pipesCount -= 1;
|
5213 | if (state.pipesCount === 1) state.pipes = state.pipes[0];
|
5214 | dest.emit('unpipe', this, unpipeInfo);
|
5215 | return this;
|
5216 | }; // set up data events if they are asked for
|
5217 | // Ensure readable listeners eventually get something
|
5218 |
|
5219 |
|
5220 | Readable.prototype.on = function (ev, fn) {
|
5221 | var res = Stream.prototype.on.call(this, ev, fn);
|
5222 | var state = this._readableState;
|
5223 |
|
5224 | if (ev === 'data') {
|
5225 | // update readableListening so that resume() may be a no-op
|
5226 | // a few lines down. This is needed to support once('readable').
|
5227 | state.readableListening = this.listenerCount('readable') > 0; // Try start flowing on next tick if stream isn't explicitly paused
|
5228 |
|
5229 | if (state.flowing !== false) this.resume();
|
5230 | } else if (ev === 'readable') {
|
5231 | if (!state.endEmitted && !state.readableListening) {
|
5232 | state.readableListening = state.needReadable = true;
|
5233 | state.flowing = false;
|
5234 | state.emittedReadable = false;
|
5235 | debug('on readable', state.length, state.reading);
|
5236 |
|
5237 | if (state.length) {
|
5238 | emitReadable(this);
|
5239 | } else if (!state.reading) {
|
5240 | process.nextTick(nReadingNextTick, this);
|
5241 | }
|
5242 | }
|
5243 | }
|
5244 |
|
5245 | return res;
|
5246 | };
|
5247 |
|
5248 | Readable.prototype.addListener = Readable.prototype.on;
|
5249 |
|
5250 | Readable.prototype.removeListener = function (ev, fn) {
|
5251 | var res = Stream.prototype.removeListener.call(this, ev, fn);
|
5252 |
|
5253 | if (ev === 'readable') {
|
5254 | // We need to check if there is someone still listening to
|
5255 | // readable and reset the state. However this needs to happen
|
5256 | // after readable has been emitted but before I/O (nextTick) to
|
5257 | // support once('readable', fn) cycles. This means that calling
|
5258 | // resume within the same tick will have no
|
5259 | // effect.
|
5260 | process.nextTick(updateReadableListening, this);
|
5261 | }
|
5262 |
|
5263 | return res;
|
5264 | };
|
5265 |
|
5266 | Readable.prototype.removeAllListeners = function (ev) {
|
5267 | var res = Stream.prototype.removeAllListeners.apply(this, arguments);
|
5268 |
|
5269 | if (ev === 'readable' || ev === undefined) {
|
5270 | // We need to check if there is someone still listening to
|
5271 | // readable and reset the state. However this needs to happen
|
5272 | // after readable has been emitted but before I/O (nextTick) to
|
5273 | // support once('readable', fn) cycles. This means that calling
|
5274 | // resume within the same tick will have no
|
5275 | // effect.
|
5276 | process.nextTick(updateReadableListening, this);
|
5277 | }
|
5278 |
|
5279 | return res;
|
5280 | };
|
5281 |
|
5282 | function updateReadableListening(self) {
|
5283 | var state = self._readableState;
|
5284 | state.readableListening = self.listenerCount('readable') > 0;
|
5285 |
|
5286 | if (state.resumeScheduled && !state.paused) {
|
5287 | // flowing needs to be set to true now, otherwise
|
5288 | // the upcoming resume will not flow.
|
5289 | state.flowing = true; // crude way to check if we should resume
|
5290 | } else if (self.listenerCount('data') > 0) {
|
5291 | self.resume();
|
5292 | }
|
5293 | }
|
5294 |
|
5295 | function nReadingNextTick(self) {
|
5296 | debug('readable nexttick read 0');
|
5297 | self.read(0);
|
5298 | } // pause() and resume() are remnants of the legacy readable stream API
|
5299 | // If the user uses them, then switch into old mode.
|
5300 |
|
5301 |
|
5302 | Readable.prototype.resume = function () {
|
5303 | var state = this._readableState;
|
5304 |
|
5305 | if (!state.flowing) {
|
5306 | debug('resume'); // we flow only if there is no one listening
|
5307 | // for readable, but we still have to call
|
5308 | // resume()
|
5309 |
|
5310 | state.flowing = !state.readableListening;
|
5311 | resume(this, state);
|
5312 | }
|
5313 |
|
5314 | state.paused = false;
|
5315 | return this;
|
5316 | };
|
5317 |
|
5318 | function resume(stream, state) {
|
5319 | if (!state.resumeScheduled) {
|
5320 | state.resumeScheduled = true;
|
5321 | process.nextTick(resume_, stream, state);
|
5322 | }
|
5323 | }
|
5324 |
|
5325 | function resume_(stream, state) {
|
5326 | debug('resume', state.reading);
|
5327 |
|
5328 | if (!state.reading) {
|
5329 | stream.read(0);
|
5330 | }
|
5331 |
|
5332 | state.resumeScheduled = false;
|
5333 | stream.emit('resume');
|
5334 | flow(stream);
|
5335 | if (state.flowing && !state.reading) stream.read(0);
|
5336 | }
|
5337 |
|
5338 | Readable.prototype.pause = function () {
|
5339 | debug('call pause flowing=%j', this._readableState.flowing);
|
5340 |
|
5341 | if (this._readableState.flowing !== false) {
|
5342 | debug('pause');
|
5343 | this._readableState.flowing = false;
|
5344 | this.emit('pause');
|
5345 | }
|
5346 |
|
5347 | this._readableState.paused = true;
|
5348 | return this;
|
5349 | };
|
5350 |
|
5351 | function flow(stream) {
|
5352 | var state = stream._readableState;
|
5353 | debug('flow', state.flowing);
|
5354 |
|
5355 | while (state.flowing && stream.read() !== null) {
|
5356 | ;
|
5357 | }
|
5358 | } // wrap an old-style stream as the async data source.
|
5359 | // This is *not* part of the readable stream interface.
|
5360 | // It is an ugly unfortunate mess of history.
|
5361 |
|
5362 |
|
5363 | Readable.prototype.wrap = function (stream) {
|
5364 | var _this = this;
|
5365 |
|
5366 | var state = this._readableState;
|
5367 | var paused = false;
|
5368 | stream.on('end', function () {
|
5369 | debug('wrapped end');
|
5370 |
|
5371 | if (state.decoder && !state.ended) {
|
5372 | var chunk = state.decoder.end();
|
5373 | if (chunk && chunk.length) _this.push(chunk);
|
5374 | }
|
5375 |
|
5376 | _this.push(null);
|
5377 | });
|
5378 | stream.on('data', function (chunk) {
|
5379 | debug('wrapped data');
|
5380 | if (state.decoder) chunk = state.decoder.write(chunk); // don't skip over falsy values in objectMode
|
5381 |
|
5382 | if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
|
5383 |
|
5384 | var ret = _this.push(chunk);
|
5385 |
|
5386 | if (!ret) {
|
5387 | paused = true;
|
5388 | stream.pause();
|
5389 | }
|
5390 | }); // proxy all the other methods.
|
5391 | // important when wrapping filters and duplexes.
|
5392 |
|
5393 | for (var i in stream) {
|
5394 | if (this[i] === undefined && typeof stream[i] === 'function') {
|
5395 | this[i] = function methodWrap(method) {
|
5396 | return function methodWrapReturnFunction() {
|
5397 | return stream[method].apply(stream, arguments);
|
5398 | };
|
5399 | }(i);
|
5400 | }
|
5401 | } // proxy certain important events.
|
5402 |
|
5403 |
|
5404 | for (var n = 0; n < kProxyEvents.length; n++) {
|
5405 | stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
|
5406 | } // when we try to consume some more bytes, simply unpause the
|
5407 | // underlying stream.
|
5408 |
|
5409 |
|
5410 | this._read = function (n) {
|
5411 | debug('wrapped _read', n);
|
5412 |
|
5413 | if (paused) {
|
5414 | paused = false;
|
5415 | stream.resume();
|
5416 | }
|
5417 | };
|
5418 |
|
5419 | return this;
|
5420 | };
|
5421 |
|
5422 | if (typeof Symbol === 'function') {
|
5423 | Readable.prototype[Symbol.asyncIterator] = function () {
|
5424 | if (createReadableStreamAsyncIterator === undefined) {
|
5425 | createReadableStreamAsyncIterator = require('./internal/streams/async_iterator');
|
5426 | }
|
5427 |
|
5428 | return createReadableStreamAsyncIterator(this);
|
5429 | };
|
5430 | }
|
5431 |
|
5432 | Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
|
5433 | // making it explicit this property is not enumerable
|
5434 | // because otherwise some prototype manipulation in
|
5435 | // userland will fail
|
5436 | enumerable: false,
|
5437 | get: function get() {
|
5438 | return this._readableState.highWaterMark;
|
5439 | }
|
5440 | });
|
5441 | Object.defineProperty(Readable.prototype, 'readableBuffer', {
|
5442 | // making it explicit this property is not enumerable
|
5443 | // because otherwise some prototype manipulation in
|
5444 | // userland will fail
|
5445 | enumerable: false,
|
5446 | get: function get() {
|
5447 | return this._readableState && this._readableState.buffer;
|
5448 | }
|
5449 | });
|
5450 | Object.defineProperty(Readable.prototype, 'readableFlowing', {
|
5451 | // making it explicit this property is not enumerable
|
5452 | // because otherwise some prototype manipulation in
|
5453 | // userland will fail
|
5454 | enumerable: false,
|
5455 | get: function get() {
|
5456 | return this._readableState.flowing;
|
5457 | },
|
5458 | set: function set(state) {
|
5459 | if (this._readableState) {
|
5460 | this._readableState.flowing = state;
|
5461 | }
|
5462 | }
|
5463 | }); // exposed for testing purposes only.
|
5464 |
|
5465 | Readable._fromList = fromList;
|
5466 | Object.defineProperty(Readable.prototype, 'readableLength', {
|
5467 | // making it explicit this property is not enumerable
|
5468 | // because otherwise some prototype manipulation in
|
5469 | // userland will fail
|
5470 | enumerable: false,
|
5471 | get: function get() {
|
5472 | return this._readableState.length;
|
5473 | }
|
5474 | }); // Pluck off n bytes from an array of buffers.
|
5475 | // Length is the combined lengths of all the buffers in the list.
|
5476 | // This function is designed to be inlinable, so please take care when making
|
5477 | // changes to the function body.
|
5478 |
|
5479 | function fromList(n, state) {
|
5480 | // nothing buffered
|
5481 | if (state.length === 0) return null;
|
5482 | var ret;
|
5483 | if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
|
5484 | // read it all, truncate the list
|
5485 | if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.first();else ret = state.buffer.concat(state.length);
|
5486 | state.buffer.clear();
|
5487 | } else {
|
5488 | // read part of list
|
5489 | ret = state.buffer.consume(n, state.decoder);
|
5490 | }
|
5491 | return ret;
|
5492 | }
|
5493 |
|
5494 | function endReadable(stream) {
|
5495 | var state = stream._readableState;
|
5496 | debug('endReadable', state.endEmitted);
|
5497 |
|
5498 | if (!state.endEmitted) {
|
5499 | state.ended = true;
|
5500 | process.nextTick(endReadableNT, state, stream);
|
5501 | }
|
5502 | }
|
5503 |
|
5504 | function endReadableNT(state, stream) {
|
5505 | debug('endReadableNT', state.endEmitted, state.length); // Check that we didn't get one last unshift.
|
5506 |
|
5507 | if (!state.endEmitted && state.length === 0) {
|
5508 | state.endEmitted = true;
|
5509 | stream.readable = false;
|
5510 | stream.emit('end');
|
5511 |
|
5512 | if (state.autoDestroy) {
|
5513 | // In case of duplex streams we need a way to detect
|
5514 | // if the writable side is ready for autoDestroy as well
|
5515 | var wState = stream._writableState;
|
5516 |
|
5517 | if (!wState || wState.autoDestroy && wState.finished) {
|
5518 | stream.destroy();
|
5519 | }
|
5520 | }
|
5521 | }
|
5522 | }
|
5523 |
|
5524 | if (typeof Symbol === 'function') {
|
5525 | Readable.from = function (iterable, opts) {
|
5526 | if (from === undefined) {
|
5527 | from = require('./internal/streams/from');
|
5528 | }
|
5529 |
|
5530 | return from(Readable, iterable, opts);
|
5531 | };
|
5532 | }
|
5533 |
|
5534 | function indexOf(xs, x) {
|
5535 | for (var i = 0, l = xs.length; i < l; i++) {
|
5536 | if (xs[i] === x) return i;
|
5537 | }
|
5538 |
|
5539 | return -1;
|
5540 | }
|
5541 | }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
5542 | },{"../errors":18,"./_stream_duplex":19,"./internal/streams/async_iterator":24,"./internal/streams/buffer_list":25,"./internal/streams/destroy":26,"./internal/streams/from":28,"./internal/streams/state":30,"./internal/streams/stream":31,"_process":11,"buffer":5,"events":7,"inherits":10,"string_decoder/":51,"util":4}],22:[function(require,module,exports){
|
5543 | // Copyright Joyent, Inc. and other Node contributors.
|
5544 | //
|
5545 | // Permission is hereby granted, free of charge, to any person obtaining a
|
5546 | // copy of this software and associated documentation files (the
|
5547 | // "Software"), to deal in the Software without restriction, including
|
5548 | // without limitation the rights to use, copy, modify, merge, publish,
|
5549 | // distribute, sublicense, and/or sell copies of the Software, and to permit
|
5550 | // persons to whom the Software is furnished to do so, subject to the
|
5551 | // following conditions:
|
5552 | //
|
5553 | // The above copyright notice and this permission notice shall be included
|
5554 | // in all copies or substantial portions of the Software.
|
5555 | //
|
5556 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
5557 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
5558 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
5559 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
5560 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
5561 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
5562 | // USE OR OTHER DEALINGS IN THE SOFTWARE.
|
5563 | // a transform stream is a readable/writable stream where you do
|
5564 | // something with the data. Sometimes it's called a "filter",
|
5565 | // but that's not a great name for it, since that implies a thing where
|
5566 | // some bits pass through, and others are simply ignored. (That would
|
5567 | // be a valid example of a transform, of course.)
|
5568 | //
|
5569 | // While the output is causally related to the input, it's not a
|
5570 | // necessarily symmetric or synchronous transformation. For example,
|
5571 | // a zlib stream might take multiple plain-text writes(), and then
|
5572 | // emit a single compressed chunk some time in the future.
|
5573 | //
|
5574 | // Here's how this works:
|
5575 | //
|
5576 | // The Transform stream has all the aspects of the readable and writable
|
5577 | // stream classes. When you write(chunk), that calls _write(chunk,cb)
|
5578 | // internally, and returns false if there's a lot of pending writes
|
5579 | // buffered up. When you call read(), that calls _read(n) until
|
5580 | // there's enough pending readable data buffered up.
|
5581 | //
|
5582 | // In a transform stream, the written data is placed in a buffer. When
|
5583 | // _read(n) is called, it transforms the queued up data, calling the
|
5584 | // buffered _write cb's as it consumes chunks. If consuming a single
|
5585 | // written chunk would result in multiple output chunks, then the first
|
5586 | // outputted bit calls the readcb, and subsequent chunks just go into
|
5587 | // the read buffer, and will cause it to emit 'readable' if necessary.
|
5588 | //
|
5589 | // This way, back-pressure is actually determined by the reading side,
|
5590 | // since _read has to be called to start processing a new chunk. However,
|
5591 | // a pathological inflate type of transform can cause excessive buffering
|
5592 | // here. For example, imagine a stream where every byte of input is
|
5593 | // interpreted as an integer from 0-255, and then results in that many
|
5594 | // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
|
5595 | // 1kb of data being output. In this case, you could write a very small
|
5596 | // amount of input, and end up with a very large amount of output. In
|
5597 | // such a pathological inflating mechanism, there'd be no way to tell
|
5598 | // the system to stop doing the transform. A single 4MB write could
|
5599 | // cause the system to run out of memory.
|
5600 | //
|
5601 | // However, even in such a pathological case, only a single written chunk
|
5602 | // would be consumed, and then the rest would wait (un-transformed) until
|
5603 | // the results of the previous transformed chunk were consumed.
|
5604 | 'use strict';
|
5605 |
|
5606 | module.exports = Transform;
|
5607 |
|
5608 | var _require$codes = require('../errors').codes,
|
5609 | ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
|
5610 | ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
|
5611 | ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING,
|
5612 | ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0;
|
5613 |
|
5614 | var Duplex = require('./_stream_duplex');
|
5615 |
|
5616 | require('inherits')(Transform, Duplex);
|
5617 |
|
5618 | function afterTransform(er, data) {
|
5619 | var ts = this._transformState;
|
5620 | ts.transforming = false;
|
5621 | var cb = ts.writecb;
|
5622 |
|
5623 | if (cb === null) {
|
5624 | return this.emit('error', new ERR_MULTIPLE_CALLBACK());
|
5625 | }
|
5626 |
|
5627 | ts.writechunk = null;
|
5628 | ts.writecb = null;
|
5629 | if (data != null) // single equals check for both `null` and `undefined`
|
5630 | this.push(data);
|
5631 | cb(er);
|
5632 | var rs = this._readableState;
|
5633 | rs.reading = false;
|
5634 |
|
5635 | if (rs.needReadable || rs.length < rs.highWaterMark) {
|
5636 | this._read(rs.highWaterMark);
|
5637 | }
|
5638 | }
|
5639 |
|
5640 | function Transform(options) {
|
5641 | if (!(this instanceof Transform)) return new Transform(options);
|
5642 | Duplex.call(this, options);
|
5643 | this._transformState = {
|
5644 | afterTransform: afterTransform.bind(this),
|
5645 | needTransform: false,
|
5646 | transforming: false,
|
5647 | writecb: null,
|
5648 | writechunk: null,
|
5649 | writeencoding: null
|
5650 | }; // start out asking for a readable event once data is transformed.
|
5651 |
|
5652 | this._readableState.needReadable = true; // we have implemented the _read method, and done the other things
|
5653 | // that Readable wants before the first _read call, so unset the
|
5654 | // sync guard flag.
|
5655 |
|
5656 | this._readableState.sync = false;
|
5657 |
|
5658 | if (options) {
|
5659 | if (typeof options.transform === 'function') this._transform = options.transform;
|
5660 | if (typeof options.flush === 'function') this._flush = options.flush;
|
5661 | } // When the writable side finishes, then flush out anything remaining.
|
5662 |
|
5663 |
|
5664 | this.on('prefinish', prefinish);
|
5665 | }
|
5666 |
|
5667 | function prefinish() {
|
5668 | var _this = this;
|
5669 |
|
5670 | if (typeof this._flush === 'function' && !this._readableState.destroyed) {
|
5671 | this._flush(function (er, data) {
|
5672 | done(_this, er, data);
|
5673 | });
|
5674 | } else {
|
5675 | done(this, null, null);
|
5676 | }
|
5677 | }
|
5678 |
|
5679 | Transform.prototype.push = function (chunk, encoding) {
|
5680 | this._transformState.needTransform = false;
|
5681 | return Duplex.prototype.push.call(this, chunk, encoding);
|
5682 | }; // This is the part where you do stuff!
|
5683 | // override this function in implementation classes.
|
5684 | // 'chunk' is an input chunk.
|
5685 | //
|
5686 | // Call `push(newChunk)` to pass along transformed output
|
5687 | // to the readable side. You may call 'push' zero or more times.
|
5688 | //
|
5689 | // Call `cb(err)` when you are done with this chunk. If you pass
|
5690 | // an error, then that'll put the hurt on the whole operation. If you
|
5691 | // never call cb(), then you'll never get another chunk.
|
5692 |
|
5693 |
|
5694 | Transform.prototype._transform = function (chunk, encoding, cb) {
|
5695 | cb(new ERR_METHOD_NOT_IMPLEMENTED('_transform()'));
|
5696 | };
|
5697 |
|
5698 | Transform.prototype._write = function (chunk, encoding, cb) {
|
5699 | var ts = this._transformState;
|
5700 | ts.writecb = cb;
|
5701 | ts.writechunk = chunk;
|
5702 | ts.writeencoding = encoding;
|
5703 |
|
5704 | if (!ts.transforming) {
|
5705 | var rs = this._readableState;
|
5706 | if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
|
5707 | }
|
5708 | }; // Doesn't matter what the args are here.
|
5709 | // _transform does all the work.
|
5710 | // That we got here means that the readable side wants more data.
|
5711 |
|
5712 |
|
5713 | Transform.prototype._read = function (n) {
|
5714 | var ts = this._transformState;
|
5715 |
|
5716 | if (ts.writechunk !== null && !ts.transforming) {
|
5717 | ts.transforming = true;
|
5718 |
|
5719 | this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
|
5720 | } else {
|
5721 | // mark that we need a transform, so that any data that comes in
|
5722 | // will get processed, now that we've asked for it.
|
5723 | ts.needTransform = true;
|
5724 | }
|
5725 | };
|
5726 |
|
5727 | Transform.prototype._destroy = function (err, cb) {
|
5728 | Duplex.prototype._destroy.call(this, err, function (err2) {
|
5729 | cb(err2);
|
5730 | });
|
5731 | };
|
5732 |
|
5733 | function done(stream, er, data) {
|
5734 | if (er) return stream.emit('error', er);
|
5735 | if (data != null) // single equals check for both `null` and `undefined`
|
5736 | stream.push(data); // TODO(BridgeAR): Write a test for these two error cases
|
5737 | // if there's nothing in the write buffer, then that means
|
5738 | // that nothing more will ever be provided
|
5739 |
|
5740 | if (stream._writableState.length) throw new ERR_TRANSFORM_WITH_LENGTH_0();
|
5741 | if (stream._transformState.transforming) throw new ERR_TRANSFORM_ALREADY_TRANSFORMING();
|
5742 | return stream.push(null);
|
5743 | }
|
5744 | },{"../errors":18,"./_stream_duplex":19,"inherits":10}],23:[function(require,module,exports){
|
5745 | (function (process,global){(function (){
|
5746 | // Copyright Joyent, Inc. and other Node contributors.
|
5747 | //
|
5748 | // Permission is hereby granted, free of charge, to any person obtaining a
|
5749 | // copy of this software and associated documentation files (the
|
5750 | // "Software"), to deal in the Software without restriction, including
|
5751 | // without limitation the rights to use, copy, modify, merge, publish,
|
5752 | // distribute, sublicense, and/or sell copies of the Software, and to permit
|
5753 | // persons to whom the Software is furnished to do so, subject to the
|
5754 | // following conditions:
|
5755 | //
|
5756 | // The above copyright notice and this permission notice shall be included
|
5757 | // in all copies or substantial portions of the Software.
|
5758 | //
|
5759 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
5760 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
5761 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
5762 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
5763 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
5764 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
5765 | // USE OR OTHER DEALINGS IN THE SOFTWARE.
|
5766 | // A bit simpler than readable streams.
|
5767 | // Implement an async ._write(chunk, encoding, cb), and it'll handle all
|
5768 | // the drain event emission and buffering.
|
5769 | 'use strict';
|
5770 |
|
5771 | module.exports = Writable;
|
5772 | /* <replacement> */
|
5773 |
|
5774 | function WriteReq(chunk, encoding, cb) {
|
5775 | this.chunk = chunk;
|
5776 | this.encoding = encoding;
|
5777 | this.callback = cb;
|
5778 | this.next = null;
|
5779 | } // It seems a linked list but it is not
|
5780 | // there will be only 2 of these for each stream
|
5781 |
|
5782 |
|
5783 | function CorkedRequest(state) {
|
5784 | var _this = this;
|
5785 |
|
5786 | this.next = null;
|
5787 | this.entry = null;
|
5788 |
|
5789 | this.finish = function () {
|
5790 | onCorkedFinish(_this, state);
|
5791 | };
|
5792 | }
|
5793 | /* </replacement> */
|
5794 |
|
5795 | /*<replacement>*/
|
5796 |
|
5797 |
|
5798 | var Duplex;
|
5799 | /*</replacement>*/
|
5800 |
|
5801 | Writable.WritableState = WritableState;
|
5802 | /*<replacement>*/
|
5803 |
|
5804 | var internalUtil = {
|
5805 | deprecate: require('util-deprecate')
|
5806 | };
|
5807 | /*</replacement>*/
|
5808 |
|
5809 | /*<replacement>*/
|
5810 |
|
5811 | var Stream = require('./internal/streams/stream');
|
5812 | /*</replacement>*/
|
5813 |
|
5814 |
|
5815 | var Buffer = require('buffer').Buffer;
|
5816 |
|
5817 | var OurUint8Array = global.Uint8Array || function () {};
|
5818 |
|
5819 | function _uint8ArrayToBuffer(chunk) {
|
5820 | return Buffer.from(chunk);
|
5821 | }
|
5822 |
|
5823 | function _isUint8Array(obj) {
|
5824 | return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
|
5825 | }
|
5826 |
|
5827 | var destroyImpl = require('./internal/streams/destroy');
|
5828 |
|
5829 | var _require = require('./internal/streams/state'),
|
5830 | getHighWaterMark = _require.getHighWaterMark;
|
5831 |
|
5832 | var _require$codes = require('../errors').codes,
|
5833 | ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
|
5834 | ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
|
5835 | ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
|
5836 | ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE,
|
5837 | ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED,
|
5838 | ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES,
|
5839 | ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END,
|
5840 | ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;
|
5841 |
|
5842 | var errorOrDestroy = destroyImpl.errorOrDestroy;
|
5843 |
|
5844 | require('inherits')(Writable, Stream);
|
5845 |
|
5846 | function nop() {}
|
5847 |
|
5848 | function WritableState(options, stream, isDuplex) {
|
5849 | Duplex = Duplex || require('./_stream_duplex');
|
5850 | options = options || {}; // Duplex streams are both readable and writable, but share
|
5851 | // the same options object.
|
5852 | // However, some cases require setting options to different
|
5853 | // values for the readable and the writable sides of the duplex stream,
|
5854 | // e.g. options.readableObjectMode vs. options.writableObjectMode, etc.
|
5855 |
|
5856 | if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; // object stream flag to indicate whether or not this stream
|
5857 | // contains buffers or objects.
|
5858 |
|
5859 | this.objectMode = !!options.objectMode;
|
5860 | if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode; // the point at which write() starts returning false
|
5861 | // Note: 0 is a valid value, means that we always return false if
|
5862 | // the entire buffer is not flushed immediately on write()
|
5863 |
|
5864 | this.highWaterMark = getHighWaterMark(this, options, 'writableHighWaterMark', isDuplex); // if _final has been called
|
5865 |
|
5866 | this.finalCalled = false; // drain event flag.
|
5867 |
|
5868 | this.needDrain = false; // at the start of calling end()
|
5869 |
|
5870 | this.ending = false; // when end() has been called, and returned
|
5871 |
|
5872 | this.ended = false; // when 'finish' is emitted
|
5873 |
|
5874 | this.finished = false; // has it been destroyed
|
5875 |
|
5876 | this.destroyed = false; // should we decode strings into buffers before passing to _write?
|
5877 | // this is here so that some node-core streams can optimize string
|
5878 | // handling at a lower level.
|
5879 |
|
5880 | var noDecode = options.decodeStrings === false;
|
5881 | this.decodeStrings = !noDecode; // Crypto is kind of old and crusty. Historically, its default string
|
5882 | // encoding is 'binary' so we have to make this configurable.
|
5883 | // Everything else in the universe uses 'utf8', though.
|
5884 |
|
5885 | this.defaultEncoding = options.defaultEncoding || 'utf8'; // not an actual buffer we keep track of, but a measurement
|
5886 | // of how much we're waiting to get pushed to some underlying
|
5887 | // socket or file.
|
5888 |
|
5889 | this.length = 0; // a flag to see when we're in the middle of a write.
|
5890 |
|
5891 | this.writing = false; // when true all writes will be buffered until .uncork() call
|
5892 |
|
5893 | this.corked = 0; // a flag to be able to tell if the onwrite cb is called immediately,
|
5894 | // or on a later tick. We set this to true at first, because any
|
5895 | // actions that shouldn't happen until "later" should generally also
|
5896 | // not happen before the first write call.
|
5897 |
|
5898 | this.sync = true; // a flag to know if we're processing previously buffered items, which
|
5899 | // may call the _write() callback in the same tick, so that we don't
|
5900 | // end up in an overlapped onwrite situation.
|
5901 |
|
5902 | this.bufferProcessing = false; // the callback that's passed to _write(chunk,cb)
|
5903 |
|
5904 | this.onwrite = function (er) {
|
5905 | onwrite(stream, er);
|
5906 | }; // the callback that the user supplies to write(chunk,encoding,cb)
|
5907 |
|
5908 |
|
5909 | this.writecb = null; // the amount that is being written when _write is called.
|
5910 |
|
5911 | this.writelen = 0;
|
5912 | this.bufferedRequest = null;
|
5913 | this.lastBufferedRequest = null; // number of pending user-supplied write callbacks
|
5914 | // this must be 0 before 'finish' can be emitted
|
5915 |
|
5916 | this.pendingcb = 0; // emit prefinish if the only thing we're waiting for is _write cbs
|
5917 | // This is relevant for synchronous Transform streams
|
5918 |
|
5919 | this.prefinished = false; // True if the error was already emitted and should not be thrown again
|
5920 |
|
5921 | this.errorEmitted = false; // Should close be emitted on destroy. Defaults to true.
|
5922 |
|
5923 | this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'finish' (and potentially 'end')
|
5924 |
|
5925 | this.autoDestroy = !!options.autoDestroy; // count buffered requests
|
5926 |
|
5927 | this.bufferedRequestCount = 0; // allocate the first CorkedRequest, there is always
|
5928 | // one allocated and free to use, and we maintain at most two
|
5929 |
|
5930 | this.corkedRequestsFree = new CorkedRequest(this);
|
5931 | }
|
5932 |
|
5933 | WritableState.prototype.getBuffer = function getBuffer() {
|
5934 | var current = this.bufferedRequest;
|
5935 | var out = [];
|
5936 |
|
5937 | while (current) {
|
5938 | out.push(current);
|
5939 | current = current.next;
|
5940 | }
|
5941 |
|
5942 | return out;
|
5943 | };
|
5944 |
|
5945 | (function () {
|
5946 | try {
|
5947 | Object.defineProperty(WritableState.prototype, 'buffer', {
|
5948 | get: internalUtil.deprecate(function writableStateBufferGetter() {
|
5949 | return this.getBuffer();
|
5950 | }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
|
5951 | });
|
5952 | } catch (_) {}
|
5953 | })(); // Test _writableState for inheritance to account for Duplex streams,
|
5954 | // whose prototype chain only points to Readable.
|
5955 |
|
5956 |
|
5957 | var realHasInstance;
|
5958 |
|
5959 | if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
|
5960 | realHasInstance = Function.prototype[Symbol.hasInstance];
|
5961 | Object.defineProperty(Writable, Symbol.hasInstance, {
|
5962 | value: function value(object) {
|
5963 | if (realHasInstance.call(this, object)) return true;
|
5964 | if (this !== Writable) return false;
|
5965 | return object && object._writableState instanceof WritableState;
|
5966 | }
|
5967 | });
|
5968 | } else {
|
5969 | realHasInstance = function realHasInstance(object) {
|
5970 | return object instanceof this;
|
5971 | };
|
5972 | }
|
5973 |
|
5974 | function Writable(options) {
|
5975 | Duplex = Duplex || require('./_stream_duplex'); // Writable ctor is applied to Duplexes, too.
|
5976 | // `realHasInstance` is necessary because using plain `instanceof`
|
5977 | // would return false, as no `_writableState` property is attached.
|
5978 | // Trying to use the custom `instanceof` for Writable here will also break the
|
5979 | // Node.js LazyTransform implementation, which has a non-trivial getter for
|
5980 | // `_writableState` that would lead to infinite recursion.
|
5981 | // Checking for a Stream.Duplex instance is faster here instead of inside
|
5982 | // the WritableState constructor, at least with V8 6.5
|
5983 |
|
5984 | var isDuplex = this instanceof Duplex;
|
5985 | if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options);
|
5986 | this._writableState = new WritableState(options, this, isDuplex); // legacy.
|
5987 |
|
5988 | this.writable = true;
|
5989 |
|
5990 | if (options) {
|
5991 | if (typeof options.write === 'function') this._write = options.write;
|
5992 | if (typeof options.writev === 'function') this._writev = options.writev;
|
5993 | if (typeof options.destroy === 'function') this._destroy = options.destroy;
|
5994 | if (typeof options.final === 'function') this._final = options.final;
|
5995 | }
|
5996 |
|
5997 | Stream.call(this);
|
5998 | } // Otherwise people can pipe Writable streams, which is just wrong.
|
5999 |
|
6000 |
|
6001 | Writable.prototype.pipe = function () {
|
6002 | errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE());
|
6003 | };
|
6004 |
|
6005 | function writeAfterEnd(stream, cb) {
|
6006 | var er = new ERR_STREAM_WRITE_AFTER_END(); // TODO: defer error events consistently everywhere, not just the cb
|
6007 |
|
6008 | errorOrDestroy(stream, er);
|
6009 | process.nextTick(cb, er);
|
6010 | } // Checks that a user-supplied chunk is valid, especially for the particular
|
6011 | // mode the stream is in. Currently this means that `null` is never accepted
|
6012 | // and undefined/non-string values are only allowed in object mode.
|
6013 |
|
6014 |
|
6015 | function validChunk(stream, state, chunk, cb) {
|
6016 | var er;
|
6017 |
|
6018 | if (chunk === null) {
|
6019 | er = new ERR_STREAM_NULL_VALUES();
|
6020 | } else if (typeof chunk !== 'string' && !state.objectMode) {
|
6021 | er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer'], chunk);
|
6022 | }
|
6023 |
|
6024 | if (er) {
|
6025 | errorOrDestroy(stream, er);
|
6026 | process.nextTick(cb, er);
|
6027 | return false;
|
6028 | }
|
6029 |
|
6030 | return true;
|
6031 | }
|
6032 |
|
6033 | Writable.prototype.write = function (chunk, encoding, cb) {
|
6034 | var state = this._writableState;
|
6035 | var ret = false;
|
6036 |
|
6037 | var isBuf = !state.objectMode && _isUint8Array(chunk);
|
6038 |
|
6039 | if (isBuf && !Buffer.isBuffer(chunk)) {
|
6040 | chunk = _uint8ArrayToBuffer(chunk);
|
6041 | }
|
6042 |
|
6043 | if (typeof encoding === 'function') {
|
6044 | cb = encoding;
|
6045 | encoding = null;
|
6046 | }
|
6047 |
|
6048 | if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
|
6049 | if (typeof cb !== 'function') cb = nop;
|
6050 | if (state.ending) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
|
6051 | state.pendingcb++;
|
6052 | ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
|
6053 | }
|
6054 | return ret;
|
6055 | };
|
6056 |
|
6057 | Writable.prototype.cork = function () {
|
6058 | this._writableState.corked++;
|
6059 | };
|
6060 |
|
6061 | Writable.prototype.uncork = function () {
|
6062 | var state = this._writableState;
|
6063 |
|
6064 | if (state.corked) {
|
6065 | state.corked--;
|
6066 | if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
|
6067 | }
|
6068 | };
|
6069 |
|
6070 | Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
|
6071 | // node::ParseEncoding() requires lower case.
|
6072 | if (typeof encoding === 'string') encoding = encoding.toLowerCase();
|
6073 | if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new ERR_UNKNOWN_ENCODING(encoding);
|
6074 | this._writableState.defaultEncoding = encoding;
|
6075 | return this;
|
6076 | };
|
6077 |
|
6078 | Object.defineProperty(Writable.prototype, 'writableBuffer', {
|
6079 | // making it explicit this property is not enumerable
|
6080 | // because otherwise some prototype manipulation in
|
6081 | // userland will fail
|
6082 | enumerable: false,
|
6083 | get: function get() {
|
6084 | return this._writableState && this._writableState.getBuffer();
|
6085 | }
|
6086 | });
|
6087 |
|
6088 | function decodeChunk(state, chunk, encoding) {
|
6089 | if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
|
6090 | chunk = Buffer.from(chunk, encoding);
|
6091 | }
|
6092 |
|
6093 | return chunk;
|
6094 | }
|
6095 |
|
6096 | Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
|
6097 | // making it explicit this property is not enumerable
|
6098 | // because otherwise some prototype manipulation in
|
6099 | // userland will fail
|
6100 | enumerable: false,
|
6101 | get: function get() {
|
6102 | return this._writableState.highWaterMark;
|
6103 | }
|
6104 | }); // if we're already writing something, then just put this
|
6105 | // in the queue, and wait our turn. Otherwise, call _write
|
6106 | // If we return false, then we need a drain event, so set that flag.
|
6107 |
|
6108 | function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
|
6109 | if (!isBuf) {
|
6110 | var newChunk = decodeChunk(state, chunk, encoding);
|
6111 |
|
6112 | if (chunk !== newChunk) {
|
6113 | isBuf = true;
|
6114 | encoding = 'buffer';
|
6115 | chunk = newChunk;
|
6116 | }
|
6117 | }
|
6118 |
|
6119 | var len = state.objectMode ? 1 : chunk.length;
|
6120 | state.length += len;
|
6121 | var ret = state.length < state.highWaterMark; // we must ensure that previous needDrain will not be reset to false.
|
6122 |
|
6123 | if (!ret) state.needDrain = true;
|
6124 |
|
6125 | if (state.writing || state.corked) {
|
6126 | var last = state.lastBufferedRequest;
|
6127 | state.lastBufferedRequest = {
|
6128 | chunk: chunk,
|
6129 | encoding: encoding,
|
6130 | isBuf: isBuf,
|
6131 | callback: cb,
|
6132 | next: null
|
6133 | };
|
6134 |
|
6135 | if (last) {
|
6136 | last.next = state.lastBufferedRequest;
|
6137 | } else {
|
6138 | state.bufferedRequest = state.lastBufferedRequest;
|
6139 | }
|
6140 |
|
6141 | state.bufferedRequestCount += 1;
|
6142 | } else {
|
6143 | doWrite(stream, state, false, len, chunk, encoding, cb);
|
6144 | }
|
6145 |
|
6146 | return ret;
|
6147 | }
|
6148 |
|
6149 | function doWrite(stream, state, writev, len, chunk, encoding, cb) {
|
6150 | state.writelen = len;
|
6151 | state.writecb = cb;
|
6152 | state.writing = true;
|
6153 | state.sync = true;
|
6154 | if (state.destroyed) state.onwrite(new ERR_STREAM_DESTROYED('write'));else if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
|
6155 | state.sync = false;
|
6156 | }
|
6157 |
|
6158 | function onwriteError(stream, state, sync, er, cb) {
|
6159 | --state.pendingcb;
|
6160 |
|
6161 | if (sync) {
|
6162 | // defer the callback if we are being called synchronously
|
6163 | // to avoid piling up things on the stack
|
6164 | process.nextTick(cb, er); // this can emit finish, and it will always happen
|
6165 | // after error
|
6166 |
|
6167 | process.nextTick(finishMaybe, stream, state);
|
6168 | stream._writableState.errorEmitted = true;
|
6169 | errorOrDestroy(stream, er);
|
6170 | } else {
|
6171 | // the caller expect this to happen before if
|
6172 | // it is async
|
6173 | cb(er);
|
6174 | stream._writableState.errorEmitted = true;
|
6175 | errorOrDestroy(stream, er); // this can emit finish, but finish must
|
6176 | // always follow error
|
6177 |
|
6178 | finishMaybe(stream, state);
|
6179 | }
|
6180 | }
|
6181 |
|
6182 | function onwriteStateUpdate(state) {
|
6183 | state.writing = false;
|
6184 | state.writecb = null;
|
6185 | state.length -= state.writelen;
|
6186 | state.writelen = 0;
|
6187 | }
|
6188 |
|
6189 | function onwrite(stream, er) {
|
6190 | var state = stream._writableState;
|
6191 | var sync = state.sync;
|
6192 | var cb = state.writecb;
|
6193 | if (typeof cb !== 'function') throw new ERR_MULTIPLE_CALLBACK();
|
6194 | onwriteStateUpdate(state);
|
6195 | if (er) onwriteError(stream, state, sync, er, cb);else {
|
6196 | // Check if we're actually ready to finish, but don't emit yet
|
6197 | var finished = needFinish(state) || stream.destroyed;
|
6198 |
|
6199 | if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
|
6200 | clearBuffer(stream, state);
|
6201 | }
|
6202 |
|
6203 | if (sync) {
|
6204 | process.nextTick(afterWrite, stream, state, finished, cb);
|
6205 | } else {
|
6206 | afterWrite(stream, state, finished, cb);
|
6207 | }
|
6208 | }
|
6209 | }
|
6210 |
|
6211 | function afterWrite(stream, state, finished, cb) {
|
6212 | if (!finished) onwriteDrain(stream, state);
|
6213 | state.pendingcb--;
|
6214 | cb();
|
6215 | finishMaybe(stream, state);
|
6216 | } // Must force callback to be called on nextTick, so that we don't
|
6217 | // emit 'drain' before the write() consumer gets the 'false' return
|
6218 | // value, and has a chance to attach a 'drain' listener.
|
6219 |
|
6220 |
|
6221 | function onwriteDrain(stream, state) {
|
6222 | if (state.length === 0 && state.needDrain) {
|
6223 | state.needDrain = false;
|
6224 | stream.emit('drain');
|
6225 | }
|
6226 | } // if there's something in the buffer waiting, then process it
|
6227 |
|
6228 |
|
6229 | function clearBuffer(stream, state) {
|
6230 | state.bufferProcessing = true;
|
6231 | var entry = state.bufferedRequest;
|
6232 |
|
6233 | if (stream._writev && entry && entry.next) {
|
6234 | // Fast case, write everything using _writev()
|
6235 | var l = state.bufferedRequestCount;
|
6236 | var buffer = new Array(l);
|
6237 | var holder = state.corkedRequestsFree;
|
6238 | holder.entry = entry;
|
6239 | var count = 0;
|
6240 | var allBuffers = true;
|
6241 |
|
6242 | while (entry) {
|
6243 | buffer[count] = entry;
|
6244 | if (!entry.isBuf) allBuffers = false;
|
6245 | entry = entry.next;
|
6246 | count += 1;
|
6247 | }
|
6248 |
|
6249 | buffer.allBuffers = allBuffers;
|
6250 | doWrite(stream, state, true, state.length, buffer, '', holder.finish); // doWrite is almost always async, defer these to save a bit of time
|
6251 | // as the hot path ends with doWrite
|
6252 |
|
6253 | state.pendingcb++;
|
6254 | state.lastBufferedRequest = null;
|
6255 |
|
6256 | if (holder.next) {
|
6257 | state.corkedRequestsFree = holder.next;
|
6258 | holder.next = null;
|
6259 | } else {
|
6260 | state.corkedRequestsFree = new CorkedRequest(state);
|
6261 | }
|
6262 |
|
6263 | state.bufferedRequestCount = 0;
|
6264 | } else {
|
6265 | // Slow case, write chunks one-by-one
|
6266 | while (entry) {
|
6267 | var chunk = entry.chunk;
|
6268 | var encoding = entry.encoding;
|
6269 | var cb = entry.callback;
|
6270 | var len = state.objectMode ? 1 : chunk.length;
|
6271 | doWrite(stream, state, false, len, chunk, encoding, cb);
|
6272 | entry = entry.next;
|
6273 | state.bufferedRequestCount--; // if we didn't call the onwrite immediately, then
|
6274 | // it means that we need to wait until it does.
|
6275 | // also, that means that the chunk and cb are currently
|
6276 | // being processed, so move the buffer counter past them.
|
6277 |
|
6278 | if (state.writing) {
|
6279 | break;
|
6280 | }
|
6281 | }
|
6282 |
|
6283 | if (entry === null) state.lastBufferedRequest = null;
|
6284 | }
|
6285 |
|
6286 | state.bufferedRequest = entry;
|
6287 | state.bufferProcessing = false;
|
6288 | }
|
6289 |
|
6290 | Writable.prototype._write = function (chunk, encoding, cb) {
|
6291 | cb(new ERR_METHOD_NOT_IMPLEMENTED('_write()'));
|
6292 | };
|
6293 |
|
6294 | Writable.prototype._writev = null;
|
6295 |
|
6296 | Writable.prototype.end = function (chunk, encoding, cb) {
|
6297 | var state = this._writableState;
|
6298 |
|
6299 | if (typeof chunk === 'function') {
|
6300 | cb = chunk;
|
6301 | chunk = null;
|
6302 | encoding = null;
|
6303 | } else if (typeof encoding === 'function') {
|
6304 | cb = encoding;
|
6305 | encoding = null;
|
6306 | }
|
6307 |
|
6308 | if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); // .end() fully uncorks
|
6309 |
|
6310 | if (state.corked) {
|
6311 | state.corked = 1;
|
6312 | this.uncork();
|
6313 | } // ignore unnecessary end() calls.
|
6314 |
|
6315 |
|
6316 | if (!state.ending) endWritable(this, state, cb);
|
6317 | return this;
|
6318 | };
|
6319 |
|
6320 | Object.defineProperty(Writable.prototype, 'writableLength', {
|
6321 | // making it explicit this property is not enumerable
|
6322 | // because otherwise some prototype manipulation in
|
6323 | // userland will fail
|
6324 | enumerable: false,
|
6325 | get: function get() {
|
6326 | return this._writableState.length;
|
6327 | }
|
6328 | });
|
6329 |
|
6330 | function needFinish(state) {
|
6331 | return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
|
6332 | }
|
6333 |
|
6334 | function callFinal(stream, state) {
|
6335 | stream._final(function (err) {
|
6336 | state.pendingcb--;
|
6337 |
|
6338 | if (err) {
|
6339 | errorOrDestroy(stream, err);
|
6340 | }
|
6341 |
|
6342 | state.prefinished = true;
|
6343 | stream.emit('prefinish');
|
6344 | finishMaybe(stream, state);
|
6345 | });
|
6346 | }
|
6347 |
|
6348 | function prefinish(stream, state) {
|
6349 | if (!state.prefinished && !state.finalCalled) {
|
6350 | if (typeof stream._final === 'function' && !state.destroyed) {
|
6351 | state.pendingcb++;
|
6352 | state.finalCalled = true;
|
6353 | process.nextTick(callFinal, stream, state);
|
6354 | } else {
|
6355 | state.prefinished = true;
|
6356 | stream.emit('prefinish');
|
6357 | }
|
6358 | }
|
6359 | }
|
6360 |
|
6361 | function finishMaybe(stream, state) {
|
6362 | var need = needFinish(state);
|
6363 |
|
6364 | if (need) {
|
6365 | prefinish(stream, state);
|
6366 |
|
6367 | if (state.pendingcb === 0) {
|
6368 | state.finished = true;
|
6369 | stream.emit('finish');
|
6370 |
|
6371 | if (state.autoDestroy) {
|
6372 | // In case of duplex streams we need a way to detect
|
6373 | // if the readable side is ready for autoDestroy as well
|
6374 | var rState = stream._readableState;
|
6375 |
|
6376 | if (!rState || rState.autoDestroy && rState.endEmitted) {
|
6377 | stream.destroy();
|
6378 | }
|
6379 | }
|
6380 | }
|
6381 | }
|
6382 |
|
6383 | return need;
|
6384 | }
|
6385 |
|
6386 | function endWritable(stream, state, cb) {
|
6387 | state.ending = true;
|
6388 | finishMaybe(stream, state);
|
6389 |
|
6390 | if (cb) {
|
6391 | if (state.finished) process.nextTick(cb);else stream.once('finish', cb);
|
6392 | }
|
6393 |
|
6394 | state.ended = true;
|
6395 | stream.writable = false;
|
6396 | }
|
6397 |
|
6398 | function onCorkedFinish(corkReq, state, err) {
|
6399 | var entry = corkReq.entry;
|
6400 | corkReq.entry = null;
|
6401 |
|
6402 | while (entry) {
|
6403 | var cb = entry.callback;
|
6404 | state.pendingcb--;
|
6405 | cb(err);
|
6406 | entry = entry.next;
|
6407 | } // reuse the free corkReq.
|
6408 |
|
6409 |
|
6410 | state.corkedRequestsFree.next = corkReq;
|
6411 | }
|
6412 |
|
6413 | Object.defineProperty(Writable.prototype, 'destroyed', {
|
6414 | // making it explicit this property is not enumerable
|
6415 | // because otherwise some prototype manipulation in
|
6416 | // userland will fail
|
6417 | enumerable: false,
|
6418 | get: function get() {
|
6419 | if (this._writableState === undefined) {
|
6420 | return false;
|
6421 | }
|
6422 |
|
6423 | return this._writableState.destroyed;
|
6424 | },
|
6425 | set: function set(value) {
|
6426 | // we ignore the value if the stream
|
6427 | // has not been initialized yet
|
6428 | if (!this._writableState) {
|
6429 | return;
|
6430 | } // backward compatibility, the user is explicitly
|
6431 | // managing destroyed
|
6432 |
|
6433 |
|
6434 | this._writableState.destroyed = value;
|
6435 | }
|
6436 | });
|
6437 | Writable.prototype.destroy = destroyImpl.destroy;
|
6438 | Writable.prototype._undestroy = destroyImpl.undestroy;
|
6439 |
|
6440 | Writable.prototype._destroy = function (err, cb) {
|
6441 | cb(err);
|
6442 | };
|
6443 | }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
6444 | },{"../errors":18,"./_stream_duplex":19,"./internal/streams/destroy":26,"./internal/streams/state":30,"./internal/streams/stream":31,"_process":11,"buffer":5,"inherits":10,"util-deprecate":54}],24:[function(require,module,exports){
|
6445 | (function (process){(function (){
|
6446 | 'use strict';
|
6447 |
|
6448 | var _Object$setPrototypeO;
|
6449 |
|
6450 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
6451 |
|
6452 | var finished = require('./end-of-stream');
|
6453 |
|
6454 | var kLastResolve = Symbol('lastResolve');
|
6455 | var kLastReject = Symbol('lastReject');
|
6456 | var kError = Symbol('error');
|
6457 | var kEnded = Symbol('ended');
|
6458 | var kLastPromise = Symbol('lastPromise');
|
6459 | var kHandlePromise = Symbol('handlePromise');
|
6460 | var kStream = Symbol('stream');
|
6461 |
|
6462 | function createIterResult(value, done) {
|
6463 | return {
|
6464 | value: value,
|
6465 | done: done
|
6466 | };
|
6467 | }
|
6468 |
|
6469 | function readAndResolve(iter) {
|
6470 | var resolve = iter[kLastResolve];
|
6471 |
|
6472 | if (resolve !== null) {
|
6473 | var data = iter[kStream].read(); // we defer if data is null
|
6474 | // we can be expecting either 'end' or
|
6475 | // 'error'
|
6476 |
|
6477 | if (data !== null) {
|
6478 | iter[kLastPromise] = null;
|
6479 | iter[kLastResolve] = null;
|
6480 | iter[kLastReject] = null;
|
6481 | resolve(createIterResult(data, false));
|
6482 | }
|
6483 | }
|
6484 | }
|
6485 |
|
6486 | function onReadable(iter) {
|
6487 | // we wait for the next tick, because it might
|
6488 | // emit an error with process.nextTick
|
6489 | process.nextTick(readAndResolve, iter);
|
6490 | }
|
6491 |
|
6492 | function wrapForNext(lastPromise, iter) {
|
6493 | return function (resolve, reject) {
|
6494 | lastPromise.then(function () {
|
6495 | if (iter[kEnded]) {
|
6496 | resolve(createIterResult(undefined, true));
|
6497 | return;
|
6498 | }
|
6499 |
|
6500 | iter[kHandlePromise](resolve, reject);
|
6501 | }, reject);
|
6502 | };
|
6503 | }
|
6504 |
|
6505 | var AsyncIteratorPrototype = Object.getPrototypeOf(function () {});
|
6506 | var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = {
|
6507 | get stream() {
|
6508 | return this[kStream];
|
6509 | },
|
6510 |
|
6511 | next: function next() {
|
6512 | var _this = this;
|
6513 |
|
6514 | // if we have detected an error in the meanwhile
|
6515 | // reject straight away
|
6516 | var error = this[kError];
|
6517 |
|
6518 | if (error !== null) {
|
6519 | return Promise.reject(error);
|
6520 | }
|
6521 |
|
6522 | if (this[kEnded]) {
|
6523 | return Promise.resolve(createIterResult(undefined, true));
|
6524 | }
|
6525 |
|
6526 | if (this[kStream].destroyed) {
|
6527 | // We need to defer via nextTick because if .destroy(err) is
|
6528 | // called, the error will be emitted via nextTick, and
|
6529 | // we cannot guarantee that there is no error lingering around
|
6530 | // waiting to be emitted.
|
6531 | return new Promise(function (resolve, reject) {
|
6532 | process.nextTick(function () {
|
6533 | if (_this[kError]) {
|
6534 | reject(_this[kError]);
|
6535 | } else {
|
6536 | resolve(createIterResult(undefined, true));
|
6537 | }
|
6538 | });
|
6539 | });
|
6540 | } // if we have multiple next() calls
|
6541 | // we will wait for the previous Promise to finish
|
6542 | // this logic is optimized to support for await loops,
|
6543 | // where next() is only called once at a time
|
6544 |
|
6545 |
|
6546 | var lastPromise = this[kLastPromise];
|
6547 | var promise;
|
6548 |
|
6549 | if (lastPromise) {
|
6550 | promise = new Promise(wrapForNext(lastPromise, this));
|
6551 | } else {
|
6552 | // fast path needed to support multiple this.push()
|
6553 | // without triggering the next() queue
|
6554 | var data = this[kStream].read();
|
6555 |
|
6556 | if (data !== null) {
|
6557 | return Promise.resolve(createIterResult(data, false));
|
6558 | }
|
6559 |
|
6560 | promise = new Promise(this[kHandlePromise]);
|
6561 | }
|
6562 |
|
6563 | this[kLastPromise] = promise;
|
6564 | return promise;
|
6565 | }
|
6566 | }, _defineProperty(_Object$setPrototypeO, Symbol.asyncIterator, function () {
|
6567 | return this;
|
6568 | }), _defineProperty(_Object$setPrototypeO, "return", function _return() {
|
6569 | var _this2 = this;
|
6570 |
|
6571 | // destroy(err, cb) is a private API
|
6572 | // we can guarantee we have that here, because we control the
|
6573 | // Readable class this is attached to
|
6574 | return new Promise(function (resolve, reject) {
|
6575 | _this2[kStream].destroy(null, function (err) {
|
6576 | if (err) {
|
6577 | reject(err);
|
6578 | return;
|
6579 | }
|
6580 |
|
6581 | resolve(createIterResult(undefined, true));
|
6582 | });
|
6583 | });
|
6584 | }), _Object$setPrototypeO), AsyncIteratorPrototype);
|
6585 |
|
6586 | var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator(stream) {
|
6587 | var _Object$create;
|
6588 |
|
6589 | var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, {
|
6590 | value: stream,
|
6591 | writable: true
|
6592 | }), _defineProperty(_Object$create, kLastResolve, {
|
6593 | value: null,
|
6594 | writable: true
|
6595 | }), _defineProperty(_Object$create, kLastReject, {
|
6596 | value: null,
|
6597 | writable: true
|
6598 | }), _defineProperty(_Object$create, kError, {
|
6599 | value: null,
|
6600 | writable: true
|
6601 | }), _defineProperty(_Object$create, kEnded, {
|
6602 | value: stream._readableState.endEmitted,
|
6603 | writable: true
|
6604 | }), _defineProperty(_Object$create, kHandlePromise, {
|
6605 | value: function value(resolve, reject) {
|
6606 | var data = iterator[kStream].read();
|
6607 |
|
6608 | if (data) {
|
6609 | iterator[kLastPromise] = null;
|
6610 | iterator[kLastResolve] = null;
|
6611 | iterator[kLastReject] = null;
|
6612 | resolve(createIterResult(data, false));
|
6613 | } else {
|
6614 | iterator[kLastResolve] = resolve;
|
6615 | iterator[kLastReject] = reject;
|
6616 | }
|
6617 | },
|
6618 | writable: true
|
6619 | }), _Object$create));
|
6620 | iterator[kLastPromise] = null;
|
6621 | finished(stream, function (err) {
|
6622 | if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
|
6623 | var reject = iterator[kLastReject]; // reject if we are waiting for data in the Promise
|
6624 | // returned by next() and store the error
|
6625 |
|
6626 | if (reject !== null) {
|
6627 | iterator[kLastPromise] = null;
|
6628 | iterator[kLastResolve] = null;
|
6629 | iterator[kLastReject] = null;
|
6630 | reject(err);
|
6631 | }
|
6632 |
|
6633 | iterator[kError] = err;
|
6634 | return;
|
6635 | }
|
6636 |
|
6637 | var resolve = iterator[kLastResolve];
|
6638 |
|
6639 | if (resolve !== null) {
|
6640 | iterator[kLastPromise] = null;
|
6641 | iterator[kLastResolve] = null;
|
6642 | iterator[kLastReject] = null;
|
6643 | resolve(createIterResult(undefined, true));
|
6644 | }
|
6645 |
|
6646 | iterator[kEnded] = true;
|
6647 | });
|
6648 | stream.on('readable', onReadable.bind(null, iterator));
|
6649 | return iterator;
|
6650 | };
|
6651 |
|
6652 | module.exports = createReadableStreamAsyncIterator;
|
6653 | }).call(this)}).call(this,require('_process'))
|
6654 | },{"./end-of-stream":27,"_process":11}],25:[function(require,module,exports){
|
6655 | 'use strict';
|
6656 |
|
6657 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
6658 |
|
6659 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
6660 |
|
6661 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
6662 |
|
6663 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
6664 |
|
6665 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
6666 |
|
6667 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
6668 |
|
6669 | var _require = require('buffer'),
|
6670 | Buffer = _require.Buffer;
|
6671 |
|
6672 | var _require2 = require('util'),
|
6673 | inspect = _require2.inspect;
|
6674 |
|
6675 | var custom = inspect && inspect.custom || 'inspect';
|
6676 |
|
6677 | function copyBuffer(src, target, offset) {
|
6678 | Buffer.prototype.copy.call(src, target, offset);
|
6679 | }
|
6680 |
|
6681 | module.exports =
|
6682 | /*#__PURE__*/
|
6683 | function () {
|
6684 | function BufferList() {
|
6685 | _classCallCheck(this, BufferList);
|
6686 |
|
6687 | this.head = null;
|
6688 | this.tail = null;
|
6689 | this.length = 0;
|
6690 | }
|
6691 |
|
6692 | _createClass(BufferList, [{
|
6693 | key: "push",
|
6694 | value: function push(v) {
|
6695 | var entry = {
|
6696 | data: v,
|
6697 | next: null
|
6698 | };
|
6699 | if (this.length > 0) this.tail.next = entry;else this.head = entry;
|
6700 | this.tail = entry;
|
6701 | ++this.length;
|
6702 | }
|
6703 | }, {
|
6704 | key: "unshift",
|
6705 | value: function unshift(v) {
|
6706 | var entry = {
|
6707 | data: v,
|
6708 | next: this.head
|
6709 | };
|
6710 | if (this.length === 0) this.tail = entry;
|
6711 | this.head = entry;
|
6712 | ++this.length;
|
6713 | }
|
6714 | }, {
|
6715 | key: "shift",
|
6716 | value: function shift() {
|
6717 | if (this.length === 0) return;
|
6718 | var ret = this.head.data;
|
6719 | if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
|
6720 | --this.length;
|
6721 | return ret;
|
6722 | }
|
6723 | }, {
|
6724 | key: "clear",
|
6725 | value: function clear() {
|
6726 | this.head = this.tail = null;
|
6727 | this.length = 0;
|
6728 | }
|
6729 | }, {
|
6730 | key: "join",
|
6731 | value: function join(s) {
|
6732 | if (this.length === 0) return '';
|
6733 | var p = this.head;
|
6734 | var ret = '' + p.data;
|
6735 |
|
6736 | while (p = p.next) {
|
6737 | ret += s + p.data;
|
6738 | }
|
6739 |
|
6740 | return ret;
|
6741 | }
|
6742 | }, {
|
6743 | key: "concat",
|
6744 | value: function concat(n) {
|
6745 | if (this.length === 0) return Buffer.alloc(0);
|
6746 | var ret = Buffer.allocUnsafe(n >>> 0);
|
6747 | var p = this.head;
|
6748 | var i = 0;
|
6749 |
|
6750 | while (p) {
|
6751 | copyBuffer(p.data, ret, i);
|
6752 | i += p.data.length;
|
6753 | p = p.next;
|
6754 | }
|
6755 |
|
6756 | return ret;
|
6757 | } // Consumes a specified amount of bytes or characters from the buffered data.
|
6758 |
|
6759 | }, {
|
6760 | key: "consume",
|
6761 | value: function consume(n, hasStrings) {
|
6762 | var ret;
|
6763 |
|
6764 | if (n < this.head.data.length) {
|
6765 | // `slice` is the same for buffers and strings.
|
6766 | ret = this.head.data.slice(0, n);
|
6767 | this.head.data = this.head.data.slice(n);
|
6768 | } else if (n === this.head.data.length) {
|
6769 | // First chunk is a perfect match.
|
6770 | ret = this.shift();
|
6771 | } else {
|
6772 | // Result spans more than one buffer.
|
6773 | ret = hasStrings ? this._getString(n) : this._getBuffer(n);
|
6774 | }
|
6775 |
|
6776 | return ret;
|
6777 | }
|
6778 | }, {
|
6779 | key: "first",
|
6780 | value: function first() {
|
6781 | return this.head.data;
|
6782 | } // Consumes a specified amount of characters from the buffered data.
|
6783 |
|
6784 | }, {
|
6785 | key: "_getString",
|
6786 | value: function _getString(n) {
|
6787 | var p = this.head;
|
6788 | var c = 1;
|
6789 | var ret = p.data;
|
6790 | n -= ret.length;
|
6791 |
|
6792 | while (p = p.next) {
|
6793 | var str = p.data;
|
6794 | var nb = n > str.length ? str.length : n;
|
6795 | if (nb === str.length) ret += str;else ret += str.slice(0, n);
|
6796 | n -= nb;
|
6797 |
|
6798 | if (n === 0) {
|
6799 | if (nb === str.length) {
|
6800 | ++c;
|
6801 | if (p.next) this.head = p.next;else this.head = this.tail = null;
|
6802 | } else {
|
6803 | this.head = p;
|
6804 | p.data = str.slice(nb);
|
6805 | }
|
6806 |
|
6807 | break;
|
6808 | }
|
6809 |
|
6810 | ++c;
|
6811 | }
|
6812 |
|
6813 | this.length -= c;
|
6814 | return ret;
|
6815 | } // Consumes a specified amount of bytes from the buffered data.
|
6816 |
|
6817 | }, {
|
6818 | key: "_getBuffer",
|
6819 | value: function _getBuffer(n) {
|
6820 | var ret = Buffer.allocUnsafe(n);
|
6821 | var p = this.head;
|
6822 | var c = 1;
|
6823 | p.data.copy(ret);
|
6824 | n -= p.data.length;
|
6825 |
|
6826 | while (p = p.next) {
|
6827 | var buf = p.data;
|
6828 | var nb = n > buf.length ? buf.length : n;
|
6829 | buf.copy(ret, ret.length - n, 0, nb);
|
6830 | n -= nb;
|
6831 |
|
6832 | if (n === 0) {
|
6833 | if (nb === buf.length) {
|
6834 | ++c;
|
6835 | if (p.next) this.head = p.next;else this.head = this.tail = null;
|
6836 | } else {
|
6837 | this.head = p;
|
6838 | p.data = buf.slice(nb);
|
6839 | }
|
6840 |
|
6841 | break;
|
6842 | }
|
6843 |
|
6844 | ++c;
|
6845 | }
|
6846 |
|
6847 | this.length -= c;
|
6848 | return ret;
|
6849 | } // Make sure the linked list only shows the minimal necessary information.
|
6850 |
|
6851 | }, {
|
6852 | key: custom,
|
6853 | value: function value(_, options) {
|
6854 | return inspect(this, _objectSpread({}, options, {
|
6855 | // Only inspect one level.
|
6856 | depth: 0,
|
6857 | // It should not recurse.
|
6858 | customInspect: false
|
6859 | }));
|
6860 | }
|
6861 | }]);
|
6862 |
|
6863 | return BufferList;
|
6864 | }();
|
6865 | },{"buffer":5,"util":4}],26:[function(require,module,exports){
|
6866 | (function (process){(function (){
|
6867 | 'use strict'; // undocumented cb() API, needed for core, not for public API
|
6868 |
|
6869 | function destroy(err, cb) {
|
6870 | var _this = this;
|
6871 |
|
6872 | var readableDestroyed = this._readableState && this._readableState.destroyed;
|
6873 | var writableDestroyed = this._writableState && this._writableState.destroyed;
|
6874 |
|
6875 | if (readableDestroyed || writableDestroyed) {
|
6876 | if (cb) {
|
6877 | cb(err);
|
6878 | } else if (err) {
|
6879 | if (!this._writableState) {
|
6880 | process.nextTick(emitErrorNT, this, err);
|
6881 | } else if (!this._writableState.errorEmitted) {
|
6882 | this._writableState.errorEmitted = true;
|
6883 | process.nextTick(emitErrorNT, this, err);
|
6884 | }
|
6885 | }
|
6886 |
|
6887 | return this;
|
6888 | } // we set destroyed to true before firing error callbacks in order
|
6889 | // to make it re-entrance safe in case destroy() is called within callbacks
|
6890 |
|
6891 |
|
6892 | if (this._readableState) {
|
6893 | this._readableState.destroyed = true;
|
6894 | } // if this is a duplex stream mark the writable part as destroyed as well
|
6895 |
|
6896 |
|
6897 | if (this._writableState) {
|
6898 | this._writableState.destroyed = true;
|
6899 | }
|
6900 |
|
6901 | this._destroy(err || null, function (err) {
|
6902 | if (!cb && err) {
|
6903 | if (!_this._writableState) {
|
6904 | process.nextTick(emitErrorAndCloseNT, _this, err);
|
6905 | } else if (!_this._writableState.errorEmitted) {
|
6906 | _this._writableState.errorEmitted = true;
|
6907 | process.nextTick(emitErrorAndCloseNT, _this, err);
|
6908 | } else {
|
6909 | process.nextTick(emitCloseNT, _this);
|
6910 | }
|
6911 | } else if (cb) {
|
6912 | process.nextTick(emitCloseNT, _this);
|
6913 | cb(err);
|
6914 | } else {
|
6915 | process.nextTick(emitCloseNT, _this);
|
6916 | }
|
6917 | });
|
6918 |
|
6919 | return this;
|
6920 | }
|
6921 |
|
6922 | function emitErrorAndCloseNT(self, err) {
|
6923 | emitErrorNT(self, err);
|
6924 | emitCloseNT(self);
|
6925 | }
|
6926 |
|
6927 | function emitCloseNT(self) {
|
6928 | if (self._writableState && !self._writableState.emitClose) return;
|
6929 | if (self._readableState && !self._readableState.emitClose) return;
|
6930 | self.emit('close');
|
6931 | }
|
6932 |
|
6933 | function undestroy() {
|
6934 | if (this._readableState) {
|
6935 | this._readableState.destroyed = false;
|
6936 | this._readableState.reading = false;
|
6937 | this._readableState.ended = false;
|
6938 | this._readableState.endEmitted = false;
|
6939 | }
|
6940 |
|
6941 | if (this._writableState) {
|
6942 | this._writableState.destroyed = false;
|
6943 | this._writableState.ended = false;
|
6944 | this._writableState.ending = false;
|
6945 | this._writableState.finalCalled = false;
|
6946 | this._writableState.prefinished = false;
|
6947 | this._writableState.finished = false;
|
6948 | this._writableState.errorEmitted = false;
|
6949 | }
|
6950 | }
|
6951 |
|
6952 | function emitErrorNT(self, err) {
|
6953 | self.emit('error', err);
|
6954 | }
|
6955 |
|
6956 | function errorOrDestroy(stream, err) {
|
6957 | // We have tests that rely on errors being emitted
|
6958 | // in the same tick, so changing this is semver major.
|
6959 | // For now when you opt-in to autoDestroy we allow
|
6960 | // the error to be emitted nextTick. In a future
|
6961 | // semver major update we should change the default to this.
|
6962 | var rState = stream._readableState;
|
6963 | var wState = stream._writableState;
|
6964 | if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err);
|
6965 | }
|
6966 |
|
6967 | module.exports = {
|
6968 | destroy: destroy,
|
6969 | undestroy: undestroy,
|
6970 | errorOrDestroy: errorOrDestroy
|
6971 | };
|
6972 | }).call(this)}).call(this,require('_process'))
|
6973 | },{"_process":11}],27:[function(require,module,exports){
|
6974 | // Ported from https://github.com/mafintosh/end-of-stream with
|
6975 | // permission from the author, Mathias Buus (@mafintosh).
|
6976 | 'use strict';
|
6977 |
|
6978 | var ERR_STREAM_PREMATURE_CLOSE = require('../../../errors').codes.ERR_STREAM_PREMATURE_CLOSE;
|
6979 |
|
6980 | function once(callback) {
|
6981 | var called = false;
|
6982 | return function () {
|
6983 | if (called) return;
|
6984 | called = true;
|
6985 |
|
6986 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
6987 | args[_key] = arguments[_key];
|
6988 | }
|
6989 |
|
6990 | callback.apply(this, args);
|
6991 | };
|
6992 | }
|
6993 |
|
6994 | function noop() {}
|
6995 |
|
6996 | function isRequest(stream) {
|
6997 | return stream.setHeader && typeof stream.abort === 'function';
|
6998 | }
|
6999 |
|
7000 | function eos(stream, opts, callback) {
|
7001 | if (typeof opts === 'function') return eos(stream, null, opts);
|
7002 | if (!opts) opts = {};
|
7003 | callback = once(callback || noop);
|
7004 | var readable = opts.readable || opts.readable !== false && stream.readable;
|
7005 | var writable = opts.writable || opts.writable !== false && stream.writable;
|
7006 |
|
7007 | var onlegacyfinish = function onlegacyfinish() {
|
7008 | if (!stream.writable) onfinish();
|
7009 | };
|
7010 |
|
7011 | var writableEnded = stream._writableState && stream._writableState.finished;
|
7012 |
|
7013 | var onfinish = function onfinish() {
|
7014 | writable = false;
|
7015 | writableEnded = true;
|
7016 | if (!readable) callback.call(stream);
|
7017 | };
|
7018 |
|
7019 | var readableEnded = stream._readableState && stream._readableState.endEmitted;
|
7020 |
|
7021 | var onend = function onend() {
|
7022 | readable = false;
|
7023 | readableEnded = true;
|
7024 | if (!writable) callback.call(stream);
|
7025 | };
|
7026 |
|
7027 | var onerror = function onerror(err) {
|
7028 | callback.call(stream, err);
|
7029 | };
|
7030 |
|
7031 | var onclose = function onclose() {
|
7032 | var err;
|
7033 |
|
7034 | if (readable && !readableEnded) {
|
7035 | if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
|
7036 | return callback.call(stream, err);
|
7037 | }
|
7038 |
|
7039 | if (writable && !writableEnded) {
|
7040 | if (!stream._writableState || !stream._writableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
|
7041 | return callback.call(stream, err);
|
7042 | }
|
7043 | };
|
7044 |
|
7045 | var onrequest = function onrequest() {
|
7046 | stream.req.on('finish', onfinish);
|
7047 | };
|
7048 |
|
7049 | if (isRequest(stream)) {
|
7050 | stream.on('complete', onfinish);
|
7051 | stream.on('abort', onclose);
|
7052 | if (stream.req) onrequest();else stream.on('request', onrequest);
|
7053 | } else if (writable && !stream._writableState) {
|
7054 | // legacy streams
|
7055 | stream.on('end', onlegacyfinish);
|
7056 | stream.on('close', onlegacyfinish);
|
7057 | }
|
7058 |
|
7059 | stream.on('end', onend);
|
7060 | stream.on('finish', onfinish);
|
7061 | if (opts.error !== false) stream.on('error', onerror);
|
7062 | stream.on('close', onclose);
|
7063 | return function () {
|
7064 | stream.removeListener('complete', onfinish);
|
7065 | stream.removeListener('abort', onclose);
|
7066 | stream.removeListener('request', onrequest);
|
7067 | if (stream.req) stream.req.removeListener('finish', onfinish);
|
7068 | stream.removeListener('end', onlegacyfinish);
|
7069 | stream.removeListener('close', onlegacyfinish);
|
7070 | stream.removeListener('finish', onfinish);
|
7071 | stream.removeListener('end', onend);
|
7072 | stream.removeListener('error', onerror);
|
7073 | stream.removeListener('close', onclose);
|
7074 | };
|
7075 | }
|
7076 |
|
7077 | module.exports = eos;
|
7078 | },{"../../../errors":18}],28:[function(require,module,exports){
|
7079 | module.exports = function () {
|
7080 | throw new Error('Readable.from is not available in the browser')
|
7081 | };
|
7082 |
|
7083 | },{}],29:[function(require,module,exports){
|
7084 | // Ported from https://github.com/mafintosh/pump with
|
7085 | // permission from the author, Mathias Buus (@mafintosh).
|
7086 | 'use strict';
|
7087 |
|
7088 | var eos;
|
7089 |
|
7090 | function once(callback) {
|
7091 | var called = false;
|
7092 | return function () {
|
7093 | if (called) return;
|
7094 | called = true;
|
7095 | callback.apply(void 0, arguments);
|
7096 | };
|
7097 | }
|
7098 |
|
7099 | var _require$codes = require('../../../errors').codes,
|
7100 | ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS,
|
7101 | ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED;
|
7102 |
|
7103 | function noop(err) {
|
7104 | // Rethrow the error if it exists to avoid swallowing it
|
7105 | if (err) throw err;
|
7106 | }
|
7107 |
|
7108 | function isRequest(stream) {
|
7109 | return stream.setHeader && typeof stream.abort === 'function';
|
7110 | }
|
7111 |
|
7112 | function destroyer(stream, reading, writing, callback) {
|
7113 | callback = once(callback);
|
7114 | var closed = false;
|
7115 | stream.on('close', function () {
|
7116 | closed = true;
|
7117 | });
|
7118 | if (eos === undefined) eos = require('./end-of-stream');
|
7119 | eos(stream, {
|
7120 | readable: reading,
|
7121 | writable: writing
|
7122 | }, function (err) {
|
7123 | if (err) return callback(err);
|
7124 | closed = true;
|
7125 | callback();
|
7126 | });
|
7127 | var destroyed = false;
|
7128 | return function (err) {
|
7129 | if (closed) return;
|
7130 | if (destroyed) return;
|
7131 | destroyed = true; // request.destroy just do .end - .abort is what we want
|
7132 |
|
7133 | if (isRequest(stream)) return stream.abort();
|
7134 | if (typeof stream.destroy === 'function') return stream.destroy();
|
7135 | callback(err || new ERR_STREAM_DESTROYED('pipe'));
|
7136 | };
|
7137 | }
|
7138 |
|
7139 | function call(fn) {
|
7140 | fn();
|
7141 | }
|
7142 |
|
7143 | function pipe(from, to) {
|
7144 | return from.pipe(to);
|
7145 | }
|
7146 |
|
7147 | function popCallback(streams) {
|
7148 | if (!streams.length) return noop;
|
7149 | if (typeof streams[streams.length - 1] !== 'function') return noop;
|
7150 | return streams.pop();
|
7151 | }
|
7152 |
|
7153 | function pipeline() {
|
7154 | for (var _len = arguments.length, streams = new Array(_len), _key = 0; _key < _len; _key++) {
|
7155 | streams[_key] = arguments[_key];
|
7156 | }
|
7157 |
|
7158 | var callback = popCallback(streams);
|
7159 | if (Array.isArray(streams[0])) streams = streams[0];
|
7160 |
|
7161 | if (streams.length < 2) {
|
7162 | throw new ERR_MISSING_ARGS('streams');
|
7163 | }
|
7164 |
|
7165 | var error;
|
7166 | var destroys = streams.map(function (stream, i) {
|
7167 | var reading = i < streams.length - 1;
|
7168 | var writing = i > 0;
|
7169 | return destroyer(stream, reading, writing, function (err) {
|
7170 | if (!error) error = err;
|
7171 | if (err) destroys.forEach(call);
|
7172 | if (reading) return;
|
7173 | destroys.forEach(call);
|
7174 | callback(error);
|
7175 | });
|
7176 | });
|
7177 | return streams.reduce(pipe);
|
7178 | }
|
7179 |
|
7180 | module.exports = pipeline;
|
7181 | },{"../../../errors":18,"./end-of-stream":27}],30:[function(require,module,exports){
|
7182 | 'use strict';
|
7183 |
|
7184 | var ERR_INVALID_OPT_VALUE = require('../../../errors').codes.ERR_INVALID_OPT_VALUE;
|
7185 |
|
7186 | function highWaterMarkFrom(options, isDuplex, duplexKey) {
|
7187 | return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
|
7188 | }
|
7189 |
|
7190 | function getHighWaterMark(state, options, duplexKey, isDuplex) {
|
7191 | var hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
|
7192 |
|
7193 | if (hwm != null) {
|
7194 | if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
|
7195 | var name = isDuplex ? duplexKey : 'highWaterMark';
|
7196 | throw new ERR_INVALID_OPT_VALUE(name, hwm);
|
7197 | }
|
7198 |
|
7199 | return Math.floor(hwm);
|
7200 | } // Default value
|
7201 |
|
7202 |
|
7203 | return state.objectMode ? 16 : 16 * 1024;
|
7204 | }
|
7205 |
|
7206 | module.exports = {
|
7207 | getHighWaterMark: getHighWaterMark
|
7208 | };
|
7209 | },{"../../../errors":18}],31:[function(require,module,exports){
|
7210 | module.exports = require('events').EventEmitter;
|
7211 |
|
7212 | },{"events":7}],32:[function(require,module,exports){
|
7213 | (function (global){(function (){
|
7214 | var ClientRequest = require('./lib/request')
|
7215 | var response = require('./lib/response')
|
7216 | var extend = require('xtend')
|
7217 | var statusCodes = require('builtin-status-codes')
|
7218 | var url = require('url')
|
7219 |
|
7220 | var http = exports
|
7221 |
|
7222 | http.request = function (opts, cb) {
|
7223 | if (typeof opts === 'string')
|
7224 | opts = url.parse(opts)
|
7225 | else
|
7226 | opts = extend(opts)
|
7227 |
|
7228 | // Normally, the page is loaded from http or https, so not specifying a protocol
|
7229 | // will result in a (valid) protocol-relative url. However, this won't work if
|
7230 | // the protocol is something else, like 'file:'
|
7231 | var defaultProtocol = global.location.protocol.search(/^https?:$/) === -1 ? 'http:' : ''
|
7232 |
|
7233 | var protocol = opts.protocol || defaultProtocol
|
7234 | var host = opts.hostname || opts.host
|
7235 | var port = opts.port
|
7236 | var path = opts.path || '/'
|
7237 |
|
7238 | // Necessary for IPv6 addresses
|
7239 | if (host && host.indexOf(':') !== -1)
|
7240 | host = '[' + host + ']'
|
7241 |
|
7242 | // This may be a relative url. The browser should always be able to interpret it correctly.
|
7243 | opts.url = (host ? (protocol + '//' + host) : '') + (port ? ':' + port : '') + path
|
7244 | opts.method = (opts.method || 'GET').toUpperCase()
|
7245 | opts.headers = opts.headers || {}
|
7246 |
|
7247 | // Also valid opts.auth, opts.mode
|
7248 |
|
7249 | var req = new ClientRequest(opts)
|
7250 | if (cb)
|
7251 | req.on('response', cb)
|
7252 | return req
|
7253 | }
|
7254 |
|
7255 | http.get = function get (opts, cb) {
|
7256 | var req = http.request(opts, cb)
|
7257 | req.end()
|
7258 | return req
|
7259 | }
|
7260 |
|
7261 | http.ClientRequest = ClientRequest
|
7262 | http.IncomingMessage = response.IncomingMessage
|
7263 |
|
7264 | http.Agent = function () {}
|
7265 | http.Agent.defaultMaxSockets = 4
|
7266 |
|
7267 | http.globalAgent = new http.Agent()
|
7268 |
|
7269 | http.STATUS_CODES = statusCodes
|
7270 |
|
7271 | http.METHODS = [
|
7272 | 'CHECKOUT',
|
7273 | 'CONNECT',
|
7274 | 'COPY',
|
7275 | 'DELETE',
|
7276 | 'GET',
|
7277 | 'HEAD',
|
7278 | 'LOCK',
|
7279 | 'M-SEARCH',
|
7280 | 'MERGE',
|
7281 | 'MKACTIVITY',
|
7282 | 'MKCOL',
|
7283 | 'MOVE',
|
7284 | 'NOTIFY',
|
7285 | 'OPTIONS',
|
7286 | 'PATCH',
|
7287 | 'POST',
|
7288 | 'PROPFIND',
|
7289 | 'PROPPATCH',
|
7290 | 'PURGE',
|
7291 | 'PUT',
|
7292 | 'REPORT',
|
7293 | 'SEARCH',
|
7294 | 'SUBSCRIBE',
|
7295 | 'TRACE',
|
7296 | 'UNLOCK',
|
7297 | 'UNSUBSCRIBE'
|
7298 | ]
|
7299 | }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
7300 | },{"./lib/request":34,"./lib/response":35,"builtin-status-codes":6,"url":52,"xtend":55}],33:[function(require,module,exports){
|
7301 | (function (global){(function (){
|
7302 | exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableStream)
|
7303 |
|
7304 | exports.writableStream = isFunction(global.WritableStream)
|
7305 |
|
7306 | exports.abortController = isFunction(global.AbortController)
|
7307 |
|
7308 | // The xhr request to example.com may violate some restrictive CSP configurations,
|
7309 | // so if we're running in a browser that supports `fetch`, avoid calling getXHR()
|
7310 | // and assume support for certain features below.
|
7311 | var xhr
|
7312 | function getXHR () {
|
7313 | // Cache the xhr value
|
7314 | if (xhr !== undefined) return xhr
|
7315 |
|
7316 | if (global.XMLHttpRequest) {
|
7317 | xhr = new global.XMLHttpRequest()
|
7318 | // If XDomainRequest is available (ie only, where xhr might not work
|
7319 | // cross domain), use the page location. Otherwise use example.com
|
7320 | // Note: this doesn't actually make an http request.
|
7321 | try {
|
7322 | xhr.open('GET', global.XDomainRequest ? '/' : 'https://example.com')
|
7323 | } catch(e) {
|
7324 | xhr = null
|
7325 | }
|
7326 | } else {
|
7327 | // Service workers don't have XHR
|
7328 | xhr = null
|
7329 | }
|
7330 | return xhr
|
7331 | }
|
7332 |
|
7333 | function checkTypeSupport (type) {
|
7334 | var xhr = getXHR()
|
7335 | if (!xhr) return false
|
7336 | try {
|
7337 | xhr.responseType = type
|
7338 | return xhr.responseType === type
|
7339 | } catch (e) {}
|
7340 | return false
|
7341 | }
|
7342 |
|
7343 | // If fetch is supported, then arraybuffer will be supported too. Skip calling
|
7344 | // checkTypeSupport(), since that calls getXHR().
|
7345 | exports.arraybuffer = exports.fetch || checkTypeSupport('arraybuffer')
|
7346 |
|
7347 | // These next two tests unavoidably show warnings in Chrome. Since fetch will always
|
7348 | // be used if it's available, just return false for these to avoid the warnings.
|
7349 | exports.msstream = !exports.fetch && checkTypeSupport('ms-stream')
|
7350 | exports.mozchunkedarraybuffer = !exports.fetch && checkTypeSupport('moz-chunked-arraybuffer')
|
7351 |
|
7352 | // If fetch is supported, then overrideMimeType will be supported too. Skip calling
|
7353 | // getXHR().
|
7354 | exports.overrideMimeType = exports.fetch || (getXHR() ? isFunction(getXHR().overrideMimeType) : false)
|
7355 |
|
7356 | function isFunction (value) {
|
7357 | return typeof value === 'function'
|
7358 | }
|
7359 |
|
7360 | xhr = null // Help gc
|
7361 |
|
7362 | }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
7363 | },{}],34:[function(require,module,exports){
|
7364 | (function (process,global,Buffer){(function (){
|
7365 | var capability = require('./capability')
|
7366 | var inherits = require('inherits')
|
7367 | var response = require('./response')
|
7368 | var stream = require('readable-stream')
|
7369 |
|
7370 | var IncomingMessage = response.IncomingMessage
|
7371 | var rStates = response.readyStates
|
7372 |
|
7373 | function decideMode (preferBinary, useFetch) {
|
7374 | if (capability.fetch && useFetch) {
|
7375 | return 'fetch'
|
7376 | } else if (capability.mozchunkedarraybuffer) {
|
7377 | return 'moz-chunked-arraybuffer'
|
7378 | } else if (capability.msstream) {
|
7379 | return 'ms-stream'
|
7380 | } else if (capability.arraybuffer && preferBinary) {
|
7381 | return 'arraybuffer'
|
7382 | } else {
|
7383 | return 'text'
|
7384 | }
|
7385 | }
|
7386 |
|
7387 | var ClientRequest = module.exports = function (opts) {
|
7388 | var self = this
|
7389 | stream.Writable.call(self)
|
7390 |
|
7391 | self._opts = opts
|
7392 | self._body = []
|
7393 | self._headers = {}
|
7394 | if (opts.auth)
|
7395 | self.setHeader('Authorization', 'Basic ' + Buffer.from(opts.auth).toString('base64'))
|
7396 | Object.keys(opts.headers).forEach(function (name) {
|
7397 | self.setHeader(name, opts.headers[name])
|
7398 | })
|
7399 |
|
7400 | var preferBinary
|
7401 | var useFetch = true
|
7402 | if (opts.mode === 'disable-fetch' || ('requestTimeout' in opts && !capability.abortController)) {
|
7403 | // If the use of XHR should be preferred. Not typically needed.
|
7404 | useFetch = false
|
7405 | preferBinary = true
|
7406 | } else if (opts.mode === 'prefer-streaming') {
|
7407 | // If streaming is a high priority but binary compatibility and
|
7408 | // the accuracy of the 'content-type' header aren't
|
7409 | preferBinary = false
|
7410 | } else if (opts.mode === 'allow-wrong-content-type') {
|
7411 | // If streaming is more important than preserving the 'content-type' header
|
7412 | preferBinary = !capability.overrideMimeType
|
7413 | } else if (!opts.mode || opts.mode === 'default' || opts.mode === 'prefer-fast') {
|
7414 | // Use binary if text streaming may corrupt data or the content-type header, or for speed
|
7415 | preferBinary = true
|
7416 | } else {
|
7417 | throw new Error('Invalid value for opts.mode')
|
7418 | }
|
7419 | self._mode = decideMode(preferBinary, useFetch)
|
7420 | self._fetchTimer = null
|
7421 | self._socketTimeout = null
|
7422 | self._socketTimer = null
|
7423 |
|
7424 | self.on('finish', function () {
|
7425 | self._onFinish()
|
7426 | })
|
7427 | }
|
7428 |
|
7429 | inherits(ClientRequest, stream.Writable)
|
7430 |
|
7431 | ClientRequest.prototype.setHeader = function (name, value) {
|
7432 | var self = this
|
7433 | var lowerName = name.toLowerCase()
|
7434 | // This check is not necessary, but it prevents warnings from browsers about setting unsafe
|
7435 | // headers. To be honest I'm not entirely sure hiding these warnings is a good thing, but
|
7436 | // http-browserify did it, so I will too.
|
7437 | if (unsafeHeaders.indexOf(lowerName) !== -1)
|
7438 | return
|
7439 |
|
7440 | self._headers[lowerName] = {
|
7441 | name: name,
|
7442 | value: value
|
7443 | }
|
7444 | }
|
7445 |
|
7446 | ClientRequest.prototype.getHeader = function (name) {
|
7447 | var header = this._headers[name.toLowerCase()]
|
7448 | if (header)
|
7449 | return header.value
|
7450 | return null
|
7451 | }
|
7452 |
|
7453 | ClientRequest.prototype.removeHeader = function (name) {
|
7454 | var self = this
|
7455 | delete self._headers[name.toLowerCase()]
|
7456 | }
|
7457 |
|
7458 | ClientRequest.prototype._onFinish = function () {
|
7459 | var self = this
|
7460 |
|
7461 | if (self._destroyed)
|
7462 | return
|
7463 | var opts = self._opts
|
7464 |
|
7465 | if ('timeout' in opts && opts.timeout !== 0) {
|
7466 | self.setTimeout(opts.timeout)
|
7467 | }
|
7468 |
|
7469 | var headersObj = self._headers
|
7470 | var body = null
|
7471 | if (opts.method !== 'GET' && opts.method !== 'HEAD') {
|
7472 | body = new Blob(self._body, {
|
7473 | type: (headersObj['content-type'] || {}).value || ''
|
7474 | });
|
7475 | }
|
7476 |
|
7477 | // create flattened list of headers
|
7478 | var headersList = []
|
7479 | Object.keys(headersObj).forEach(function (keyName) {
|
7480 | var name = headersObj[keyName].name
|
7481 | var value = headersObj[keyName].value
|
7482 | if (Array.isArray(value)) {
|
7483 | value.forEach(function (v) {
|
7484 | headersList.push([name, v])
|
7485 | })
|
7486 | } else {
|
7487 | headersList.push([name, value])
|
7488 | }
|
7489 | })
|
7490 |
|
7491 | if (self._mode === 'fetch') {
|
7492 | var signal = null
|
7493 | if (capability.abortController) {
|
7494 | var controller = new AbortController()
|
7495 | signal = controller.signal
|
7496 | self._fetchAbortController = controller
|
7497 |
|
7498 | if ('requestTimeout' in opts && opts.requestTimeout !== 0) {
|
7499 | self._fetchTimer = global.setTimeout(function () {
|
7500 | self.emit('requestTimeout')
|
7501 | if (self._fetchAbortController)
|
7502 | self._fetchAbortController.abort()
|
7503 | }, opts.requestTimeout)
|
7504 | }
|
7505 | }
|
7506 |
|
7507 | global.fetch(self._opts.url, {
|
7508 | method: self._opts.method,
|
7509 | headers: headersList,
|
7510 | body: body || undefined,
|
7511 | mode: 'cors',
|
7512 | credentials: opts.withCredentials ? 'include' : 'same-origin',
|
7513 | signal: signal
|
7514 | }).then(function (response) {
|
7515 | self._fetchResponse = response
|
7516 | self._resetTimers(false)
|
7517 | self._connect()
|
7518 | }, function (reason) {
|
7519 | self._resetTimers(true)
|
7520 | if (!self._destroyed)
|
7521 | self.emit('error', reason)
|
7522 | })
|
7523 | } else {
|
7524 | var xhr = self._xhr = new global.XMLHttpRequest()
|
7525 | try {
|
7526 | xhr.open(self._opts.method, self._opts.url, true)
|
7527 | } catch (err) {
|
7528 | process.nextTick(function () {
|
7529 | self.emit('error', err)
|
7530 | })
|
7531 | return
|
7532 | }
|
7533 |
|
7534 | // Can't set responseType on really old browsers
|
7535 | if ('responseType' in xhr)
|
7536 | xhr.responseType = self._mode
|
7537 |
|
7538 | if ('withCredentials' in xhr)
|
7539 | xhr.withCredentials = !!opts.withCredentials
|
7540 |
|
7541 | if (self._mode === 'text' && 'overrideMimeType' in xhr)
|
7542 | xhr.overrideMimeType('text/plain; charset=x-user-defined')
|
7543 |
|
7544 | if ('requestTimeout' in opts) {
|
7545 | xhr.timeout = opts.requestTimeout
|
7546 | xhr.ontimeout = function () {
|
7547 | self.emit('requestTimeout')
|
7548 | }
|
7549 | }
|
7550 |
|
7551 | headersList.forEach(function (header) {
|
7552 | xhr.setRequestHeader(header[0], header[1])
|
7553 | })
|
7554 |
|
7555 | self._response = null
|
7556 | xhr.onreadystatechange = function () {
|
7557 | switch (xhr.readyState) {
|
7558 | case rStates.LOADING:
|
7559 | case rStates.DONE:
|
7560 | self._onXHRProgress()
|
7561 | break
|
7562 | }
|
7563 | }
|
7564 | // Necessary for streaming in Firefox, since xhr.response is ONLY defined
|
7565 | // in onprogress, not in onreadystatechange with xhr.readyState = 3
|
7566 | if (self._mode === 'moz-chunked-arraybuffer') {
|
7567 | xhr.onprogress = function () {
|
7568 | self._onXHRProgress()
|
7569 | }
|
7570 | }
|
7571 |
|
7572 | xhr.onerror = function () {
|
7573 | if (self._destroyed)
|
7574 | return
|
7575 | self._resetTimers(true)
|
7576 | self.emit('error', new Error('XHR error'))
|
7577 | }
|
7578 |
|
7579 | try {
|
7580 | xhr.send(body)
|
7581 | } catch (err) {
|
7582 | process.nextTick(function () {
|
7583 | self.emit('error', err)
|
7584 | })
|
7585 | return
|
7586 | }
|
7587 | }
|
7588 | }
|
7589 |
|
7590 | /**
|
7591 | * Checks if xhr.status is readable and non-zero, indicating no error.
|
7592 | * Even though the spec says it should be available in readyState 3,
|
7593 | * accessing it throws an exception in IE8
|
7594 | */
|
7595 | function statusValid (xhr) {
|
7596 | try {
|
7597 | var status = xhr.status
|
7598 | return (status !== null && status !== 0)
|
7599 | } catch (e) {
|
7600 | return false
|
7601 | }
|
7602 | }
|
7603 |
|
7604 | ClientRequest.prototype._onXHRProgress = function () {
|
7605 | var self = this
|
7606 |
|
7607 | self._resetTimers(false)
|
7608 |
|
7609 | if (!statusValid(self._xhr) || self._destroyed)
|
7610 | return
|
7611 |
|
7612 | if (!self._response)
|
7613 | self._connect()
|
7614 |
|
7615 | self._response._onXHRProgress(self._resetTimers.bind(self))
|
7616 | }
|
7617 |
|
7618 | ClientRequest.prototype._connect = function () {
|
7619 | var self = this
|
7620 |
|
7621 | if (self._destroyed)
|
7622 | return
|
7623 |
|
7624 | self._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode, self._resetTimers.bind(self))
|
7625 | self._response.on('error', function(err) {
|
7626 | self.emit('error', err)
|
7627 | })
|
7628 |
|
7629 | self.emit('response', self._response)
|
7630 | }
|
7631 |
|
7632 | ClientRequest.prototype._write = function (chunk, encoding, cb) {
|
7633 | var self = this
|
7634 |
|
7635 | self._body.push(chunk)
|
7636 | cb()
|
7637 | }
|
7638 |
|
7639 | ClientRequest.prototype._resetTimers = function (done) {
|
7640 | var self = this
|
7641 |
|
7642 | global.clearTimeout(self._socketTimer)
|
7643 | self._socketTimer = null
|
7644 |
|
7645 | if (done) {
|
7646 | global.clearTimeout(self._fetchTimer)
|
7647 | self._fetchTimer = null
|
7648 | } else if (self._socketTimeout) {
|
7649 | self._socketTimer = global.setTimeout(function () {
|
7650 | self.emit('timeout')
|
7651 | }, self._socketTimeout)
|
7652 | }
|
7653 | }
|
7654 |
|
7655 | ClientRequest.prototype.abort = ClientRequest.prototype.destroy = function (err) {
|
7656 | var self = this
|
7657 | self._destroyed = true
|
7658 | self._resetTimers(true)
|
7659 | if (self._response)
|
7660 | self._response._destroyed = true
|
7661 | if (self._xhr)
|
7662 | self._xhr.abort()
|
7663 | else if (self._fetchAbortController)
|
7664 | self._fetchAbortController.abort()
|
7665 |
|
7666 | if (err)
|
7667 | self.emit('error', err)
|
7668 | }
|
7669 |
|
7670 | ClientRequest.prototype.end = function (data, encoding, cb) {
|
7671 | var self = this
|
7672 | if (typeof data === 'function') {
|
7673 | cb = data
|
7674 | data = undefined
|
7675 | }
|
7676 |
|
7677 | stream.Writable.prototype.end.call(self, data, encoding, cb)
|
7678 | }
|
7679 |
|
7680 | ClientRequest.prototype.setTimeout = function (timeout, cb) {
|
7681 | var self = this
|
7682 |
|
7683 | if (cb)
|
7684 | self.once('timeout', cb)
|
7685 |
|
7686 | self._socketTimeout = timeout
|
7687 | self._resetTimers(false)
|
7688 | }
|
7689 |
|
7690 | ClientRequest.prototype.flushHeaders = function () {}
|
7691 | ClientRequest.prototype.setNoDelay = function () {}
|
7692 | ClientRequest.prototype.setSocketKeepAlive = function () {}
|
7693 |
|
7694 | // Taken from http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader%28%29-method
|
7695 | var unsafeHeaders = [
|
7696 | 'accept-charset',
|
7697 | 'accept-encoding',
|
7698 | 'access-control-request-headers',
|
7699 | 'access-control-request-method',
|
7700 | 'connection',
|
7701 | 'content-length',
|
7702 | 'cookie',
|
7703 | 'cookie2',
|
7704 | 'date',
|
7705 | 'dnt',
|
7706 | 'expect',
|
7707 | 'host',
|
7708 | 'keep-alive',
|
7709 | 'origin',
|
7710 | 'referer',
|
7711 | 'te',
|
7712 | 'trailer',
|
7713 | 'transfer-encoding',
|
7714 | 'upgrade',
|
7715 | 'via'
|
7716 | ]
|
7717 |
|
7718 | }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
|
7719 | },{"./capability":33,"./response":35,"_process":11,"buffer":5,"inherits":10,"readable-stream":50}],35:[function(require,module,exports){
|
7720 | (function (process,global,Buffer){(function (){
|
7721 | var capability = require('./capability')
|
7722 | var inherits = require('inherits')
|
7723 | var stream = require('readable-stream')
|
7724 |
|
7725 | var rStates = exports.readyStates = {
|
7726 | UNSENT: 0,
|
7727 | OPENED: 1,
|
7728 | HEADERS_RECEIVED: 2,
|
7729 | LOADING: 3,
|
7730 | DONE: 4
|
7731 | }
|
7732 |
|
7733 | var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode, resetTimers) {
|
7734 | var self = this
|
7735 | stream.Readable.call(self)
|
7736 |
|
7737 | self._mode = mode
|
7738 | self.headers = {}
|
7739 | self.rawHeaders = []
|
7740 | self.trailers = {}
|
7741 | self.rawTrailers = []
|
7742 |
|
7743 | // Fake the 'close' event, but only once 'end' fires
|
7744 | self.on('end', function () {
|
7745 | // The nextTick is necessary to prevent the 'request' module from causing an infinite loop
|
7746 | process.nextTick(function () {
|
7747 | self.emit('close')
|
7748 | })
|
7749 | })
|
7750 |
|
7751 | if (mode === 'fetch') {
|
7752 | self._fetchResponse = response
|
7753 |
|
7754 | self.url = response.url
|
7755 | self.statusCode = response.status
|
7756 | self.statusMessage = response.statusText
|
7757 |
|
7758 | response.headers.forEach(function (header, key){
|
7759 | self.headers[key.toLowerCase()] = header
|
7760 | self.rawHeaders.push(key, header)
|
7761 | })
|
7762 |
|
7763 | if (capability.writableStream) {
|
7764 | var writable = new WritableStream({
|
7765 | write: function (chunk) {
|
7766 | resetTimers(false)
|
7767 | return new Promise(function (resolve, reject) {
|
7768 | if (self._destroyed) {
|
7769 | reject()
|
7770 | } else if(self.push(Buffer.from(chunk))) {
|
7771 | resolve()
|
7772 | } else {
|
7773 | self._resumeFetch = resolve
|
7774 | }
|
7775 | })
|
7776 | },
|
7777 | close: function () {
|
7778 | resetTimers(true)
|
7779 | if (!self._destroyed)
|
7780 | self.push(null)
|
7781 | },
|
7782 | abort: function (err) {
|
7783 | resetTimers(true)
|
7784 | if (!self._destroyed)
|
7785 | self.emit('error', err)
|
7786 | }
|
7787 | })
|
7788 |
|
7789 | try {
|
7790 | response.body.pipeTo(writable).catch(function (err) {
|
7791 | resetTimers(true)
|
7792 | if (!self._destroyed)
|
7793 | self.emit('error', err)
|
7794 | })
|
7795 | return
|
7796 | } catch (e) {} // pipeTo method isn't defined. Can't find a better way to feature test this
|
7797 | }
|
7798 | // fallback for when writableStream or pipeTo aren't available
|
7799 | var reader = response.body.getReader()
|
7800 | function read () {
|
7801 | reader.read().then(function (result) {
|
7802 | if (self._destroyed)
|
7803 | return
|
7804 | resetTimers(result.done)
|
7805 | if (result.done) {
|
7806 | self.push(null)
|
7807 | return
|
7808 | }
|
7809 | self.push(Buffer.from(result.value))
|
7810 | read()
|
7811 | }).catch(function (err) {
|
7812 | resetTimers(true)
|
7813 | if (!self._destroyed)
|
7814 | self.emit('error', err)
|
7815 | })
|
7816 | }
|
7817 | read()
|
7818 | } else {
|
7819 | self._xhr = xhr
|
7820 | self._pos = 0
|
7821 |
|
7822 | self.url = xhr.responseURL
|
7823 | self.statusCode = xhr.status
|
7824 | self.statusMessage = xhr.statusText
|
7825 | var headers = xhr.getAllResponseHeaders().split(/\r?\n/)
|
7826 | headers.forEach(function (header) {
|
7827 | var matches = header.match(/^([^:]+):\s*(.*)/)
|
7828 | if (matches) {
|
7829 | var key = matches[1].toLowerCase()
|
7830 | if (key === 'set-cookie') {
|
7831 | if (self.headers[key] === undefined) {
|
7832 | self.headers[key] = []
|
7833 | }
|
7834 | self.headers[key].push(matches[2])
|
7835 | } else if (self.headers[key] !== undefined) {
|
7836 | self.headers[key] += ', ' + matches[2]
|
7837 | } else {
|
7838 | self.headers[key] = matches[2]
|
7839 | }
|
7840 | self.rawHeaders.push(matches[1], matches[2])
|
7841 | }
|
7842 | })
|
7843 |
|
7844 | self._charset = 'x-user-defined'
|
7845 | if (!capability.overrideMimeType) {
|
7846 | var mimeType = self.rawHeaders['mime-type']
|
7847 | if (mimeType) {
|
7848 | var charsetMatch = mimeType.match(/;\s*charset=([^;])(;|$)/)
|
7849 | if (charsetMatch) {
|
7850 | self._charset = charsetMatch[1].toLowerCase()
|
7851 | }
|
7852 | }
|
7853 | if (!self._charset)
|
7854 | self._charset = 'utf-8' // best guess
|
7855 | }
|
7856 | }
|
7857 | }
|
7858 |
|
7859 | inherits(IncomingMessage, stream.Readable)
|
7860 |
|
7861 | IncomingMessage.prototype._read = function () {
|
7862 | var self = this
|
7863 |
|
7864 | var resolve = self._resumeFetch
|
7865 | if (resolve) {
|
7866 | self._resumeFetch = null
|
7867 | resolve()
|
7868 | }
|
7869 | }
|
7870 |
|
7871 | IncomingMessage.prototype._onXHRProgress = function (resetTimers) {
|
7872 | var self = this
|
7873 |
|
7874 | var xhr = self._xhr
|
7875 |
|
7876 | var response = null
|
7877 | switch (self._mode) {
|
7878 | case 'text':
|
7879 | response = xhr.responseText
|
7880 | if (response.length > self._pos) {
|
7881 | var newData = response.substr(self._pos)
|
7882 | if (self._charset === 'x-user-defined') {
|
7883 | var buffer = Buffer.alloc(newData.length)
|
7884 | for (var i = 0; i < newData.length; i++)
|
7885 | buffer[i] = newData.charCodeAt(i) & 0xff
|
7886 |
|
7887 | self.push(buffer)
|
7888 | } else {
|
7889 | self.push(newData, self._charset)
|
7890 | }
|
7891 | self._pos = response.length
|
7892 | }
|
7893 | break
|
7894 | case 'arraybuffer':
|
7895 | if (xhr.readyState !== rStates.DONE || !xhr.response)
|
7896 | break
|
7897 | response = xhr.response
|
7898 | self.push(Buffer.from(new Uint8Array(response)))
|
7899 | break
|
7900 | case 'moz-chunked-arraybuffer': // take whole
|
7901 | response = xhr.response
|
7902 | if (xhr.readyState !== rStates.LOADING || !response)
|
7903 | break
|
7904 | self.push(Buffer.from(new Uint8Array(response)))
|
7905 | break
|
7906 | case 'ms-stream':
|
7907 | response = xhr.response
|
7908 | if (xhr.readyState !== rStates.LOADING)
|
7909 | break
|
7910 | var reader = new global.MSStreamReader()
|
7911 | reader.onprogress = function () {
|
7912 | if (reader.result.byteLength > self._pos) {
|
7913 | self.push(Buffer.from(new Uint8Array(reader.result.slice(self._pos))))
|
7914 | self._pos = reader.result.byteLength
|
7915 | }
|
7916 | }
|
7917 | reader.onload = function () {
|
7918 | resetTimers(true)
|
7919 | self.push(null)
|
7920 | }
|
7921 | // reader.onerror = ??? // TODO: this
|
7922 | reader.readAsArrayBuffer(response)
|
7923 | break
|
7924 | }
|
7925 |
|
7926 | // The ms-stream case handles end separately in reader.onload()
|
7927 | if (self._xhr.readyState === rStates.DONE && self._mode !== 'ms-stream') {
|
7928 | resetTimers(true)
|
7929 | self.push(null)
|
7930 | }
|
7931 | }
|
7932 |
|
7933 | }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
|
7934 | },{"./capability":33,"_process":11,"buffer":5,"inherits":10,"readable-stream":50}],36:[function(require,module,exports){
|
7935 | arguments[4][18][0].apply(exports,arguments)
|
7936 | },{"dup":18}],37:[function(require,module,exports){
|
7937 | arguments[4][19][0].apply(exports,arguments)
|
7938 | },{"./_stream_readable":39,"./_stream_writable":41,"_process":11,"dup":19,"inherits":10}],38:[function(require,module,exports){
|
7939 | arguments[4][20][0].apply(exports,arguments)
|
7940 | },{"./_stream_transform":40,"dup":20,"inherits":10}],39:[function(require,module,exports){
|
7941 | arguments[4][21][0].apply(exports,arguments)
|
7942 | },{"../errors":36,"./_stream_duplex":37,"./internal/streams/async_iterator":42,"./internal/streams/buffer_list":43,"./internal/streams/destroy":44,"./internal/streams/from":46,"./internal/streams/state":48,"./internal/streams/stream":49,"_process":11,"buffer":5,"dup":21,"events":7,"inherits":10,"string_decoder/":51,"util":4}],40:[function(require,module,exports){
|
7943 | arguments[4][22][0].apply(exports,arguments)
|
7944 | },{"../errors":36,"./_stream_duplex":37,"dup":22,"inherits":10}],41:[function(require,module,exports){
|
7945 | arguments[4][23][0].apply(exports,arguments)
|
7946 | },{"../errors":36,"./_stream_duplex":37,"./internal/streams/destroy":44,"./internal/streams/state":48,"./internal/streams/stream":49,"_process":11,"buffer":5,"dup":23,"inherits":10,"util-deprecate":54}],42:[function(require,module,exports){
|
7947 | arguments[4][24][0].apply(exports,arguments)
|
7948 | },{"./end-of-stream":45,"_process":11,"dup":24}],43:[function(require,module,exports){
|
7949 | arguments[4][25][0].apply(exports,arguments)
|
7950 | },{"buffer":5,"dup":25,"util":4}],44:[function(require,module,exports){
|
7951 | arguments[4][26][0].apply(exports,arguments)
|
7952 | },{"_process":11,"dup":26}],45:[function(require,module,exports){
|
7953 | arguments[4][27][0].apply(exports,arguments)
|
7954 | },{"../../../errors":36,"dup":27}],46:[function(require,module,exports){
|
7955 | arguments[4][28][0].apply(exports,arguments)
|
7956 | },{"dup":28}],47:[function(require,module,exports){
|
7957 | arguments[4][29][0].apply(exports,arguments)
|
7958 | },{"../../../errors":36,"./end-of-stream":45,"dup":29}],48:[function(require,module,exports){
|
7959 | arguments[4][30][0].apply(exports,arguments)
|
7960 | },{"../../../errors":36,"dup":30}],49:[function(require,module,exports){
|
7961 | arguments[4][31][0].apply(exports,arguments)
|
7962 | },{"dup":31,"events":7}],50:[function(require,module,exports){
|
7963 | exports = module.exports = require('./lib/_stream_readable.js');
|
7964 | exports.Stream = exports;
|
7965 | exports.Readable = exports;
|
7966 | exports.Writable = require('./lib/_stream_writable.js');
|
7967 | exports.Duplex = require('./lib/_stream_duplex.js');
|
7968 | exports.Transform = require('./lib/_stream_transform.js');
|
7969 | exports.PassThrough = require('./lib/_stream_passthrough.js');
|
7970 | exports.finished = require('./lib/internal/streams/end-of-stream.js');
|
7971 | exports.pipeline = require('./lib/internal/streams/pipeline.js');
|
7972 |
|
7973 | },{"./lib/_stream_duplex.js":37,"./lib/_stream_passthrough.js":38,"./lib/_stream_readable.js":39,"./lib/_stream_transform.js":40,"./lib/_stream_writable.js":41,"./lib/internal/streams/end-of-stream.js":45,"./lib/internal/streams/pipeline.js":47}],51:[function(require,module,exports){
|
7974 | // Copyright Joyent, Inc. and other Node contributors.
|
7975 | //
|
7976 | // Permission is hereby granted, free of charge, to any person obtaining a
|
7977 | // copy of this software and associated documentation files (the
|
7978 | // "Software"), to deal in the Software without restriction, including
|
7979 | // without limitation the rights to use, copy, modify, merge, publish,
|
7980 | // distribute, sublicense, and/or sell copies of the Software, and to permit
|
7981 | // persons to whom the Software is furnished to do so, subject to the
|
7982 | // following conditions:
|
7983 | //
|
7984 | // The above copyright notice and this permission notice shall be included
|
7985 | // in all copies or substantial portions of the Software.
|
7986 | //
|
7987 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
7988 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
7989 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
7990 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
7991 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
7992 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
7993 | // USE OR OTHER DEALINGS IN THE SOFTWARE.
|
7994 |
|
7995 | 'use strict';
|
7996 |
|
7997 | /*<replacement>*/
|
7998 |
|
7999 | var Buffer = require('safe-buffer').Buffer;
|
8000 | /*</replacement>*/
|
8001 |
|
8002 | var isEncoding = Buffer.isEncoding || function (encoding) {
|
8003 | encoding = '' + encoding;
|
8004 | switch (encoding && encoding.toLowerCase()) {
|
8005 | case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw':
|
8006 | return true;
|
8007 | default:
|
8008 | return false;
|
8009 | }
|
8010 | };
|
8011 |
|
8012 | function _normalizeEncoding(enc) {
|
8013 | if (!enc) return 'utf8';
|
8014 | var retried;
|
8015 | while (true) {
|
8016 | switch (enc) {
|
8017 | case 'utf8':
|
8018 | case 'utf-8':
|
8019 | return 'utf8';
|
8020 | case 'ucs2':
|
8021 | case 'ucs-2':
|
8022 | case 'utf16le':
|
8023 | case 'utf-16le':
|
8024 | return 'utf16le';
|
8025 | case 'latin1':
|
8026 | case 'binary':
|
8027 | return 'latin1';
|
8028 | case 'base64':
|
8029 | case 'ascii':
|
8030 | case 'hex':
|
8031 | return enc;
|
8032 | default:
|
8033 | if (retried) return; // undefined
|
8034 | enc = ('' + enc).toLowerCase();
|
8035 | retried = true;
|
8036 | }
|
8037 | }
|
8038 | };
|
8039 |
|
8040 | // Do not cache `Buffer.isEncoding` when checking encoding names as some
|
8041 | // modules monkey-patch it to support additional encodings
|
8042 | function normalizeEncoding(enc) {
|
8043 | var nenc = _normalizeEncoding(enc);
|
8044 | if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
|
8045 | return nenc || enc;
|
8046 | }
|
8047 |
|
8048 | // StringDecoder provides an interface for efficiently splitting a series of
|
8049 | // buffers into a series of JS strings without breaking apart multi-byte
|
8050 | // characters.
|
8051 | exports.StringDecoder = StringDecoder;
|
8052 | function StringDecoder(encoding) {
|
8053 | this.encoding = normalizeEncoding(encoding);
|
8054 | var nb;
|
8055 | switch (this.encoding) {
|
8056 | case 'utf16le':
|
8057 | this.text = utf16Text;
|
8058 | this.end = utf16End;
|
8059 | nb = 4;
|
8060 | break;
|
8061 | case 'utf8':
|
8062 | this.fillLast = utf8FillLast;
|
8063 | nb = 4;
|
8064 | break;
|
8065 | case 'base64':
|
8066 | this.text = base64Text;
|
8067 | this.end = base64End;
|
8068 | nb = 3;
|
8069 | break;
|
8070 | default:
|
8071 | this.write = simpleWrite;
|
8072 | this.end = simpleEnd;
|
8073 | return;
|
8074 | }
|
8075 | this.lastNeed = 0;
|
8076 | this.lastTotal = 0;
|
8077 | this.lastChar = Buffer.allocUnsafe(nb);
|
8078 | }
|
8079 |
|
8080 | StringDecoder.prototype.write = function (buf) {
|
8081 | if (buf.length === 0) return '';
|
8082 | var r;
|
8083 | var i;
|
8084 | if (this.lastNeed) {
|
8085 | r = this.fillLast(buf);
|
8086 | if (r === undefined) return '';
|
8087 | i = this.lastNeed;
|
8088 | this.lastNeed = 0;
|
8089 | } else {
|
8090 | i = 0;
|
8091 | }
|
8092 | if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
|
8093 | return r || '';
|
8094 | };
|
8095 |
|
8096 | StringDecoder.prototype.end = utf8End;
|
8097 |
|
8098 | // Returns only complete characters in a Buffer
|
8099 | StringDecoder.prototype.text = utf8Text;
|
8100 |
|
8101 | // Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
|
8102 | StringDecoder.prototype.fillLast = function (buf) {
|
8103 | if (this.lastNeed <= buf.length) {
|
8104 | buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
|
8105 | return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
8106 | }
|
8107 | buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
|
8108 | this.lastNeed -= buf.length;
|
8109 | };
|
8110 |
|
8111 | // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
|
8112 | // continuation byte. If an invalid byte is detected, -2 is returned.
|
8113 | function utf8CheckByte(byte) {
|
8114 | if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
|
8115 | return byte >> 6 === 0x02 ? -1 : -2;
|
8116 | }
|
8117 |
|
8118 | // Checks at most 3 bytes at the end of a Buffer in order to detect an
|
8119 | // incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
|
8120 | // needed to complete the UTF-8 character (if applicable) are returned.
|
8121 | function utf8CheckIncomplete(self, buf, i) {
|
8122 | var j = buf.length - 1;
|
8123 | if (j < i) return 0;
|
8124 | var nb = utf8CheckByte(buf[j]);
|
8125 | if (nb >= 0) {
|
8126 | if (nb > 0) self.lastNeed = nb - 1;
|
8127 | return nb;
|
8128 | }
|
8129 | if (--j < i || nb === -2) return 0;
|
8130 | nb = utf8CheckByte(buf[j]);
|
8131 | if (nb >= 0) {
|
8132 | if (nb > 0) self.lastNeed = nb - 2;
|
8133 | return nb;
|
8134 | }
|
8135 | if (--j < i || nb === -2) return 0;
|
8136 | nb = utf8CheckByte(buf[j]);
|
8137 | if (nb >= 0) {
|
8138 | if (nb > 0) {
|
8139 | if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
|
8140 | }
|
8141 | return nb;
|
8142 | }
|
8143 | return 0;
|
8144 | }
|
8145 |
|
8146 | // Validates as many continuation bytes for a multi-byte UTF-8 character as
|
8147 | // needed or are available. If we see a non-continuation byte where we expect
|
8148 | // one, we "replace" the validated continuation bytes we've seen so far with
|
8149 | // a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
|
8150 | // behavior. The continuation byte check is included three times in the case
|
8151 | // where all of the continuation bytes for a character exist in the same buffer.
|
8152 | // It is also done this way as a slight performance increase instead of using a
|
8153 | // loop.
|
8154 | function utf8CheckExtraBytes(self, buf, p) {
|
8155 | if ((buf[0] & 0xC0) !== 0x80) {
|
8156 | self.lastNeed = 0;
|
8157 | return '\ufffd';
|
8158 | }
|
8159 | if (self.lastNeed > 1 && buf.length > 1) {
|
8160 | if ((buf[1] & 0xC0) !== 0x80) {
|
8161 | self.lastNeed = 1;
|
8162 | return '\ufffd';
|
8163 | }
|
8164 | if (self.lastNeed > 2 && buf.length > 2) {
|
8165 | if ((buf[2] & 0xC0) !== 0x80) {
|
8166 | self.lastNeed = 2;
|
8167 | return '\ufffd';
|
8168 | }
|
8169 | }
|
8170 | }
|
8171 | }
|
8172 |
|
8173 | // Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
|
8174 | function utf8FillLast(buf) {
|
8175 | var p = this.lastTotal - this.lastNeed;
|
8176 | var r = utf8CheckExtraBytes(this, buf, p);
|
8177 | if (r !== undefined) return r;
|
8178 | if (this.lastNeed <= buf.length) {
|
8179 | buf.copy(this.lastChar, p, 0, this.lastNeed);
|
8180 | return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
8181 | }
|
8182 | buf.copy(this.lastChar, p, 0, buf.length);
|
8183 | this.lastNeed -= buf.length;
|
8184 | }
|
8185 |
|
8186 | // Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
|
8187 | // partial character, the character's bytes are buffered until the required
|
8188 | // number of bytes are available.
|
8189 | function utf8Text(buf, i) {
|
8190 | var total = utf8CheckIncomplete(this, buf, i);
|
8191 | if (!this.lastNeed) return buf.toString('utf8', i);
|
8192 | this.lastTotal = total;
|
8193 | var end = buf.length - (total - this.lastNeed);
|
8194 | buf.copy(this.lastChar, 0, end);
|
8195 | return buf.toString('utf8', i, end);
|
8196 | }
|
8197 |
|
8198 | // For UTF-8, a replacement character is added when ending on a partial
|
8199 | // character.
|
8200 | function utf8End(buf) {
|
8201 | var r = buf && buf.length ? this.write(buf) : '';
|
8202 | if (this.lastNeed) return r + '\ufffd';
|
8203 | return r;
|
8204 | }
|
8205 |
|
8206 | // UTF-16LE typically needs two bytes per character, but even if we have an even
|
8207 | // number of bytes available, we need to check if we end on a leading/high
|
8208 | // surrogate. In that case, we need to wait for the next two bytes in order to
|
8209 | // decode the last character properly.
|
8210 | function utf16Text(buf, i) {
|
8211 | if ((buf.length - i) % 2 === 0) {
|
8212 | var r = buf.toString('utf16le', i);
|
8213 | if (r) {
|
8214 | var c = r.charCodeAt(r.length - 1);
|
8215 | if (c >= 0xD800 && c <= 0xDBFF) {
|
8216 | this.lastNeed = 2;
|
8217 | this.lastTotal = 4;
|
8218 | this.lastChar[0] = buf[buf.length - 2];
|
8219 | this.lastChar[1] = buf[buf.length - 1];
|
8220 | return r.slice(0, -1);
|
8221 | }
|
8222 | }
|
8223 | return r;
|
8224 | }
|
8225 | this.lastNeed = 1;
|
8226 | this.lastTotal = 2;
|
8227 | this.lastChar[0] = buf[buf.length - 1];
|
8228 | return buf.toString('utf16le', i, buf.length - 1);
|
8229 | }
|
8230 |
|
8231 | // For UTF-16LE we do not explicitly append special replacement characters if we
|
8232 | // end on a partial character, we simply let v8 handle that.
|
8233 | function utf16End(buf) {
|
8234 | var r = buf && buf.length ? this.write(buf) : '';
|
8235 | if (this.lastNeed) {
|
8236 | var end = this.lastTotal - this.lastNeed;
|
8237 | return r + this.lastChar.toString('utf16le', 0, end);
|
8238 | }
|
8239 | return r;
|
8240 | }
|
8241 |
|
8242 | function base64Text(buf, i) {
|
8243 | var n = (buf.length - i) % 3;
|
8244 | if (n === 0) return buf.toString('base64', i);
|
8245 | this.lastNeed = 3 - n;
|
8246 | this.lastTotal = 3;
|
8247 | if (n === 1) {
|
8248 | this.lastChar[0] = buf[buf.length - 1];
|
8249 | } else {
|
8250 | this.lastChar[0] = buf[buf.length - 2];
|
8251 | this.lastChar[1] = buf[buf.length - 1];
|
8252 | }
|
8253 | return buf.toString('base64', i, buf.length - n);
|
8254 | }
|
8255 |
|
8256 | function base64End(buf) {
|
8257 | var r = buf && buf.length ? this.write(buf) : '';
|
8258 | if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
|
8259 | return r;
|
8260 | }
|
8261 |
|
8262 | // Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
|
8263 | function simpleWrite(buf) {
|
8264 | return buf.toString(this.encoding);
|
8265 | }
|
8266 |
|
8267 | function simpleEnd(buf) {
|
8268 | return buf && buf.length ? this.write(buf) : '';
|
8269 | }
|
8270 | },{"safe-buffer":16}],52:[function(require,module,exports){
|
8271 | // Copyright Joyent, Inc. and other Node contributors.
|
8272 | //
|
8273 | // Permission is hereby granted, free of charge, to any person obtaining a
|
8274 | // copy of this software and associated documentation files (the
|
8275 | // "Software"), to deal in the Software without restriction, including
|
8276 | // without limitation the rights to use, copy, modify, merge, publish,
|
8277 | // distribute, sublicense, and/or sell copies of the Software, and to permit
|
8278 | // persons to whom the Software is furnished to do so, subject to the
|
8279 | // following conditions:
|
8280 | //
|
8281 | // The above copyright notice and this permission notice shall be included
|
8282 | // in all copies or substantial portions of the Software.
|
8283 | //
|
8284 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
8285 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
8286 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
8287 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
8288 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
8289 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
8290 | // USE OR OTHER DEALINGS IN THE SOFTWARE.
|
8291 |
|
8292 | 'use strict';
|
8293 |
|
8294 | var punycode = require('punycode');
|
8295 | var util = require('./util');
|
8296 |
|
8297 | exports.parse = urlParse;
|
8298 | exports.resolve = urlResolve;
|
8299 | exports.resolveObject = urlResolveObject;
|
8300 | exports.format = urlFormat;
|
8301 |
|
8302 | exports.Url = Url;
|
8303 |
|
8304 | function Url() {
|
8305 | this.protocol = null;
|
8306 | this.slashes = null;
|
8307 | this.auth = null;
|
8308 | this.host = null;
|
8309 | this.port = null;
|
8310 | this.hostname = null;
|
8311 | this.hash = null;
|
8312 | this.search = null;
|
8313 | this.query = null;
|
8314 | this.pathname = null;
|
8315 | this.path = null;
|
8316 | this.href = null;
|
8317 | }
|
8318 |
|
8319 | // Reference: RFC 3986, RFC 1808, RFC 2396
|
8320 |
|
8321 | // define these here so at least they only have to be
|
8322 | // compiled once on the first module load.
|
8323 | var protocolPattern = /^([a-z0-9.+-]+:)/i,
|
8324 | portPattern = /:[0-9]*$/,
|
8325 |
|
8326 | // Special case for a simple path URL
|
8327 | simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
|
8328 |
|
8329 | // RFC 2396: characters reserved for delimiting URLs.
|
8330 | // We actually just auto-escape these.
|
8331 | delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
|
8332 |
|
8333 | // RFC 2396: characters not allowed for various reasons.
|
8334 | unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
|
8335 |
|
8336 | // Allowed by RFCs, but cause of XSS attacks. Always escape these.
|
8337 | autoEscape = ['\''].concat(unwise),
|
8338 | // Characters that are never ever allowed in a hostname.
|
8339 | // Note that any invalid chars are also handled, but these
|
8340 | // are the ones that are *expected* to be seen, so we fast-path
|
8341 | // them.
|
8342 | nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
|
8343 | hostEndingChars = ['/', '?', '#'],
|
8344 | hostnameMaxLen = 255,
|
8345 | hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
|
8346 | hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
|
8347 | // protocols that can allow "unsafe" and "unwise" chars.
|
8348 | unsafeProtocol = {
|
8349 | 'javascript': true,
|
8350 | 'javascript:': true
|
8351 | },
|
8352 | // protocols that never have a hostname.
|
8353 | hostlessProtocol = {
|
8354 | 'javascript': true,
|
8355 | 'javascript:': true
|
8356 | },
|
8357 | // protocols that always contain a // bit.
|
8358 | slashedProtocol = {
|
8359 | 'http': true,
|
8360 | 'https': true,
|
8361 | 'ftp': true,
|
8362 | 'gopher': true,
|
8363 | 'file': true,
|
8364 | 'http:': true,
|
8365 | 'https:': true,
|
8366 | 'ftp:': true,
|
8367 | 'gopher:': true,
|
8368 | 'file:': true
|
8369 | },
|
8370 | querystring = require('querystring');
|
8371 |
|
8372 | function urlParse(url, parseQueryString, slashesDenoteHost) {
|
8373 | if (url && util.isObject(url) && url instanceof Url) return url;
|
8374 |
|
8375 | var u = new Url;
|
8376 | u.parse(url, parseQueryString, slashesDenoteHost);
|
8377 | return u;
|
8378 | }
|
8379 |
|
8380 | Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
8381 | if (!util.isString(url)) {
|
8382 | throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
|
8383 | }
|
8384 |
|
8385 | // Copy chrome, IE, opera backslash-handling behavior.
|
8386 | // Back slashes before the query string get converted to forward slashes
|
8387 | // See: https://code.google.com/p/chromium/issues/detail?id=25916
|
8388 | var queryIndex = url.indexOf('?'),
|
8389 | splitter =
|
8390 | (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
|
8391 | uSplit = url.split(splitter),
|
8392 | slashRegex = /\\/g;
|
8393 | uSplit[0] = uSplit[0].replace(slashRegex, '/');
|
8394 | url = uSplit.join(splitter);
|
8395 |
|
8396 | var rest = url;
|
8397 |
|
8398 | // trim before proceeding.
|
8399 | // This is to support parse stuff like " http://foo.com \n"
|
8400 | rest = rest.trim();
|
8401 |
|
8402 | if (!slashesDenoteHost && url.split('#').length === 1) {
|
8403 | // Try fast path regexp
|
8404 | var simplePath = simplePathPattern.exec(rest);
|
8405 | if (simplePath) {
|
8406 | this.path = rest;
|
8407 | this.href = rest;
|
8408 | this.pathname = simplePath[1];
|
8409 | if (simplePath[2]) {
|
8410 | this.search = simplePath[2];
|
8411 | if (parseQueryString) {
|
8412 | this.query = querystring.parse(this.search.substr(1));
|
8413 | } else {
|
8414 | this.query = this.search.substr(1);
|
8415 | }
|
8416 | } else if (parseQueryString) {
|
8417 | this.search = '';
|
8418 | this.query = {};
|
8419 | }
|
8420 | return this;
|
8421 | }
|
8422 | }
|
8423 |
|
8424 | var proto = protocolPattern.exec(rest);
|
8425 | if (proto) {
|
8426 | proto = proto[0];
|
8427 | var lowerProto = proto.toLowerCase();
|
8428 | this.protocol = lowerProto;
|
8429 | rest = rest.substr(proto.length);
|
8430 | }
|
8431 |
|
8432 | // figure out if it's got a host
|
8433 | // user@server is *always* interpreted as a hostname, and url
|
8434 | // resolution will treat //foo/bar as host=foo,path=bar because that's
|
8435 | // how the browser resolves relative URLs.
|
8436 | if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
|
8437 | var slashes = rest.substr(0, 2) === '//';
|
8438 | if (slashes && !(proto && hostlessProtocol[proto])) {
|
8439 | rest = rest.substr(2);
|
8440 | this.slashes = true;
|
8441 | }
|
8442 | }
|
8443 |
|
8444 | if (!hostlessProtocol[proto] &&
|
8445 | (slashes || (proto && !slashedProtocol[proto]))) {
|
8446 |
|
8447 | // there's a hostname.
|
8448 | // the first instance of /, ?, ;, or # ends the host.
|
8449 | //
|
8450 | // If there is an @ in the hostname, then non-host chars *are* allowed
|
8451 | // to the left of the last @ sign, unless some host-ending character
|
8452 | // comes *before* the @-sign.
|
8453 | // URLs are obnoxious.
|
8454 | //
|
8455 | // ex:
|
8456 | // http://a@b@c/ => user:a@b host:c
|
8457 | // http://a@b?@c => user:a host:c path:/?@c
|
8458 |
|
8459 | // v0.12 TODO(isaacs): This is not quite how Chrome does things.
|
8460 | // Review our test case against browsers more comprehensively.
|
8461 |
|
8462 | // find the first instance of any hostEndingChars
|
8463 | var hostEnd = -1;
|
8464 | for (var i = 0; i < hostEndingChars.length; i++) {
|
8465 | var hec = rest.indexOf(hostEndingChars[i]);
|
8466 | if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
|
8467 | hostEnd = hec;
|
8468 | }
|
8469 |
|
8470 | // at this point, either we have an explicit point where the
|
8471 | // auth portion cannot go past, or the last @ char is the decider.
|
8472 | var auth, atSign;
|
8473 | if (hostEnd === -1) {
|
8474 | // atSign can be anywhere.
|
8475 | atSign = rest.lastIndexOf('@');
|
8476 | } else {
|
8477 | // atSign must be in auth portion.
|
8478 | // http://a@b/c@d => host:b auth:a path:/c@d
|
8479 | atSign = rest.lastIndexOf('@', hostEnd);
|
8480 | }
|
8481 |
|
8482 | // Now we have a portion which is definitely the auth.
|
8483 | // Pull that off.
|
8484 | if (atSign !== -1) {
|
8485 | auth = rest.slice(0, atSign);
|
8486 | rest = rest.slice(atSign + 1);
|
8487 | this.auth = decodeURIComponent(auth);
|
8488 | }
|
8489 |
|
8490 | // the host is the remaining to the left of the first non-host char
|
8491 | hostEnd = -1;
|
8492 | for (var i = 0; i < nonHostChars.length; i++) {
|
8493 | var hec = rest.indexOf(nonHostChars[i]);
|
8494 | if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
|
8495 | hostEnd = hec;
|
8496 | }
|
8497 | // if we still have not hit it, then the entire thing is a host.
|
8498 | if (hostEnd === -1)
|
8499 | hostEnd = rest.length;
|
8500 |
|
8501 | this.host = rest.slice(0, hostEnd);
|
8502 | rest = rest.slice(hostEnd);
|
8503 |
|
8504 | // pull out port.
|
8505 | this.parseHost();
|
8506 |
|
8507 | // we've indicated that there is a hostname,
|
8508 | // so even if it's empty, it has to be present.
|
8509 | this.hostname = this.hostname || '';
|
8510 |
|
8511 | // if hostname begins with [ and ends with ]
|
8512 | // assume that it's an IPv6 address.
|
8513 | var ipv6Hostname = this.hostname[0] === '[' &&
|
8514 | this.hostname[this.hostname.length - 1] === ']';
|
8515 |
|
8516 | // validate a little.
|
8517 | if (!ipv6Hostname) {
|
8518 | var hostparts = this.hostname.split(/\./);
|
8519 | for (var i = 0, l = hostparts.length; i < l; i++) {
|
8520 | var part = hostparts[i];
|
8521 | if (!part) continue;
|
8522 | if (!part.match(hostnamePartPattern)) {
|
8523 | var newpart = '';
|
8524 | for (var j = 0, k = part.length; j < k; j++) {
|
8525 | if (part.charCodeAt(j) > 127) {
|
8526 | // we replace non-ASCII char with a temporary placeholder
|
8527 | // we need this to make sure size of hostname is not
|
8528 | // broken by replacing non-ASCII by nothing
|
8529 | newpart += 'x';
|
8530 | } else {
|
8531 | newpart += part[j];
|
8532 | }
|
8533 | }
|
8534 | // we test again with ASCII char only
|
8535 | if (!newpart.match(hostnamePartPattern)) {
|
8536 | var validParts = hostparts.slice(0, i);
|
8537 | var notHost = hostparts.slice(i + 1);
|
8538 | var bit = part.match(hostnamePartStart);
|
8539 | if (bit) {
|
8540 | validParts.push(bit[1]);
|
8541 | notHost.unshift(bit[2]);
|
8542 | }
|
8543 | if (notHost.length) {
|
8544 | rest = '/' + notHost.join('.') + rest;
|
8545 | }
|
8546 | this.hostname = validParts.join('.');
|
8547 | break;
|
8548 | }
|
8549 | }
|
8550 | }
|
8551 | }
|
8552 |
|
8553 | if (this.hostname.length > hostnameMaxLen) {
|
8554 | this.hostname = '';
|
8555 | } else {
|
8556 | // hostnames are always lower case.
|
8557 | this.hostname = this.hostname.toLowerCase();
|
8558 | }
|
8559 |
|
8560 | if (!ipv6Hostname) {
|
8561 | // IDNA Support: Returns a punycoded representation of "domain".
|
8562 | // It only converts parts of the domain name that
|
8563 | // have non-ASCII characters, i.e. it doesn't matter if
|
8564 | // you call it with a domain that already is ASCII-only.
|
8565 | this.hostname = punycode.toASCII(this.hostname);
|
8566 | }
|
8567 |
|
8568 | var p = this.port ? ':' + this.port : '';
|
8569 | var h = this.hostname || '';
|
8570 | this.host = h + p;
|
8571 | this.href += this.host;
|
8572 |
|
8573 | // strip [ and ] from the hostname
|
8574 | // the host field still retains them, though
|
8575 | if (ipv6Hostname) {
|
8576 | this.hostname = this.hostname.substr(1, this.hostname.length - 2);
|
8577 | if (rest[0] !== '/') {
|
8578 | rest = '/' + rest;
|
8579 | }
|
8580 | }
|
8581 | }
|
8582 |
|
8583 | // now rest is set to the post-host stuff.
|
8584 | // chop off any delim chars.
|
8585 | if (!unsafeProtocol[lowerProto]) {
|
8586 |
|
8587 | // First, make 100% sure that any "autoEscape" chars get
|
8588 | // escaped, even if encodeURIComponent doesn't think they
|
8589 | // need to be.
|
8590 | for (var i = 0, l = autoEscape.length; i < l; i++) {
|
8591 | var ae = autoEscape[i];
|
8592 | if (rest.indexOf(ae) === -1)
|
8593 | continue;
|
8594 | var esc = encodeURIComponent(ae);
|
8595 | if (esc === ae) {
|
8596 | esc = escape(ae);
|
8597 | }
|
8598 | rest = rest.split(ae).join(esc);
|
8599 | }
|
8600 | }
|
8601 |
|
8602 |
|
8603 | // chop off from the tail first.
|
8604 | var hash = rest.indexOf('#');
|
8605 | if (hash !== -1) {
|
8606 | // got a fragment string.
|
8607 | this.hash = rest.substr(hash);
|
8608 | rest = rest.slice(0, hash);
|
8609 | }
|
8610 | var qm = rest.indexOf('?');
|
8611 | if (qm !== -1) {
|
8612 | this.search = rest.substr(qm);
|
8613 | this.query = rest.substr(qm + 1);
|
8614 | if (parseQueryString) {
|
8615 | this.query = querystring.parse(this.query);
|
8616 | }
|
8617 | rest = rest.slice(0, qm);
|
8618 | } else if (parseQueryString) {
|
8619 | // no query string, but parseQueryString still requested
|
8620 | this.search = '';
|
8621 | this.query = {};
|
8622 | }
|
8623 | if (rest) this.pathname = rest;
|
8624 | if (slashedProtocol[lowerProto] &&
|
8625 | this.hostname && !this.pathname) {
|
8626 | this.pathname = '/';
|
8627 | }
|
8628 |
|
8629 | //to support http.request
|
8630 | if (this.pathname || this.search) {
|
8631 | var p = this.pathname || '';
|
8632 | var s = this.search || '';
|
8633 | this.path = p + s;
|
8634 | }
|
8635 |
|
8636 | // finally, reconstruct the href based on what has been validated.
|
8637 | this.href = this.format();
|
8638 | return this;
|
8639 | };
|
8640 |
|
8641 | // format a parsed object into a url string
|
8642 | function urlFormat(obj) {
|
8643 | // ensure it's an object, and not a string url.
|
8644 | // If it's an obj, this is a no-op.
|
8645 | // this way, you can call url_format() on strings
|
8646 | // to clean up potentially wonky urls.
|
8647 | if (util.isString(obj)) obj = urlParse(obj);
|
8648 | if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
|
8649 | return obj.format();
|
8650 | }
|
8651 |
|
8652 | Url.prototype.format = function() {
|
8653 | var auth = this.auth || '';
|
8654 | if (auth) {
|
8655 | auth = encodeURIComponent(auth);
|
8656 | auth = auth.replace(/%3A/i, ':');
|
8657 | auth += '@';
|
8658 | }
|
8659 |
|
8660 | var protocol = this.protocol || '',
|
8661 | pathname = this.pathname || '',
|
8662 | hash = this.hash || '',
|
8663 | host = false,
|
8664 | query = '';
|
8665 |
|
8666 | if (this.host) {
|
8667 | host = auth + this.host;
|
8668 | } else if (this.hostname) {
|
8669 | host = auth + (this.hostname.indexOf(':') === -1 ?
|
8670 | this.hostname :
|
8671 | '[' + this.hostname + ']');
|
8672 | if (this.port) {
|
8673 | host += ':' + this.port;
|
8674 | }
|
8675 | }
|
8676 |
|
8677 | if (this.query &&
|
8678 | util.isObject(this.query) &&
|
8679 | Object.keys(this.query).length) {
|
8680 | query = querystring.stringify(this.query);
|
8681 | }
|
8682 |
|
8683 | var search = this.search || (query && ('?' + query)) || '';
|
8684 |
|
8685 | if (protocol && protocol.substr(-1) !== ':') protocol += ':';
|
8686 |
|
8687 | // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
|
8688 | // unless they had them to begin with.
|
8689 | if (this.slashes ||
|
8690 | (!protocol || slashedProtocol[protocol]) && host !== false) {
|
8691 | host = '//' + (host || '');
|
8692 | if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
|
8693 | } else if (!host) {
|
8694 | host = '';
|
8695 | }
|
8696 |
|
8697 | if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
|
8698 | if (search && search.charAt(0) !== '?') search = '?' + search;
|
8699 |
|
8700 | pathname = pathname.replace(/[?#]/g, function(match) {
|
8701 | return encodeURIComponent(match);
|
8702 | });
|
8703 | search = search.replace('#', '%23');
|
8704 |
|
8705 | return protocol + host + pathname + search + hash;
|
8706 | };
|
8707 |
|
8708 | function urlResolve(source, relative) {
|
8709 | return urlParse(source, false, true).resolve(relative);
|
8710 | }
|
8711 |
|
8712 | Url.prototype.resolve = function(relative) {
|
8713 | return this.resolveObject(urlParse(relative, false, true)).format();
|
8714 | };
|
8715 |
|
8716 | function urlResolveObject(source, relative) {
|
8717 | if (!source) return relative;
|
8718 | return urlParse(source, false, true).resolveObject(relative);
|
8719 | }
|
8720 |
|
8721 | Url.prototype.resolveObject = function(relative) {
|
8722 | if (util.isString(relative)) {
|
8723 | var rel = new Url();
|
8724 | rel.parse(relative, false, true);
|
8725 | relative = rel;
|
8726 | }
|
8727 |
|
8728 | var result = new Url();
|
8729 | var tkeys = Object.keys(this);
|
8730 | for (var tk = 0; tk < tkeys.length; tk++) {
|
8731 | var tkey = tkeys[tk];
|
8732 | result[tkey] = this[tkey];
|
8733 | }
|
8734 |
|
8735 | // hash is always overridden, no matter what.
|
8736 | // even href="" will remove it.
|
8737 | result.hash = relative.hash;
|
8738 |
|
8739 | // if the relative url is empty, then there's nothing left to do here.
|
8740 | if (relative.href === '') {
|
8741 | result.href = result.format();
|
8742 | return result;
|
8743 | }
|
8744 |
|
8745 | // hrefs like //foo/bar always cut to the protocol.
|
8746 | if (relative.slashes && !relative.protocol) {
|
8747 | // take everything except the protocol from relative
|
8748 | var rkeys = Object.keys(relative);
|
8749 | for (var rk = 0; rk < rkeys.length; rk++) {
|
8750 | var rkey = rkeys[rk];
|
8751 | if (rkey !== 'protocol')
|
8752 | result[rkey] = relative[rkey];
|
8753 | }
|
8754 |
|
8755 | //urlParse appends trailing / to urls like http://www.example.com
|
8756 | if (slashedProtocol[result.protocol] &&
|
8757 | result.hostname && !result.pathname) {
|
8758 | result.path = result.pathname = '/';
|
8759 | }
|
8760 |
|
8761 | result.href = result.format();
|
8762 | return result;
|
8763 | }
|
8764 |
|
8765 | if (relative.protocol && relative.protocol !== result.protocol) {
|
8766 | // if it's a known url protocol, then changing
|
8767 | // the protocol does weird things
|
8768 | // first, if it's not file:, then we MUST have a host,
|
8769 | // and if there was a path
|
8770 | // to begin with, then we MUST have a path.
|
8771 | // if it is file:, then the host is dropped,
|
8772 | // because that's known to be hostless.
|
8773 | // anything else is assumed to be absolute.
|
8774 | if (!slashedProtocol[relative.protocol]) {
|
8775 | var keys = Object.keys(relative);
|
8776 | for (var v = 0; v < keys.length; v++) {
|
8777 | var k = keys[v];
|
8778 | result[k] = relative[k];
|
8779 | }
|
8780 | result.href = result.format();
|
8781 | return result;
|
8782 | }
|
8783 |
|
8784 | result.protocol = relative.protocol;
|
8785 | if (!relative.host && !hostlessProtocol[relative.protocol]) {
|
8786 | var relPath = (relative.pathname || '').split('/');
|
8787 | while (relPath.length && !(relative.host = relPath.shift()));
|
8788 | if (!relative.host) relative.host = '';
|
8789 | if (!relative.hostname) relative.hostname = '';
|
8790 | if (relPath[0] !== '') relPath.unshift('');
|
8791 | if (relPath.length < 2) relPath.unshift('');
|
8792 | result.pathname = relPath.join('/');
|
8793 | } else {
|
8794 | result.pathname = relative.pathname;
|
8795 | }
|
8796 | result.search = relative.search;
|
8797 | result.query = relative.query;
|
8798 | result.host = relative.host || '';
|
8799 | result.auth = relative.auth;
|
8800 | result.hostname = relative.hostname || relative.host;
|
8801 | result.port = relative.port;
|
8802 | // to support http.request
|
8803 | if (result.pathname || result.search) {
|
8804 | var p = result.pathname || '';
|
8805 | var s = result.search || '';
|
8806 | result.path = p + s;
|
8807 | }
|
8808 | result.slashes = result.slashes || relative.slashes;
|
8809 | result.href = result.format();
|
8810 | return result;
|
8811 | }
|
8812 |
|
8813 | var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
|
8814 | isRelAbs = (
|
8815 | relative.host ||
|
8816 | relative.pathname && relative.pathname.charAt(0) === '/'
|
8817 | ),
|
8818 | mustEndAbs = (isRelAbs || isSourceAbs ||
|
8819 | (result.host && relative.pathname)),
|
8820 | removeAllDots = mustEndAbs,
|
8821 | srcPath = result.pathname && result.pathname.split('/') || [],
|
8822 | relPath = relative.pathname && relative.pathname.split('/') || [],
|
8823 | psychotic = result.protocol && !slashedProtocol[result.protocol];
|
8824 |
|
8825 | // if the url is a non-slashed url, then relative
|
8826 | // links like ../.. should be able
|
8827 | // to crawl up to the hostname, as well. This is strange.
|
8828 | // result.protocol has already been set by now.
|
8829 | // Later on, put the first path part into the host field.
|
8830 | if (psychotic) {
|
8831 | result.hostname = '';
|
8832 | result.port = null;
|
8833 | if (result.host) {
|
8834 | if (srcPath[0] === '') srcPath[0] = result.host;
|
8835 | else srcPath.unshift(result.host);
|
8836 | }
|
8837 | result.host = '';
|
8838 | if (relative.protocol) {
|
8839 | relative.hostname = null;
|
8840 | relative.port = null;
|
8841 | if (relative.host) {
|
8842 | if (relPath[0] === '') relPath[0] = relative.host;
|
8843 | else relPath.unshift(relative.host);
|
8844 | }
|
8845 | relative.host = null;
|
8846 | }
|
8847 | mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
|
8848 | }
|
8849 |
|
8850 | if (isRelAbs) {
|
8851 | // it's absolute.
|
8852 | result.host = (relative.host || relative.host === '') ?
|
8853 | relative.host : result.host;
|
8854 | result.hostname = (relative.hostname || relative.hostname === '') ?
|
8855 | relative.hostname : result.hostname;
|
8856 | result.search = relative.search;
|
8857 | result.query = relative.query;
|
8858 | srcPath = relPath;
|
8859 | // fall through to the dot-handling below.
|
8860 | } else if (relPath.length) {
|
8861 | // it's relative
|
8862 | // throw away the existing file, and take the new path instead.
|
8863 | if (!srcPath) srcPath = [];
|
8864 | srcPath.pop();
|
8865 | srcPath = srcPath.concat(relPath);
|
8866 | result.search = relative.search;
|
8867 | result.query = relative.query;
|
8868 | } else if (!util.isNullOrUndefined(relative.search)) {
|
8869 | // just pull out the search.
|
8870 | // like href='?foo'.
|
8871 | // Put this after the other two cases because it simplifies the booleans
|
8872 | if (psychotic) {
|
8873 | result.hostname = result.host = srcPath.shift();
|
8874 | //occationaly the auth can get stuck only in host
|
8875 | //this especially happens in cases like
|
8876 | //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
|
8877 | var authInHost = result.host && result.host.indexOf('@') > 0 ?
|
8878 | result.host.split('@') : false;
|
8879 | if (authInHost) {
|
8880 | result.auth = authInHost.shift();
|
8881 | result.host = result.hostname = authInHost.shift();
|
8882 | }
|
8883 | }
|
8884 | result.search = relative.search;
|
8885 | result.query = relative.query;
|
8886 | //to support http.request
|
8887 | if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
|
8888 | result.path = (result.pathname ? result.pathname : '') +
|
8889 | (result.search ? result.search : '');
|
8890 | }
|
8891 | result.href = result.format();
|
8892 | return result;
|
8893 | }
|
8894 |
|
8895 | if (!srcPath.length) {
|
8896 | // no path at all. easy.
|
8897 | // we've already handled the other stuff above.
|
8898 | result.pathname = null;
|
8899 | //to support http.request
|
8900 | if (result.search) {
|
8901 | result.path = '/' + result.search;
|
8902 | } else {
|
8903 | result.path = null;
|
8904 | }
|
8905 | result.href = result.format();
|
8906 | return result;
|
8907 | }
|
8908 |
|
8909 | // if a url ENDs in . or .., then it must get a trailing slash.
|
8910 | // however, if it ends in anything else non-slashy,
|
8911 | // then it must NOT get a trailing slash.
|
8912 | var last = srcPath.slice(-1)[0];
|
8913 | var hasTrailingSlash = (
|
8914 | (result.host || relative.host || srcPath.length > 1) &&
|
8915 | (last === '.' || last === '..') || last === '');
|
8916 |
|
8917 | // strip single dots, resolve double dots to parent dir
|
8918 | // if the path tries to go above the root, `up` ends up > 0
|
8919 | var up = 0;
|
8920 | for (var i = srcPath.length; i >= 0; i--) {
|
8921 | last = srcPath[i];
|
8922 | if (last === '.') {
|
8923 | srcPath.splice(i, 1);
|
8924 | } else if (last === '..') {
|
8925 | srcPath.splice(i, 1);
|
8926 | up++;
|
8927 | } else if (up) {
|
8928 | srcPath.splice(i, 1);
|
8929 | up--;
|
8930 | }
|
8931 | }
|
8932 |
|
8933 | // if the path is allowed to go above the root, restore leading ..s
|
8934 | if (!mustEndAbs && !removeAllDots) {
|
8935 | for (; up--; up) {
|
8936 | srcPath.unshift('..');
|
8937 | }
|
8938 | }
|
8939 |
|
8940 | if (mustEndAbs && srcPath[0] !== '' &&
|
8941 | (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
|
8942 | srcPath.unshift('');
|
8943 | }
|
8944 |
|
8945 | if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
|
8946 | srcPath.push('');
|
8947 | }
|
8948 |
|
8949 | var isAbsolute = srcPath[0] === '' ||
|
8950 | (srcPath[0] && srcPath[0].charAt(0) === '/');
|
8951 |
|
8952 | // put the host back
|
8953 | if (psychotic) {
|
8954 | result.hostname = result.host = isAbsolute ? '' :
|
8955 | srcPath.length ? srcPath.shift() : '';
|
8956 | //occationaly the auth can get stuck only in host
|
8957 | //this especially happens in cases like
|
8958 | //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
|
8959 | var authInHost = result.host && result.host.indexOf('@') > 0 ?
|
8960 | result.host.split('@') : false;
|
8961 | if (authInHost) {
|
8962 | result.auth = authInHost.shift();
|
8963 | result.host = result.hostname = authInHost.shift();
|
8964 | }
|
8965 | }
|
8966 |
|
8967 | mustEndAbs = mustEndAbs || (result.host && srcPath.length);
|
8968 |
|
8969 | if (mustEndAbs && !isAbsolute) {
|
8970 | srcPath.unshift('');
|
8971 | }
|
8972 |
|
8973 | if (!srcPath.length) {
|
8974 | result.pathname = null;
|
8975 | result.path = null;
|
8976 | } else {
|
8977 | result.pathname = srcPath.join('/');
|
8978 | }
|
8979 |
|
8980 | //to support request.http
|
8981 | if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
|
8982 | result.path = (result.pathname ? result.pathname : '') +
|
8983 | (result.search ? result.search : '');
|
8984 | }
|
8985 | result.auth = relative.auth || result.auth;
|
8986 | result.slashes = result.slashes || relative.slashes;
|
8987 | result.href = result.format();
|
8988 | return result;
|
8989 | };
|
8990 |
|
8991 | Url.prototype.parseHost = function() {
|
8992 | var host = this.host;
|
8993 | var port = portPattern.exec(host);
|
8994 | if (port) {
|
8995 | port = port[0];
|
8996 | if (port !== ':') {
|
8997 | this.port = port.substr(1);
|
8998 | }
|
8999 | host = host.substr(0, host.length - port.length);
|
9000 | }
|
9001 | if (host) this.hostname = host;
|
9002 | };
|
9003 |
|
9004 | },{"./util":53,"punycode":12,"querystring":15}],53:[function(require,module,exports){
|
9005 | 'use strict';
|
9006 |
|
9007 | module.exports = {
|
9008 | isString: function(arg) {
|
9009 | return typeof(arg) === 'string';
|
9010 | },
|
9011 | isObject: function(arg) {
|
9012 | return typeof(arg) === 'object' && arg !== null;
|
9013 | },
|
9014 | isNull: function(arg) {
|
9015 | return arg === null;
|
9016 | },
|
9017 | isNullOrUndefined: function(arg) {
|
9018 | return arg == null;
|
9019 | }
|
9020 | };
|
9021 |
|
9022 | },{}],54:[function(require,module,exports){
|
9023 | (function (global){(function (){
|
9024 |
|
9025 | /**
|
9026 | * Module exports.
|
9027 | */
|
9028 |
|
9029 | module.exports = deprecate;
|
9030 |
|
9031 | /**
|
9032 | * Mark that a method should not be used.
|
9033 | * Returns a modified function which warns once by default.
|
9034 | *
|
9035 | * If `localStorage.noDeprecation = true` is set, then it is a no-op.
|
9036 | *
|
9037 | * If `localStorage.throwDeprecation = true` is set, then deprecated functions
|
9038 | * will throw an Error when invoked.
|
9039 | *
|
9040 | * If `localStorage.traceDeprecation = true` is set, then deprecated functions
|
9041 | * will invoke `console.trace()` instead of `console.error()`.
|
9042 | *
|
9043 | * @param {Function} fn - the function to deprecate
|
9044 | * @param {String} msg - the string to print to the console when `fn` is invoked
|
9045 | * @returns {Function} a new "deprecated" version of `fn`
|
9046 | * @api public
|
9047 | */
|
9048 |
|
9049 | function deprecate (fn, msg) {
|
9050 | if (config('noDeprecation')) {
|
9051 | return fn;
|
9052 | }
|
9053 |
|
9054 | var warned = false;
|
9055 | function deprecated() {
|
9056 | if (!warned) {
|
9057 | if (config('throwDeprecation')) {
|
9058 | throw new Error(msg);
|
9059 | } else if (config('traceDeprecation')) {
|
9060 | console.trace(msg);
|
9061 | } else {
|
9062 | console.warn(msg);
|
9063 | }
|
9064 | warned = true;
|
9065 | }
|
9066 | return fn.apply(this, arguments);
|
9067 | }
|
9068 |
|
9069 | return deprecated;
|
9070 | }
|
9071 |
|
9072 | /**
|
9073 | * Checks `localStorage` for boolean values for the given `name`.
|
9074 | *
|
9075 | * @param {String} name
|
9076 | * @returns {Boolean}
|
9077 | * @api private
|
9078 | */
|
9079 |
|
9080 | function config (name) {
|
9081 | // accessing global.localStorage can trigger a DOMException in sandboxed iframes
|
9082 | try {
|
9083 | if (!global.localStorage) return false;
|
9084 | } catch (_) {
|
9085 | return false;
|
9086 | }
|
9087 | var val = global.localStorage[name];
|
9088 | if (null == val) return false;
|
9089 | return String(val).toLowerCase() === 'true';
|
9090 | }
|
9091 |
|
9092 | }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
9093 | },{}],55:[function(require,module,exports){
|
9094 | module.exports = extend
|
9095 |
|
9096 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
9097 |
|
9098 | function extend() {
|
9099 | var target = {}
|
9100 |
|
9101 | for (var i = 0; i < arguments.length; i++) {
|
9102 | var source = arguments[i]
|
9103 |
|
9104 | for (var key in source) {
|
9105 | if (hasOwnProperty.call(source, key)) {
|
9106 | target[key] = source[key]
|
9107 | }
|
9108 | }
|
9109 | }
|
9110 |
|
9111 | return target
|
9112 | }
|
9113 |
|
9114 | },{}]},{},[2]);
|