UrgentcareCLI 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/UrgentCare/CLI.rb +1 -2
- data/lib/UrgentCare/Scraper.rb +65 -0
- data/lib/UrgentCare/version.rb +2 -2
- data/lib/UrgentCare.rb +1 -0
- metadata +3 -313
- data/.gitignore +0 -11
- data/.rspec +0 -3
- data/.travis.yml +0 -5
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -12
- data/Gemfile.lock +0 -84
- data/LICENSE.txt +0 -21
- data/Notes +0 -41
- data/README.md +0 -41
- data/Rakefile +0 -8
- data/UrgentCare.gemspec +0 -39
- data/background.jpg +0 -0
- data/data.txt +0 -4
- data/lib/Urgentcare/Scraper.rb +0 -78
- data/node_modules/.bin/rimraf +0 -1
- data/node_modules/.package-lock.json +0 -250
- data/node_modules/balanced-match/.github/FUNDING.yml +0 -2
- data/node_modules/balanced-match/LICENSE.md +0 -21
- data/node_modules/balanced-match/README.md +0 -97
- data/node_modules/balanced-match/index.js +0 -62
- data/node_modules/balanced-match/package.json +0 -48
- data/node_modules/brace-expansion/LICENSE +0 -21
- data/node_modules/brace-expansion/README.md +0 -129
- data/node_modules/brace-expansion/index.js +0 -201
- data/node_modules/brace-expansion/package.json +0 -47
- data/node_modules/concat-map/.travis.yml +0 -4
- data/node_modules/concat-map/LICENSE +0 -18
- data/node_modules/concat-map/README.markdown +0 -62
- data/node_modules/concat-map/example/map.js +0 -6
- data/node_modules/concat-map/index.js +0 -13
- data/node_modules/concat-map/package.json +0 -43
- data/node_modules/concat-map/test/map.js +0 -39
- data/node_modules/core-util-is/LICENSE +0 -19
- data/node_modules/core-util-is/README.md +0 -3
- data/node_modules/core-util-is/float.patch +0 -604
- data/node_modules/core-util-is/lib/util.js +0 -107
- data/node_modules/core-util-is/package.json +0 -32
- data/node_modules/core-util-is/test.js +0 -68
- data/node_modules/fs.realpath/LICENSE +0 -43
- data/node_modules/fs.realpath/README.md +0 -33
- data/node_modules/fs.realpath/index.js +0 -66
- data/node_modules/fs.realpath/old.js +0 -303
- data/node_modules/fs.realpath/package.json +0 -26
- data/node_modules/glob/LICENSE +0 -21
- data/node_modules/glob/README.md +0 -375
- data/node_modules/glob/changelog.md +0 -67
- data/node_modules/glob/common.js +0 -234
- data/node_modules/glob/glob.js +0 -788
- data/node_modules/glob/package.json +0 -51
- data/node_modules/glob/sync.js +0 -484
- data/node_modules/immediate/LICENSE.txt +0 -20
- data/node_modules/immediate/README.md +0 -93
- data/node_modules/immediate/dist/immediate.js +0 -75
- data/node_modules/immediate/dist/immediate.min.js +0 -1
- data/node_modules/immediate/lib/browser.js +0 -69
- data/node_modules/immediate/lib/index.js +0 -73
- data/node_modules/immediate/package.json +0 -42
- data/node_modules/inflight/LICENSE +0 -15
- data/node_modules/inflight/README.md +0 -37
- data/node_modules/inflight/inflight.js +0 -54
- data/node_modules/inflight/package.json +0 -29
- data/node_modules/inherits/LICENSE +0 -16
- data/node_modules/inherits/README.md +0 -42
- data/node_modules/inherits/inherits.js +0 -9
- data/node_modules/inherits/inherits_browser.js +0 -27
- data/node_modules/inherits/package.json +0 -29
- data/node_modules/isarray/.npmignore +0 -1
- data/node_modules/isarray/.travis.yml +0 -4
- data/node_modules/isarray/Makefile +0 -6
- data/node_modules/isarray/README.md +0 -60
- data/node_modules/isarray/component.json +0 -19
- data/node_modules/isarray/index.js +0 -5
- data/node_modules/isarray/package.json +0 -45
- data/node_modules/isarray/test.js +0 -20
- data/node_modules/jszip/.codeclimate.yml +0 -16
- data/node_modules/jszip/.editorconfig +0 -8
- data/node_modules/jszip/.jshintignore +0 -1
- data/node_modules/jszip/.jshintrc +0 -21
- data/node_modules/jszip/.travis.yml +0 -17
- data/node_modules/jszip/CHANGES.md +0 -163
- data/node_modules/jszip/LICENSE.markdown +0 -651
- data/node_modules/jszip/README.markdown +0 -35
- data/node_modules/jszip/dist/jszip.js +0 -30
- data/node_modules/jszip/dist/jszip.min.js +0 -13
- data/node_modules/jszip/index.d.ts +0 -270
- data/node_modules/jszip/lib/base64.js +0 -106
- data/node_modules/jszip/lib/compressedObject.js +0 -74
- data/node_modules/jszip/lib/compressions.js +0 -14
- data/node_modules/jszip/lib/crc32.js +0 -77
- data/node_modules/jszip/lib/defaults.js +0 -11
- data/node_modules/jszip/lib/external.js +0 -19
- data/node_modules/jszip/lib/flate.js +0 -85
- data/node_modules/jszip/lib/generate/ZipFileWorker.js +0 -540
- data/node_modules/jszip/lib/generate/index.js +0 -57
- data/node_modules/jszip/lib/index.js +0 -52
- data/node_modules/jszip/lib/license_header.js +0 -11
- data/node_modules/jszip/lib/load.js +0 -81
- data/node_modules/jszip/lib/nodejs/NodejsStreamInputAdapter.js +0 -74
- data/node_modules/jszip/lib/nodejs/NodejsStreamOutputAdapter.js +0 -42
- data/node_modules/jszip/lib/nodejsUtils.js +0 -57
- data/node_modules/jszip/lib/object.js +0 -389
- data/node_modules/jszip/lib/readable-stream-browser.js +0 -9
- data/node_modules/jszip/lib/reader/ArrayReader.js +0 -57
- data/node_modules/jszip/lib/reader/DataReader.js +0 -116
- data/node_modules/jszip/lib/reader/NodeBufferReader.js +0 -19
- data/node_modules/jszip/lib/reader/StringReader.js +0 -38
- data/node_modules/jszip/lib/reader/Uint8ArrayReader.js +0 -22
- data/node_modules/jszip/lib/reader/readerFor.js +0 -28
- data/node_modules/jszip/lib/signature.js +0 -7
- data/node_modules/jszip/lib/stream/ConvertWorker.js +0 -26
- data/node_modules/jszip/lib/stream/Crc32Probe.js +0 -24
- data/node_modules/jszip/lib/stream/DataLengthProbe.js +0 -29
- data/node_modules/jszip/lib/stream/DataWorker.js +0 -116
- data/node_modules/jszip/lib/stream/GenericWorker.js +0 -263
- data/node_modules/jszip/lib/stream/StreamHelper.js +0 -212
- data/node_modules/jszip/lib/support.js +0 -38
- data/node_modules/jszip/lib/utf8.js +0 -275
- data/node_modules/jszip/lib/utils.js +0 -476
- data/node_modules/jszip/lib/zipEntries.js +0 -262
- data/node_modules/jszip/lib/zipEntry.js +0 -294
- data/node_modules/jszip/lib/zipObject.js +0 -133
- data/node_modules/jszip/package.json +0 -63
- data/node_modules/jszip/vendor/FileSaver.js +0 -247
- data/node_modules/lie/README.md +0 -62
- data/node_modules/lie/dist/lie.js +0 -350
- data/node_modules/lie/dist/lie.min.js +0 -1
- data/node_modules/lie/dist/lie.polyfill.js +0 -358
- data/node_modules/lie/dist/lie.polyfill.min.js +0 -1
- data/node_modules/lie/lib/browser.js +0 -273
- data/node_modules/lie/lib/index.js +0 -298
- data/node_modules/lie/license.md +0 -7
- data/node_modules/lie/lie.d.ts +0 -244
- data/node_modules/lie/package.json +0 -69
- data/node_modules/lie/polyfill.js +0 -4
- data/node_modules/minimatch/LICENSE +0 -15
- data/node_modules/minimatch/README.md +0 -209
- data/node_modules/minimatch/minimatch.js +0 -923
- data/node_modules/minimatch/package.json +0 -30
- data/node_modules/once/LICENSE +0 -15
- data/node_modules/once/README.md +0 -79
- data/node_modules/once/once.js +0 -42
- data/node_modules/once/package.json +0 -33
- data/node_modules/pako/CHANGELOG.md +0 -164
- data/node_modules/pako/LICENSE +0 -21
- data/node_modules/pako/README.md +0 -191
- data/node_modules/pako/dist/pako.js +0 -6818
- data/node_modules/pako/dist/pako.min.js +0 -1
- data/node_modules/pako/dist/pako_deflate.js +0 -3997
- data/node_modules/pako/dist/pako_deflate.min.js +0 -1
- data/node_modules/pako/dist/pako_inflate.js +0 -3300
- data/node_modules/pako/dist/pako_inflate.min.js +0 -1
- data/node_modules/pako/index.js +0 -14
- data/node_modules/pako/lib/deflate.js +0 -400
- data/node_modules/pako/lib/inflate.js +0 -423
- data/node_modules/pako/lib/utils/common.js +0 -105
- data/node_modules/pako/lib/utils/strings.js +0 -187
- data/node_modules/pako/lib/zlib/README +0 -59
- data/node_modules/pako/lib/zlib/adler32.js +0 -51
- data/node_modules/pako/lib/zlib/constants.js +0 -68
- data/node_modules/pako/lib/zlib/crc32.js +0 -59
- data/node_modules/pako/lib/zlib/deflate.js +0 -1874
- data/node_modules/pako/lib/zlib/gzheader.js +0 -58
- data/node_modules/pako/lib/zlib/inffast.js +0 -345
- data/node_modules/pako/lib/zlib/inflate.js +0 -1556
- data/node_modules/pako/lib/zlib/inftrees.js +0 -343
- data/node_modules/pako/lib/zlib/messages.js +0 -32
- data/node_modules/pako/lib/zlib/trees.js +0 -1222
- data/node_modules/pako/lib/zlib/zstream.js +0 -47
- data/node_modules/pako/package.json +0 -44
- data/node_modules/path-is-absolute/index.js +0 -20
- data/node_modules/path-is-absolute/license +0 -21
- data/node_modules/path-is-absolute/package.json +0 -43
- data/node_modules/path-is-absolute/readme.md +0 -59
- data/node_modules/process-nextick-args/index.js +0 -45
- data/node_modules/process-nextick-args/license.md +0 -19
- data/node_modules/process-nextick-args/package.json +0 -25
- data/node_modules/process-nextick-args/readme.md +0 -18
- data/node_modules/readable-stream/.travis.yml +0 -34
- data/node_modules/readable-stream/CONTRIBUTING.md +0 -38
- data/node_modules/readable-stream/GOVERNANCE.md +0 -136
- data/node_modules/readable-stream/LICENSE +0 -47
- data/node_modules/readable-stream/README.md +0 -58
- data/node_modules/readable-stream/doc/wg-meetings/2015-01-30.md +0 -60
- data/node_modules/readable-stream/duplex-browser.js +0 -1
- data/node_modules/readable-stream/duplex.js +0 -1
- data/node_modules/readable-stream/lib/_stream_duplex.js +0 -131
- data/node_modules/readable-stream/lib/_stream_passthrough.js +0 -47
- data/node_modules/readable-stream/lib/_stream_readable.js +0 -1019
- data/node_modules/readable-stream/lib/_stream_transform.js +0 -214
- data/node_modules/readable-stream/lib/_stream_writable.js +0 -687
- data/node_modules/readable-stream/lib/internal/streams/BufferList.js +0 -79
- data/node_modules/readable-stream/lib/internal/streams/destroy.js +0 -74
- data/node_modules/readable-stream/lib/internal/streams/stream-browser.js +0 -1
- data/node_modules/readable-stream/lib/internal/streams/stream.js +0 -1
- data/node_modules/readable-stream/package.json +0 -52
- data/node_modules/readable-stream/passthrough.js +0 -1
- data/node_modules/readable-stream/readable-browser.js +0 -7
- data/node_modules/readable-stream/readable.js +0 -19
- data/node_modules/readable-stream/transform.js +0 -1
- data/node_modules/readable-stream/writable-browser.js +0 -1
- data/node_modules/readable-stream/writable.js +0 -8
- data/node_modules/rimraf/LICENSE +0 -15
- data/node_modules/rimraf/README.md +0 -101
- data/node_modules/rimraf/bin.js +0 -50
- data/node_modules/rimraf/package.json +0 -29
- data/node_modules/rimraf/rimraf.js +0 -372
- data/node_modules/safe-buffer/LICENSE +0 -21
- data/node_modules/safe-buffer/README.md +0 -584
- data/node_modules/safe-buffer/index.d.ts +0 -187
- data/node_modules/safe-buffer/index.js +0 -62
- data/node_modules/safe-buffer/package.json +0 -37
- data/node_modules/selenium-webdriver/CHANGES.md +0 -1114
- data/node_modules/selenium-webdriver/LICENSE +0 -202
- data/node_modules/selenium-webdriver/NOTICE +0 -2
- data/node_modules/selenium-webdriver/README.md +0 -229
- data/node_modules/selenium-webdriver/chrome.js +0 -295
- data/node_modules/selenium-webdriver/chromium.js +0 -829
- data/node_modules/selenium-webdriver/devtools/CDPConnection.js +0 -35
- data/node_modules/selenium-webdriver/edge.js +0 -224
- data/node_modules/selenium-webdriver/example/chrome_android.js +0 -45
- data/node_modules/selenium-webdriver/example/chrome_mobile_emulation.js +0 -46
- data/node_modules/selenium-webdriver/example/firefox_channels.js +0 -84
- data/node_modules/selenium-webdriver/example/google_search.js +0 -50
- data/node_modules/selenium-webdriver/example/google_search_test.js +0 -70
- data/node_modules/selenium-webdriver/example/headless.js +0 -63
- data/node_modules/selenium-webdriver/example/logging.js +0 -64
- data/node_modules/selenium-webdriver/firefox.js +0 -789
- data/node_modules/selenium-webdriver/http/index.js +0 -324
- data/node_modules/selenium-webdriver/http/util.js +0 -172
- data/node_modules/selenium-webdriver/ie.js +0 -503
- data/node_modules/selenium-webdriver/index.js +0 -825
- data/node_modules/selenium-webdriver/io/exec.js +0 -162
- data/node_modules/selenium-webdriver/io/index.js +0 -348
- data/node_modules/selenium-webdriver/io/zip.js +0 -223
- data/node_modules/selenium-webdriver/lib/atoms/find-elements.js +0 -123
- data/node_modules/selenium-webdriver/lib/atoms/get-attribute.js +0 -101
- data/node_modules/selenium-webdriver/lib/atoms/is-displayed.js +0 -101
- data/node_modules/selenium-webdriver/lib/atoms/mutation-listener.js +0 -55
- data/node_modules/selenium-webdriver/lib/by.js +0 -415
- data/node_modules/selenium-webdriver/lib/capabilities.js +0 -553
- data/node_modules/selenium-webdriver/lib/command.js +0 -206
- data/node_modules/selenium-webdriver/lib/error.js +0 -605
- data/node_modules/selenium-webdriver/lib/http.js +0 -704
- data/node_modules/selenium-webdriver/lib/input.js +0 -946
- data/node_modules/selenium-webdriver/lib/logging.js +0 -661
- data/node_modules/selenium-webdriver/lib/promise.js +0 -285
- data/node_modules/selenium-webdriver/lib/proxy.js +0 -212
- data/node_modules/selenium-webdriver/lib/session.js +0 -77
- data/node_modules/selenium-webdriver/lib/symbols.js +0 -37
- data/node_modules/selenium-webdriver/lib/until.js +0 -429
- data/node_modules/selenium-webdriver/lib/webdriver.js +0 -2919
- data/node_modules/selenium-webdriver/net/index.js +0 -107
- data/node_modules/selenium-webdriver/net/portprober.js +0 -75
- data/node_modules/selenium-webdriver/opera.js +0 -406
- data/node_modules/selenium-webdriver/package.json +0 -54
- data/node_modules/selenium-webdriver/proxy.js +0 -32
- data/node_modules/selenium-webdriver/remote/index.js +0 -624
- data/node_modules/selenium-webdriver/safari.js +0 -168
- data/node_modules/selenium-webdriver/testing/index.js +0 -504
- data/node_modules/set-immediate-shim/index.js +0 -7
- data/node_modules/set-immediate-shim/package.json +0 -34
- data/node_modules/set-immediate-shim/readme.md +0 -31
- data/node_modules/string_decoder/.travis.yml +0 -50
- data/node_modules/string_decoder/LICENSE +0 -48
- data/node_modules/string_decoder/README.md +0 -47
- data/node_modules/string_decoder/lib/string_decoder.js +0 -296
- data/node_modules/string_decoder/package.json +0 -31
- data/node_modules/tmp/CHANGELOG.md +0 -288
- data/node_modules/tmp/LICENSE +0 -21
- data/node_modules/tmp/README.md +0 -365
- data/node_modules/tmp/lib/tmp.js +0 -780
- data/node_modules/tmp/node_modules/.bin/rimraf +0 -1
- data/node_modules/tmp/node_modules/rimraf/CHANGELOG.md +0 -65
- data/node_modules/tmp/node_modules/rimraf/LICENSE +0 -15
- data/node_modules/tmp/node_modules/rimraf/README.md +0 -101
- data/node_modules/tmp/node_modules/rimraf/bin.js +0 -68
- data/node_modules/tmp/node_modules/rimraf/package.json +0 -32
- data/node_modules/tmp/node_modules/rimraf/rimraf.js +0 -360
- data/node_modules/tmp/package.json +0 -58
- data/node_modules/util-deprecate/History.md +0 -16
- data/node_modules/util-deprecate/LICENSE +0 -24
- data/node_modules/util-deprecate/README.md +0 -53
- data/node_modules/util-deprecate/browser.js +0 -67
- data/node_modules/util-deprecate/node.js +0 -6
- data/node_modules/util-deprecate/package.json +0 -27
- data/node_modules/wrappy/LICENSE +0 -15
- data/node_modules/wrappy/README.md +0 -36
- data/node_modules/wrappy/package.json +0 -29
- data/node_modules/wrappy/wrappy.js +0 -33
- data/node_modules/ws/LICENSE +0 -21
- data/node_modules/ws/README.md +0 -496
- data/node_modules/ws/browser.js +0 -8
- data/node_modules/ws/index.js +0 -10
- data/node_modules/ws/lib/buffer-util.js +0 -129
- data/node_modules/ws/lib/constants.js +0 -10
- data/node_modules/ws/lib/event-target.js +0 -184
- data/node_modules/ws/lib/extension.js +0 -223
- data/node_modules/ws/lib/limiter.js +0 -55
- data/node_modules/ws/lib/permessage-deflate.js +0 -517
- data/node_modules/ws/lib/receiver.js +0 -507
- data/node_modules/ws/lib/sender.js +0 -405
- data/node_modules/ws/lib/stream.js +0 -165
- data/node_modules/ws/lib/validation.js +0 -104
- data/node_modules/ws/lib/websocket-server.js +0 -418
- data/node_modules/ws/lib/websocket.js +0 -942
- data/node_modules/ws/package.json +0 -56
- data/package-lock.json +0 -458
- data/package.json +0 -5
- data/selenium.log +0 -1
- data/spec.md +0 -6
- data/test.data +0 -2110
@@ -1,38 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
exports.base64 = true;
|
4
|
-
exports.array = true;
|
5
|
-
exports.string = true;
|
6
|
-
exports.arraybuffer = typeof ArrayBuffer !== "undefined" && typeof Uint8Array !== "undefined";
|
7
|
-
exports.nodebuffer = typeof Buffer !== "undefined";
|
8
|
-
// contains true if JSZip can read/generate Uint8Array, false otherwise.
|
9
|
-
exports.uint8array = typeof Uint8Array !== "undefined";
|
10
|
-
|
11
|
-
if (typeof ArrayBuffer === "undefined") {
|
12
|
-
exports.blob = false;
|
13
|
-
}
|
14
|
-
else {
|
15
|
-
var buffer = new ArrayBuffer(0);
|
16
|
-
try {
|
17
|
-
exports.blob = new Blob([buffer], {
|
18
|
-
type: "application/zip"
|
19
|
-
}).size === 0;
|
20
|
-
}
|
21
|
-
catch (e) {
|
22
|
-
try {
|
23
|
-
var Builder = self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder;
|
24
|
-
var builder = new Builder();
|
25
|
-
builder.append(buffer);
|
26
|
-
exports.blob = builder.getBlob('application/zip').size === 0;
|
27
|
-
}
|
28
|
-
catch (e) {
|
29
|
-
exports.blob = false;
|
30
|
-
}
|
31
|
-
}
|
32
|
-
}
|
33
|
-
|
34
|
-
try {
|
35
|
-
exports.nodestream = !!require('readable-stream').Readable;
|
36
|
-
} catch(e) {
|
37
|
-
exports.nodestream = false;
|
38
|
-
}
|
@@ -1,275 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
var utils = require('./utils');
|
4
|
-
var support = require('./support');
|
5
|
-
var nodejsUtils = require('./nodejsUtils');
|
6
|
-
var GenericWorker = require('./stream/GenericWorker');
|
7
|
-
|
8
|
-
/**
|
9
|
-
* The following functions come from pako, from pako/lib/utils/strings
|
10
|
-
* released under the MIT license, see pako https://github.com/nodeca/pako/
|
11
|
-
*/
|
12
|
-
|
13
|
-
// Table with utf8 lengths (calculated by first byte of sequence)
|
14
|
-
// Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,
|
15
|
-
// because max possible codepoint is 0x10ffff
|
16
|
-
var _utf8len = new Array(256);
|
17
|
-
for (var i=0; i<256; i++) {
|
18
|
-
_utf8len[i] = (i >= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1);
|
19
|
-
}
|
20
|
-
_utf8len[254]=_utf8len[254]=1; // Invalid sequence start
|
21
|
-
|
22
|
-
// convert string to array (typed, when possible)
|
23
|
-
var string2buf = function (str) {
|
24
|
-
var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0;
|
25
|
-
|
26
|
-
// count binary size
|
27
|
-
for (m_pos = 0; m_pos < str_len; m_pos++) {
|
28
|
-
c = str.charCodeAt(m_pos);
|
29
|
-
if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) {
|
30
|
-
c2 = str.charCodeAt(m_pos+1);
|
31
|
-
if ((c2 & 0xfc00) === 0xdc00) {
|
32
|
-
c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
|
33
|
-
m_pos++;
|
34
|
-
}
|
35
|
-
}
|
36
|
-
buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;
|
37
|
-
}
|
38
|
-
|
39
|
-
// allocate buffer
|
40
|
-
if (support.uint8array) {
|
41
|
-
buf = new Uint8Array(buf_len);
|
42
|
-
} else {
|
43
|
-
buf = new Array(buf_len);
|
44
|
-
}
|
45
|
-
|
46
|
-
// convert
|
47
|
-
for (i=0, m_pos = 0; i < buf_len; m_pos++) {
|
48
|
-
c = str.charCodeAt(m_pos);
|
49
|
-
if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) {
|
50
|
-
c2 = str.charCodeAt(m_pos+1);
|
51
|
-
if ((c2 & 0xfc00) === 0xdc00) {
|
52
|
-
c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
|
53
|
-
m_pos++;
|
54
|
-
}
|
55
|
-
}
|
56
|
-
if (c < 0x80) {
|
57
|
-
/* one byte */
|
58
|
-
buf[i++] = c;
|
59
|
-
} else if (c < 0x800) {
|
60
|
-
/* two bytes */
|
61
|
-
buf[i++] = 0xC0 | (c >>> 6);
|
62
|
-
buf[i++] = 0x80 | (c & 0x3f);
|
63
|
-
} else if (c < 0x10000) {
|
64
|
-
/* three bytes */
|
65
|
-
buf[i++] = 0xE0 | (c >>> 12);
|
66
|
-
buf[i++] = 0x80 | (c >>> 6 & 0x3f);
|
67
|
-
buf[i++] = 0x80 | (c & 0x3f);
|
68
|
-
} else {
|
69
|
-
/* four bytes */
|
70
|
-
buf[i++] = 0xf0 | (c >>> 18);
|
71
|
-
buf[i++] = 0x80 | (c >>> 12 & 0x3f);
|
72
|
-
buf[i++] = 0x80 | (c >>> 6 & 0x3f);
|
73
|
-
buf[i++] = 0x80 | (c & 0x3f);
|
74
|
-
}
|
75
|
-
}
|
76
|
-
|
77
|
-
return buf;
|
78
|
-
};
|
79
|
-
|
80
|
-
// Calculate max possible position in utf8 buffer,
|
81
|
-
// that will not break sequence. If that's not possible
|
82
|
-
// - (very small limits) return max size as is.
|
83
|
-
//
|
84
|
-
// buf[] - utf8 bytes array
|
85
|
-
// max - length limit (mandatory);
|
86
|
-
var utf8border = function(buf, max) {
|
87
|
-
var pos;
|
88
|
-
|
89
|
-
max = max || buf.length;
|
90
|
-
if (max > buf.length) { max = buf.length; }
|
91
|
-
|
92
|
-
// go back from last position, until start of sequence found
|
93
|
-
pos = max-1;
|
94
|
-
while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }
|
95
|
-
|
96
|
-
// Fuckup - very small and broken sequence,
|
97
|
-
// return max, because we should return something anyway.
|
98
|
-
if (pos < 0) { return max; }
|
99
|
-
|
100
|
-
// If we came to start of buffer - that means vuffer is too small,
|
101
|
-
// return max too.
|
102
|
-
if (pos === 0) { return max; }
|
103
|
-
|
104
|
-
return (pos + _utf8len[buf[pos]] > max) ? pos : max;
|
105
|
-
};
|
106
|
-
|
107
|
-
// convert array to string
|
108
|
-
var buf2string = function (buf) {
|
109
|
-
var str, i, out, c, c_len;
|
110
|
-
var len = buf.length;
|
111
|
-
|
112
|
-
// Reserve max possible length (2 words per char)
|
113
|
-
// NB: by unknown reasons, Array is significantly faster for
|
114
|
-
// String.fromCharCode.apply than Uint16Array.
|
115
|
-
var utf16buf = new Array(len*2);
|
116
|
-
|
117
|
-
for (out=0, i=0; i<len;) {
|
118
|
-
c = buf[i++];
|
119
|
-
// quick process ascii
|
120
|
-
if (c < 0x80) { utf16buf[out++] = c; continue; }
|
121
|
-
|
122
|
-
c_len = _utf8len[c];
|
123
|
-
// skip 5 & 6 byte codes
|
124
|
-
if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len-1; continue; }
|
125
|
-
|
126
|
-
// apply mask on first byte
|
127
|
-
c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;
|
128
|
-
// join the rest
|
129
|
-
while (c_len > 1 && i < len) {
|
130
|
-
c = (c << 6) | (buf[i++] & 0x3f);
|
131
|
-
c_len--;
|
132
|
-
}
|
133
|
-
|
134
|
-
// terminated by end of string?
|
135
|
-
if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; }
|
136
|
-
|
137
|
-
if (c < 0x10000) {
|
138
|
-
utf16buf[out++] = c;
|
139
|
-
} else {
|
140
|
-
c -= 0x10000;
|
141
|
-
utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff);
|
142
|
-
utf16buf[out++] = 0xdc00 | (c & 0x3ff);
|
143
|
-
}
|
144
|
-
}
|
145
|
-
|
146
|
-
// shrinkBuf(utf16buf, out)
|
147
|
-
if (utf16buf.length !== out) {
|
148
|
-
if(utf16buf.subarray) {
|
149
|
-
utf16buf = utf16buf.subarray(0, out);
|
150
|
-
} else {
|
151
|
-
utf16buf.length = out;
|
152
|
-
}
|
153
|
-
}
|
154
|
-
|
155
|
-
// return String.fromCharCode.apply(null, utf16buf);
|
156
|
-
return utils.applyFromCharCode(utf16buf);
|
157
|
-
};
|
158
|
-
|
159
|
-
|
160
|
-
// That's all for the pako functions.
|
161
|
-
|
162
|
-
|
163
|
-
/**
|
164
|
-
* Transform a javascript string into an array (typed if possible) of bytes,
|
165
|
-
* UTF-8 encoded.
|
166
|
-
* @param {String} str the string to encode
|
167
|
-
* @return {Array|Uint8Array|Buffer} the UTF-8 encoded string.
|
168
|
-
*/
|
169
|
-
exports.utf8encode = function utf8encode(str) {
|
170
|
-
if (support.nodebuffer) {
|
171
|
-
return nodejsUtils.newBufferFrom(str, "utf-8");
|
172
|
-
}
|
173
|
-
|
174
|
-
return string2buf(str);
|
175
|
-
};
|
176
|
-
|
177
|
-
|
178
|
-
/**
|
179
|
-
* Transform a bytes array (or a representation) representing an UTF-8 encoded
|
180
|
-
* string into a javascript string.
|
181
|
-
* @param {Array|Uint8Array|Buffer} buf the data de decode
|
182
|
-
* @return {String} the decoded string.
|
183
|
-
*/
|
184
|
-
exports.utf8decode = function utf8decode(buf) {
|
185
|
-
if (support.nodebuffer) {
|
186
|
-
return utils.transformTo("nodebuffer", buf).toString("utf-8");
|
187
|
-
}
|
188
|
-
|
189
|
-
buf = utils.transformTo(support.uint8array ? "uint8array" : "array", buf);
|
190
|
-
|
191
|
-
return buf2string(buf);
|
192
|
-
};
|
193
|
-
|
194
|
-
/**
|
195
|
-
* A worker to decode utf8 encoded binary chunks into string chunks.
|
196
|
-
* @constructor
|
197
|
-
*/
|
198
|
-
function Utf8DecodeWorker() {
|
199
|
-
GenericWorker.call(this, "utf-8 decode");
|
200
|
-
// the last bytes if a chunk didn't end with a complete codepoint.
|
201
|
-
this.leftOver = null;
|
202
|
-
}
|
203
|
-
utils.inherits(Utf8DecodeWorker, GenericWorker);
|
204
|
-
|
205
|
-
/**
|
206
|
-
* @see GenericWorker.processChunk
|
207
|
-
*/
|
208
|
-
Utf8DecodeWorker.prototype.processChunk = function (chunk) {
|
209
|
-
|
210
|
-
var data = utils.transformTo(support.uint8array ? "uint8array" : "array", chunk.data);
|
211
|
-
|
212
|
-
// 1st step, re-use what's left of the previous chunk
|
213
|
-
if (this.leftOver && this.leftOver.length) {
|
214
|
-
if(support.uint8array) {
|
215
|
-
var previousData = data;
|
216
|
-
data = new Uint8Array(previousData.length + this.leftOver.length);
|
217
|
-
data.set(this.leftOver, 0);
|
218
|
-
data.set(previousData, this.leftOver.length);
|
219
|
-
} else {
|
220
|
-
data = this.leftOver.concat(data);
|
221
|
-
}
|
222
|
-
this.leftOver = null;
|
223
|
-
}
|
224
|
-
|
225
|
-
var nextBoundary = utf8border(data);
|
226
|
-
var usableData = data;
|
227
|
-
if (nextBoundary !== data.length) {
|
228
|
-
if (support.uint8array) {
|
229
|
-
usableData = data.subarray(0, nextBoundary);
|
230
|
-
this.leftOver = data.subarray(nextBoundary, data.length);
|
231
|
-
} else {
|
232
|
-
usableData = data.slice(0, nextBoundary);
|
233
|
-
this.leftOver = data.slice(nextBoundary, data.length);
|
234
|
-
}
|
235
|
-
}
|
236
|
-
|
237
|
-
this.push({
|
238
|
-
data : exports.utf8decode(usableData),
|
239
|
-
meta : chunk.meta
|
240
|
-
});
|
241
|
-
};
|
242
|
-
|
243
|
-
/**
|
244
|
-
* @see GenericWorker.flush
|
245
|
-
*/
|
246
|
-
Utf8DecodeWorker.prototype.flush = function () {
|
247
|
-
if(this.leftOver && this.leftOver.length) {
|
248
|
-
this.push({
|
249
|
-
data : exports.utf8decode(this.leftOver),
|
250
|
-
meta : {}
|
251
|
-
});
|
252
|
-
this.leftOver = null;
|
253
|
-
}
|
254
|
-
};
|
255
|
-
exports.Utf8DecodeWorker = Utf8DecodeWorker;
|
256
|
-
|
257
|
-
/**
|
258
|
-
* A worker to endcode string chunks into utf8 encoded binary chunks.
|
259
|
-
* @constructor
|
260
|
-
*/
|
261
|
-
function Utf8EncodeWorker() {
|
262
|
-
GenericWorker.call(this, "utf-8 encode");
|
263
|
-
}
|
264
|
-
utils.inherits(Utf8EncodeWorker, GenericWorker);
|
265
|
-
|
266
|
-
/**
|
267
|
-
* @see GenericWorker.processChunk
|
268
|
-
*/
|
269
|
-
Utf8EncodeWorker.prototype.processChunk = function (chunk) {
|
270
|
-
this.push({
|
271
|
-
data : exports.utf8encode(chunk.data),
|
272
|
-
meta : chunk.meta
|
273
|
-
});
|
274
|
-
};
|
275
|
-
exports.Utf8EncodeWorker = Utf8EncodeWorker;
|
@@ -1,476 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
var support = require('./support');
|
4
|
-
var base64 = require('./base64');
|
5
|
-
var nodejsUtils = require('./nodejsUtils');
|
6
|
-
var setImmediate = require('set-immediate-shim');
|
7
|
-
var external = require("./external");
|
8
|
-
|
9
|
-
|
10
|
-
/**
|
11
|
-
* Convert a string that pass as a "binary string": it should represent a byte
|
12
|
-
* array but may have > 255 char codes. Be sure to take only the first byte
|
13
|
-
* and returns the byte array.
|
14
|
-
* @param {String} str the string to transform.
|
15
|
-
* @return {Array|Uint8Array} the string in a binary format.
|
16
|
-
*/
|
17
|
-
function string2binary(str) {
|
18
|
-
var result = null;
|
19
|
-
if (support.uint8array) {
|
20
|
-
result = new Uint8Array(str.length);
|
21
|
-
} else {
|
22
|
-
result = new Array(str.length);
|
23
|
-
}
|
24
|
-
return stringToArrayLike(str, result);
|
25
|
-
}
|
26
|
-
|
27
|
-
/**
|
28
|
-
* Create a new blob with the given content and the given type.
|
29
|
-
* @param {String|ArrayBuffer} part the content to put in the blob. DO NOT use
|
30
|
-
* an Uint8Array because the stock browser of android 4 won't accept it (it
|
31
|
-
* will be silently converted to a string, "[object Uint8Array]").
|
32
|
-
*
|
33
|
-
* Use only ONE part to build the blob to avoid a memory leak in IE11 / Edge:
|
34
|
-
* when a large amount of Array is used to create the Blob, the amount of
|
35
|
-
* memory consumed is nearly 100 times the original data amount.
|
36
|
-
*
|
37
|
-
* @param {String} type the mime type of the blob.
|
38
|
-
* @return {Blob} the created blob.
|
39
|
-
*/
|
40
|
-
exports.newBlob = function(part, type) {
|
41
|
-
exports.checkSupport("blob");
|
42
|
-
|
43
|
-
try {
|
44
|
-
// Blob constructor
|
45
|
-
return new Blob([part], {
|
46
|
-
type: type
|
47
|
-
});
|
48
|
-
}
|
49
|
-
catch (e) {
|
50
|
-
|
51
|
-
try {
|
52
|
-
// deprecated, browser only, old way
|
53
|
-
var Builder = self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder;
|
54
|
-
var builder = new Builder();
|
55
|
-
builder.append(part);
|
56
|
-
return builder.getBlob(type);
|
57
|
-
}
|
58
|
-
catch (e) {
|
59
|
-
|
60
|
-
// well, fuck ?!
|
61
|
-
throw new Error("Bug : can't construct the Blob.");
|
62
|
-
}
|
63
|
-
}
|
64
|
-
|
65
|
-
|
66
|
-
};
|
67
|
-
/**
|
68
|
-
* The identity function.
|
69
|
-
* @param {Object} input the input.
|
70
|
-
* @return {Object} the same input.
|
71
|
-
*/
|
72
|
-
function identity(input) {
|
73
|
-
return input;
|
74
|
-
}
|
75
|
-
|
76
|
-
/**
|
77
|
-
* Fill in an array with a string.
|
78
|
-
* @param {String} str the string to use.
|
79
|
-
* @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to fill in (will be mutated).
|
80
|
-
* @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated array.
|
81
|
-
*/
|
82
|
-
function stringToArrayLike(str, array) {
|
83
|
-
for (var i = 0; i < str.length; ++i) {
|
84
|
-
array[i] = str.charCodeAt(i) & 0xFF;
|
85
|
-
}
|
86
|
-
return array;
|
87
|
-
}
|
88
|
-
|
89
|
-
/**
|
90
|
-
* An helper for the function arrayLikeToString.
|
91
|
-
* This contains static information and functions that
|
92
|
-
* can be optimized by the browser JIT compiler.
|
93
|
-
*/
|
94
|
-
var arrayToStringHelper = {
|
95
|
-
/**
|
96
|
-
* Transform an array of int into a string, chunk by chunk.
|
97
|
-
* See the performances notes on arrayLikeToString.
|
98
|
-
* @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform.
|
99
|
-
* @param {String} type the type of the array.
|
100
|
-
* @param {Integer} chunk the chunk size.
|
101
|
-
* @return {String} the resulting string.
|
102
|
-
* @throws Error if the chunk is too big for the stack.
|
103
|
-
*/
|
104
|
-
stringifyByChunk: function(array, type, chunk) {
|
105
|
-
var result = [], k = 0, len = array.length;
|
106
|
-
// shortcut
|
107
|
-
if (len <= chunk) {
|
108
|
-
return String.fromCharCode.apply(null, array);
|
109
|
-
}
|
110
|
-
while (k < len) {
|
111
|
-
if (type === "array" || type === "nodebuffer") {
|
112
|
-
result.push(String.fromCharCode.apply(null, array.slice(k, Math.min(k + chunk, len))));
|
113
|
-
}
|
114
|
-
else {
|
115
|
-
result.push(String.fromCharCode.apply(null, array.subarray(k, Math.min(k + chunk, len))));
|
116
|
-
}
|
117
|
-
k += chunk;
|
118
|
-
}
|
119
|
-
return result.join("");
|
120
|
-
},
|
121
|
-
/**
|
122
|
-
* Call String.fromCharCode on every item in the array.
|
123
|
-
* This is the naive implementation, which generate A LOT of intermediate string.
|
124
|
-
* This should be used when everything else fail.
|
125
|
-
* @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform.
|
126
|
-
* @return {String} the result.
|
127
|
-
*/
|
128
|
-
stringifyByChar: function(array){
|
129
|
-
var resultStr = "";
|
130
|
-
for(var i = 0; i < array.length; i++) {
|
131
|
-
resultStr += String.fromCharCode(array[i]);
|
132
|
-
}
|
133
|
-
return resultStr;
|
134
|
-
},
|
135
|
-
applyCanBeUsed : {
|
136
|
-
/**
|
137
|
-
* true if the browser accepts to use String.fromCharCode on Uint8Array
|
138
|
-
*/
|
139
|
-
uint8array : (function () {
|
140
|
-
try {
|
141
|
-
return support.uint8array && String.fromCharCode.apply(null, new Uint8Array(1)).length === 1;
|
142
|
-
} catch (e) {
|
143
|
-
return false;
|
144
|
-
}
|
145
|
-
})(),
|
146
|
-
/**
|
147
|
-
* true if the browser accepts to use String.fromCharCode on nodejs Buffer.
|
148
|
-
*/
|
149
|
-
nodebuffer : (function () {
|
150
|
-
try {
|
151
|
-
return support.nodebuffer && String.fromCharCode.apply(null, nodejsUtils.allocBuffer(1)).length === 1;
|
152
|
-
} catch (e) {
|
153
|
-
return false;
|
154
|
-
}
|
155
|
-
})()
|
156
|
-
}
|
157
|
-
};
|
158
|
-
|
159
|
-
/**
|
160
|
-
* Transform an array-like object to a string.
|
161
|
-
* @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform.
|
162
|
-
* @return {String} the result.
|
163
|
-
*/
|
164
|
-
function arrayLikeToString(array) {
|
165
|
-
// Performances notes :
|
166
|
-
// --------------------
|
167
|
-
// String.fromCharCode.apply(null, array) is the fastest, see
|
168
|
-
// see http://jsperf.com/converting-a-uint8array-to-a-string/2
|
169
|
-
// but the stack is limited (and we can get huge arrays !).
|
170
|
-
//
|
171
|
-
// result += String.fromCharCode(array[i]); generate too many strings !
|
172
|
-
//
|
173
|
-
// This code is inspired by http://jsperf.com/arraybuffer-to-string-apply-performance/2
|
174
|
-
// TODO : we now have workers that split the work. Do we still need that ?
|
175
|
-
var chunk = 65536,
|
176
|
-
type = exports.getTypeOf(array),
|
177
|
-
canUseApply = true;
|
178
|
-
if (type === "uint8array") {
|
179
|
-
canUseApply = arrayToStringHelper.applyCanBeUsed.uint8array;
|
180
|
-
} else if (type === "nodebuffer") {
|
181
|
-
canUseApply = arrayToStringHelper.applyCanBeUsed.nodebuffer;
|
182
|
-
}
|
183
|
-
|
184
|
-
if (canUseApply) {
|
185
|
-
while (chunk > 1) {
|
186
|
-
try {
|
187
|
-
return arrayToStringHelper.stringifyByChunk(array, type, chunk);
|
188
|
-
} catch (e) {
|
189
|
-
chunk = Math.floor(chunk / 2);
|
190
|
-
}
|
191
|
-
}
|
192
|
-
}
|
193
|
-
|
194
|
-
// no apply or chunk error : slow and painful algorithm
|
195
|
-
// default browser on android 4.*
|
196
|
-
return arrayToStringHelper.stringifyByChar(array);
|
197
|
-
}
|
198
|
-
|
199
|
-
exports.applyFromCharCode = arrayLikeToString;
|
200
|
-
|
201
|
-
|
202
|
-
/**
|
203
|
-
* Copy the data from an array-like to an other array-like.
|
204
|
-
* @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayFrom the origin array.
|
205
|
-
* @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayTo the destination array which will be mutated.
|
206
|
-
* @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated destination array.
|
207
|
-
*/
|
208
|
-
function arrayLikeToArrayLike(arrayFrom, arrayTo) {
|
209
|
-
for (var i = 0; i < arrayFrom.length; i++) {
|
210
|
-
arrayTo[i] = arrayFrom[i];
|
211
|
-
}
|
212
|
-
return arrayTo;
|
213
|
-
}
|
214
|
-
|
215
|
-
// a matrix containing functions to transform everything into everything.
|
216
|
-
var transform = {};
|
217
|
-
|
218
|
-
// string to ?
|
219
|
-
transform["string"] = {
|
220
|
-
"string": identity,
|
221
|
-
"array": function(input) {
|
222
|
-
return stringToArrayLike(input, new Array(input.length));
|
223
|
-
},
|
224
|
-
"arraybuffer": function(input) {
|
225
|
-
return transform["string"]["uint8array"](input).buffer;
|
226
|
-
},
|
227
|
-
"uint8array": function(input) {
|
228
|
-
return stringToArrayLike(input, new Uint8Array(input.length));
|
229
|
-
},
|
230
|
-
"nodebuffer": function(input) {
|
231
|
-
return stringToArrayLike(input, nodejsUtils.allocBuffer(input.length));
|
232
|
-
}
|
233
|
-
};
|
234
|
-
|
235
|
-
// array to ?
|
236
|
-
transform["array"] = {
|
237
|
-
"string": arrayLikeToString,
|
238
|
-
"array": identity,
|
239
|
-
"arraybuffer": function(input) {
|
240
|
-
return (new Uint8Array(input)).buffer;
|
241
|
-
},
|
242
|
-
"uint8array": function(input) {
|
243
|
-
return new Uint8Array(input);
|
244
|
-
},
|
245
|
-
"nodebuffer": function(input) {
|
246
|
-
return nodejsUtils.newBufferFrom(input);
|
247
|
-
}
|
248
|
-
};
|
249
|
-
|
250
|
-
// arraybuffer to ?
|
251
|
-
transform["arraybuffer"] = {
|
252
|
-
"string": function(input) {
|
253
|
-
return arrayLikeToString(new Uint8Array(input));
|
254
|
-
},
|
255
|
-
"array": function(input) {
|
256
|
-
return arrayLikeToArrayLike(new Uint8Array(input), new Array(input.byteLength));
|
257
|
-
},
|
258
|
-
"arraybuffer": identity,
|
259
|
-
"uint8array": function(input) {
|
260
|
-
return new Uint8Array(input);
|
261
|
-
},
|
262
|
-
"nodebuffer": function(input) {
|
263
|
-
return nodejsUtils.newBufferFrom(new Uint8Array(input));
|
264
|
-
}
|
265
|
-
};
|
266
|
-
|
267
|
-
// uint8array to ?
|
268
|
-
transform["uint8array"] = {
|
269
|
-
"string": arrayLikeToString,
|
270
|
-
"array": function(input) {
|
271
|
-
return arrayLikeToArrayLike(input, new Array(input.length));
|
272
|
-
},
|
273
|
-
"arraybuffer": function(input) {
|
274
|
-
return input.buffer;
|
275
|
-
},
|
276
|
-
"uint8array": identity,
|
277
|
-
"nodebuffer": function(input) {
|
278
|
-
return nodejsUtils.newBufferFrom(input);
|
279
|
-
}
|
280
|
-
};
|
281
|
-
|
282
|
-
// nodebuffer to ?
|
283
|
-
transform["nodebuffer"] = {
|
284
|
-
"string": arrayLikeToString,
|
285
|
-
"array": function(input) {
|
286
|
-
return arrayLikeToArrayLike(input, new Array(input.length));
|
287
|
-
},
|
288
|
-
"arraybuffer": function(input) {
|
289
|
-
return transform["nodebuffer"]["uint8array"](input).buffer;
|
290
|
-
},
|
291
|
-
"uint8array": function(input) {
|
292
|
-
return arrayLikeToArrayLike(input, new Uint8Array(input.length));
|
293
|
-
},
|
294
|
-
"nodebuffer": identity
|
295
|
-
};
|
296
|
-
|
297
|
-
/**
|
298
|
-
* Transform an input into any type.
|
299
|
-
* The supported output type are : string, array, uint8array, arraybuffer, nodebuffer.
|
300
|
-
* If no output type is specified, the unmodified input will be returned.
|
301
|
-
* @param {String} outputType the output type.
|
302
|
-
* @param {String|Array|ArrayBuffer|Uint8Array|Buffer} input the input to convert.
|
303
|
-
* @throws {Error} an Error if the browser doesn't support the requested output type.
|
304
|
-
*/
|
305
|
-
exports.transformTo = function(outputType, input) {
|
306
|
-
if (!input) {
|
307
|
-
// undefined, null, etc
|
308
|
-
// an empty string won't harm.
|
309
|
-
input = "";
|
310
|
-
}
|
311
|
-
if (!outputType) {
|
312
|
-
return input;
|
313
|
-
}
|
314
|
-
exports.checkSupport(outputType);
|
315
|
-
var inputType = exports.getTypeOf(input);
|
316
|
-
var result = transform[inputType][outputType](input);
|
317
|
-
return result;
|
318
|
-
};
|
319
|
-
|
320
|
-
/**
|
321
|
-
* Return the type of the input.
|
322
|
-
* The type will be in a format valid for JSZip.utils.transformTo : string, array, uint8array, arraybuffer.
|
323
|
-
* @param {Object} input the input to identify.
|
324
|
-
* @return {String} the (lowercase) type of the input.
|
325
|
-
*/
|
326
|
-
exports.getTypeOf = function(input) {
|
327
|
-
if (typeof input === "string") {
|
328
|
-
return "string";
|
329
|
-
}
|
330
|
-
if (Object.prototype.toString.call(input) === "[object Array]") {
|
331
|
-
return "array";
|
332
|
-
}
|
333
|
-
if (support.nodebuffer && nodejsUtils.isBuffer(input)) {
|
334
|
-
return "nodebuffer";
|
335
|
-
}
|
336
|
-
if (support.uint8array && input instanceof Uint8Array) {
|
337
|
-
return "uint8array";
|
338
|
-
}
|
339
|
-
if (support.arraybuffer && input instanceof ArrayBuffer) {
|
340
|
-
return "arraybuffer";
|
341
|
-
}
|
342
|
-
};
|
343
|
-
|
344
|
-
/**
|
345
|
-
* Throw an exception if the type is not supported.
|
346
|
-
* @param {String} type the type to check.
|
347
|
-
* @throws {Error} an Error if the browser doesn't support the requested type.
|
348
|
-
*/
|
349
|
-
exports.checkSupport = function(type) {
|
350
|
-
var supported = support[type.toLowerCase()];
|
351
|
-
if (!supported) {
|
352
|
-
throw new Error(type + " is not supported by this platform");
|
353
|
-
}
|
354
|
-
};
|
355
|
-
|
356
|
-
exports.MAX_VALUE_16BITS = 65535;
|
357
|
-
exports.MAX_VALUE_32BITS = -1; // well, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" is parsed as -1
|
358
|
-
|
359
|
-
/**
|
360
|
-
* Prettify a string read as binary.
|
361
|
-
* @param {string} str the string to prettify.
|
362
|
-
* @return {string} a pretty string.
|
363
|
-
*/
|
364
|
-
exports.pretty = function(str) {
|
365
|
-
var res = '',
|
366
|
-
code, i;
|
367
|
-
for (i = 0; i < (str || "").length; i++) {
|
368
|
-
code = str.charCodeAt(i);
|
369
|
-
res += '\\x' + (code < 16 ? "0" : "") + code.toString(16).toUpperCase();
|
370
|
-
}
|
371
|
-
return res;
|
372
|
-
};
|
373
|
-
|
374
|
-
/**
|
375
|
-
* Defer the call of a function.
|
376
|
-
* @param {Function} callback the function to call asynchronously.
|
377
|
-
* @param {Array} args the arguments to give to the callback.
|
378
|
-
*/
|
379
|
-
exports.delay = function(callback, args, self) {
|
380
|
-
setImmediate(function () {
|
381
|
-
callback.apply(self || null, args || []);
|
382
|
-
});
|
383
|
-
};
|
384
|
-
|
385
|
-
/**
|
386
|
-
* Extends a prototype with an other, without calling a constructor with
|
387
|
-
* side effects. Inspired by nodejs' `utils.inherits`
|
388
|
-
* @param {Function} ctor the constructor to augment
|
389
|
-
* @param {Function} superCtor the parent constructor to use
|
390
|
-
*/
|
391
|
-
exports.inherits = function (ctor, superCtor) {
|
392
|
-
var Obj = function() {};
|
393
|
-
Obj.prototype = superCtor.prototype;
|
394
|
-
ctor.prototype = new Obj();
|
395
|
-
};
|
396
|
-
|
397
|
-
/**
|
398
|
-
* Merge the objects passed as parameters into a new one.
|
399
|
-
* @private
|
400
|
-
* @param {...Object} var_args All objects to merge.
|
401
|
-
* @return {Object} a new object with the data of the others.
|
402
|
-
*/
|
403
|
-
exports.extend = function() {
|
404
|
-
var result = {}, i, attr;
|
405
|
-
for (i = 0; i < arguments.length; i++) { // arguments is not enumerable in some browsers
|
406
|
-
for (attr in arguments[i]) {
|
407
|
-
if (arguments[i].hasOwnProperty(attr) && typeof result[attr] === "undefined") {
|
408
|
-
result[attr] = arguments[i][attr];
|
409
|
-
}
|
410
|
-
}
|
411
|
-
}
|
412
|
-
return result;
|
413
|
-
};
|
414
|
-
|
415
|
-
/**
|
416
|
-
* Transform arbitrary content into a Promise.
|
417
|
-
* @param {String} name a name for the content being processed.
|
418
|
-
* @param {Object} inputData the content to process.
|
419
|
-
* @param {Boolean} isBinary true if the content is not an unicode string
|
420
|
-
* @param {Boolean} isOptimizedBinaryString true if the string content only has one byte per character.
|
421
|
-
* @param {Boolean} isBase64 true if the string content is encoded with base64.
|
422
|
-
* @return {Promise} a promise in a format usable by JSZip.
|
423
|
-
*/
|
424
|
-
exports.prepareContent = function(name, inputData, isBinary, isOptimizedBinaryString, isBase64) {
|
425
|
-
|
426
|
-
// if inputData is already a promise, this flatten it.
|
427
|
-
var promise = external.Promise.resolve(inputData).then(function(data) {
|
428
|
-
|
429
|
-
|
430
|
-
var isBlob = support.blob && (data instanceof Blob || ['[object File]', '[object Blob]'].indexOf(Object.prototype.toString.call(data)) !== -1);
|
431
|
-
|
432
|
-
if (isBlob && typeof FileReader !== "undefined") {
|
433
|
-
return new external.Promise(function (resolve, reject) {
|
434
|
-
var reader = new FileReader();
|
435
|
-
|
436
|
-
reader.onload = function(e) {
|
437
|
-
resolve(e.target.result);
|
438
|
-
};
|
439
|
-
reader.onerror = function(e) {
|
440
|
-
reject(e.target.error);
|
441
|
-
};
|
442
|
-
reader.readAsArrayBuffer(data);
|
443
|
-
});
|
444
|
-
} else {
|
445
|
-
return data;
|
446
|
-
}
|
447
|
-
});
|
448
|
-
|
449
|
-
return promise.then(function(data) {
|
450
|
-
var dataType = exports.getTypeOf(data);
|
451
|
-
|
452
|
-
if (!dataType) {
|
453
|
-
return external.Promise.reject(
|
454
|
-
new Error("Can't read the data of '" + name + "'. Is it " +
|
455
|
-
"in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?")
|
456
|
-
);
|
457
|
-
}
|
458
|
-
// special case : it's way easier to work with Uint8Array than with ArrayBuffer
|
459
|
-
if (dataType === "arraybuffer") {
|
460
|
-
data = exports.transformTo("uint8array", data);
|
461
|
-
} else if (dataType === "string") {
|
462
|
-
if (isBase64) {
|
463
|
-
data = base64.decode(data);
|
464
|
-
}
|
465
|
-
else if (isBinary) {
|
466
|
-
// optimizedBinaryString === true means that the file has already been filtered with a 0xFF mask
|
467
|
-
if (isOptimizedBinaryString !== true) {
|
468
|
-
// this is a string, not in a base64 format.
|
469
|
-
// Be sure that this is a correct "binary string"
|
470
|
-
data = string2binary(data);
|
471
|
-
}
|
472
|
-
}
|
473
|
-
}
|
474
|
-
return data;
|
475
|
-
});
|
476
|
-
};
|