workflow-editor 0.9.84-dw-tmp1 → 0.9.84-dw-tmp3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/lib/workflow-editor.css +1 -0
  2. package/lib/workflow-editor.umd.min.js +39 -1
  3. package/package.json +2 -2
  4. package/packages/index.js +34 -0
  5. package/packages/plugins/formValidatorUtil.js +528 -0
  6. package/packages/plugins/index.js +8 -0
  7. package/packages/workflow-editor/index.js +14 -0
  8. package/packages/workflow-editor/src/api.js +7 -0
  9. package/{lib/workflow-editor.umd.min.workflow-editor.umd.min~e2e93592.js → packages/workflow-editor/src/assets/wf-editor-icons.js} +2 -1
  10. package/packages/workflow-editor/src/constant.js +8 -0
  11. package/packages/workflow-editor/src/json-object-templates/copy-task.js +67 -0
  12. package/packages/workflow-editor/src/json-object-templates/decision.js +11 -0
  13. package/packages/workflow-editor/src/json-object-templates/end.js +14 -0
  14. package/packages/workflow-editor/src/json-object-templates/fork.js +10 -0
  15. package/packages/workflow-editor/src/json-object-templates/human-decision.js +9 -0
  16. package/packages/workflow-editor/src/json-object-templates/human-task.js +199 -0
  17. package/packages/workflow-editor/src/json-object-templates/join.js +10 -0
  18. package/packages/workflow-editor/src/json-object-templates/process.js +98 -0
  19. package/packages/workflow-editor/src/json-object-templates/start.js +13 -0
  20. package/packages/workflow-editor/src/json-object-templates/subprocess.js +30 -0
  21. package/packages/workflow-editor/src/json-object-templates/transition.js +26 -0
  22. package/packages/workflow-editor/src/main/admin-save-dialog.vue +66 -0
  23. package/packages/workflow-editor/src/main/canvas.vue +479 -0
  24. package/packages/workflow-editor/src/main/context-menu.vue +132 -0
  25. package/packages/workflow-editor/src/main/icon-svg.vue +32 -0
  26. package/packages/workflow-editor/src/main/selection-region.vue +66 -0
  27. package/packages/workflow-editor/src/main/tache-history-tooltip.vue +38 -0
  28. package/packages/workflow-editor/src/main/tache-name-input.vue +19 -0
  29. package/packages/workflow-editor/src/main/tache-subprocess-history-dialog.vue +35 -0
  30. package/packages/workflow-editor/src/main/toolbox.vue +60 -0
  31. package/packages/workflow-editor/src/main/wf-history-canvas.vue +302 -0
  32. package/packages/workflow-editor/src/process-json.js +622 -0
  33. package/packages/workflow-editor/src/process-service.js +31 -0
  34. package/packages/workflow-editor/src/properties-editors/common/additional-condition-utils.js +522 -0
  35. package/packages/workflow-editor/src/properties-editors/common/additional-condition.vue +276 -0
  36. package/packages/workflow-editor/src/properties-editors/common/auto-filled-fields-utils.js +34 -0
  37. package/packages/workflow-editor/src/properties-editors/common/auto-filled-fields.vue +239 -0
  38. package/packages/workflow-editor/src/properties-editors/common/common-notice-tool.vue +47 -0
  39. package/packages/workflow-editor/src/properties-editors/common/common-user-condition.vue +241 -0
  40. package/packages/workflow-editor/src/properties-editors/common/form-fields-utils.js +23 -0
  41. package/packages/workflow-editor/src/properties-editors/common/form-fields.vue +116 -0
  42. package/packages/workflow-editor/src/properties-editors/common/i18n-input.vue +75 -0
  43. package/packages/workflow-editor/src/properties-editors/common/i18n-set-dialog.vue +125 -0
  44. package/packages/workflow-editor/src/properties-editors/common/notice.vue +98 -0
  45. package/packages/workflow-editor/src/properties-editors/common/reminder.vue +179 -0
  46. package/packages/workflow-editor/src/properties-editors/common/select-mail-template.vue +83 -0
  47. package/packages/workflow-editor/src/properties-editors/common/standard-fields.vue +65 -0
  48. package/packages/workflow-editor/src/properties-editors/common/system-role-tree-inline.vue +355 -0
  49. package/packages/workflow-editor/src/properties-editors/common/system-role-tree.vue +63 -0
  50. package/packages/workflow-editor/src/properties-editors/common/task-title.vue +148 -0
  51. package/packages/workflow-editor/src/properties-editors/common/transactor-settings.vue +220 -0
  52. package/packages/workflow-editor/src/properties-editors/common/user-selection.vue +386 -0
  53. package/packages/workflow-editor/src/properties-editors/common/value-selection-dialog.vue +209 -0
  54. package/packages/workflow-editor/src/properties-editors/common/variables.vue +135 -0
  55. package/packages/workflow-editor/src/properties-editors/copy-task/basic-properties.vue +90 -0
  56. package/packages/workflow-editor/src/properties-editors/copy-task/permission-settings.vue +155 -0
  57. package/packages/workflow-editor/src/properties-editors/copy-task.vue +80 -0
  58. package/packages/workflow-editor/src/properties-editors/decision.vue +90 -0
  59. package/packages/workflow-editor/src/properties-editors/fork.vue +72 -0
  60. package/packages/workflow-editor/src/properties-editors/human-decision.vue +44 -0
  61. package/packages/workflow-editor/src/properties-editors/human-task/additional-condition-dialog.vue +60 -0
  62. package/packages/workflow-editor/src/properties-editors/human-task/basic-properties.vue +156 -0
  63. package/packages/workflow-editor/src/properties-editors/human-task/componentsConfigUtil.js +291 -0
  64. package/packages/workflow-editor/src/properties-editors/human-task/custom-actions.vue +249 -0
  65. package/packages/workflow-editor/src/properties-editors/human-task/editable-child-field-setting.vue +392 -0
  66. package/packages/workflow-editor/src/properties-editors/human-task/editable-child-fields.vue +241 -0
  67. package/packages/workflow-editor/src/properties-editors/human-task/editable-field-selection.vue +220 -0
  68. package/packages/workflow-editor/src/properties-editors/human-task/editable-fields.vue +204 -0
  69. package/packages/workflow-editor/src/properties-editors/human-task/events.vue +59 -0
  70. package/packages/workflow-editor/src/properties-editors/human-task/permission-settings.vue +207 -0
  71. package/packages/workflow-editor/src/properties-editors/human-task/selection-conditions.vue +390 -0
  72. package/packages/workflow-editor/src/properties-editors/human-task.vue +103 -0
  73. package/packages/workflow-editor/src/properties-editors/join.vue +44 -0
  74. package/packages/workflow-editor/src/properties-editors/process/basic-properties.vue +273 -0
  75. package/packages/workflow-editor/src/properties-editors/process/events.vue +76 -0
  76. package/packages/workflow-editor/src/properties-editors/process/notice-settings.vue +60 -0
  77. package/packages/workflow-editor/src/properties-editors/process/parameter-settings.vue +95 -0
  78. package/packages/workflow-editor/src/properties-editors/process/permission-settings.vue +28 -0
  79. package/packages/workflow-editor/src/properties-editors/process/selectPage.vue +81 -0
  80. package/packages/workflow-editor/src/properties-editors/process.vue +109 -0
  81. package/packages/workflow-editor/src/properties-editors/subprocess/basic-properties.vue +176 -0
  82. package/packages/workflow-editor/src/properties-editors/subprocess/events.vue +26 -0
  83. package/packages/workflow-editor/src/properties-editors/subprocess/field-mappings.vue +206 -0
  84. package/packages/workflow-editor/src/properties-editors/subprocess/transactor-settings.vue +64 -0
  85. package/packages/workflow-editor/src/properties-editors/subprocess.vue +79 -0
  86. package/packages/workflow-editor/src/properties-editors/transition/basic-properties.vue +53 -0
  87. package/packages/workflow-editor/src/properties-editors/transition.vue +74 -0
  88. package/packages/workflow-editor/src/properties-editors/user-condition.js +177 -0
  89. package/packages/workflow-editor/src/store/getters.js +27 -0
  90. package/packages/workflow-editor/src/store/workflow-editor.js +125 -0
  91. package/packages/workflow-editor/src/taches/common-methods.js +21 -0
  92. package/packages/workflow-editor/src/taches/copy-task.vue +99 -0
  93. package/packages/workflow-editor/src/taches/custom-task.vue +88 -0
  94. package/packages/workflow-editor/src/taches/decision.vue +102 -0
  95. package/packages/workflow-editor/src/taches/end.vue +76 -0
  96. package/packages/workflow-editor/src/taches/fork.vue +102 -0
  97. package/packages/workflow-editor/src/taches/human-decision.vue +102 -0
  98. package/packages/workflow-editor/src/taches/human-task.vue +113 -0
  99. package/packages/workflow-editor/src/taches/join.vue +91 -0
  100. package/packages/workflow-editor/src/taches/joint.vue +177 -0
  101. package/packages/workflow-editor/src/taches/start.vue +76 -0
  102. package/packages/workflow-editor/src/taches/subprocess.vue +99 -0
  103. package/packages/workflow-editor/src/taches/tache-resizer.vue +80 -0
  104. package/packages/workflow-editor/src/transitions/broken-line.vue +91 -0
  105. package/packages/workflow-editor/src/transitions/curve-line.vue +91 -0
  106. package/packages/workflow-editor/src/transitions/straight-line.vue +26 -0
  107. package/packages/workflow-editor/src/transitions/transition.vue +212 -0
  108. package/packages/workflow-editor/src/transitions/virtual-transition.vue +43 -0
  109. package/packages/workflow-editor/src/util.js +493 -0
  110. package/packages/workflow-editor/src/workflow-editor.vue +605 -0
  111. package/packages/workflow-editor/src/workflow-history.vue +153 -0
  112. package/src/index.js +28 -0
  113. package/lib/css/workflow-editor.common~247b300f.28fbd3a3.css +0 -1
  114. package/lib/css/workflow-editor.common~62bcfb54.c1b3ecc5.css +0 -1
  115. package/lib/css/workflow-editor.common~95b80cda.16e04122.css +0 -1
  116. package/lib/css/workflow-editor.common~e19cd708.68e04fb4.css +0 -1
  117. package/lib/css/workflow-editor.umd.min~247b300f.28fbd3a3.css +0 -1
  118. package/lib/css/workflow-editor.umd.min~62bcfb54.c1b3ecc5.css +0 -1
  119. package/lib/css/workflow-editor.umd.min~95b80cda.16e04122.css +0 -1
  120. package/lib/css/workflow-editor.umd.min~e19cd708.68e04fb4.css +0 -1
  121. package/lib/css/workflow-editor.umd~247b300f.28fbd3a3.css +0 -1
  122. package/lib/css/workflow-editor.umd~62bcfb54.c1b3ecc5.css +0 -1
  123. package/lib/css/workflow-editor.umd~95b80cda.16e04122.css +0 -1
  124. package/lib/css/workflow-editor.umd~e19cd708.68e04fb4.css +0 -1
  125. package/lib/css/yarn.prismjs~0bd0e877.9093a967.css +0 -1
  126. package/lib/workflow-editor.common.vendors~workflow-editor.common~253ae210.js +0 -4136
  127. package/lib/workflow-editor.common.workflow-editor.common~0b5ad61a.js +0 -1022
  128. package/lib/workflow-editor.common.workflow-editor.common~247b300f.js +0 -1948
  129. package/lib/workflow-editor.common.workflow-editor.common~62bcfb54.js +0 -14764
  130. package/lib/workflow-editor.common.workflow-editor.common~95b80cda.js +0 -3300
  131. package/lib/workflow-editor.common.workflow-editor.common~e19cd708.js +0 -1585
  132. package/lib/workflow-editor.common.workflow-editor.common~e2e93592.js +0 -1293
  133. package/lib/workflow-editor.common.yarn.async-validator~7864cd12.js +0 -1223
  134. package/lib/workflow-editor.common.yarn.buffer~7e5e8261.js +0 -1801
  135. package/lib/workflow-editor.common.yarn.core-js~2b13b260.js +0 -5078
  136. package/lib/workflow-editor.common.yarn.imatrix-ui~f5767151.js +0 -2256
  137. package/lib/workflow-editor.common.yarn.prismjs~0bd0e877.js +0 -2028
  138. package/lib/workflow-editor.common.yarn.readable-stream~2b6d3a99.js +0 -2435
  139. package/lib/workflow-editor.common.yarn.sax~95191fae.js +0 -1576
  140. package/lib/workflow-editor.common.yarn.vue-i18n~02576867.js +0 -2259
  141. package/lib/workflow-editor.umd.min.vendors~workflow-editor.umd.min~253ae210.js +0 -12
  142. package/lib/workflow-editor.umd.min.workflow-editor.umd.min~0b5ad61a.js +0 -1
  143. package/lib/workflow-editor.umd.min.workflow-editor.umd.min~247b300f.js +0 -1
  144. package/lib/workflow-editor.umd.min.workflow-editor.umd.min~62bcfb54.js +0 -1
  145. package/lib/workflow-editor.umd.min.workflow-editor.umd.min~95b80cda.js +0 -1
  146. package/lib/workflow-editor.umd.min.workflow-editor.umd.min~e19cd708.js +0 -1
  147. package/lib/workflow-editor.umd.min.yarn.async-validator~7864cd12.js +0 -1
  148. package/lib/workflow-editor.umd.min.yarn.buffer~7e5e8261.js +0 -8
  149. package/lib/workflow-editor.umd.min.yarn.core-js~2b13b260.js +0 -1
  150. package/lib/workflow-editor.umd.min.yarn.imatrix-ui~f5767151.js +0 -1
  151. package/lib/workflow-editor.umd.min.yarn.prismjs~0bd0e877.js +0 -9
  152. package/lib/workflow-editor.umd.min.yarn.readable-stream~2b6d3a99.js +0 -1
  153. package/lib/workflow-editor.umd.min.yarn.sax~95191fae.js +0 -2
  154. package/lib/workflow-editor.umd.min.yarn.vue-i18n~02576867.js +0 -6
  155. package/lib/workflow-editor.umd.vendors~workflow-editor.umd~253ae210.js +0 -4136
  156. package/lib/workflow-editor.umd.workflow-editor.umd~0b5ad61a.js +0 -1032
  157. package/lib/workflow-editor.umd.workflow-editor.umd~247b300f.js +0 -1948
  158. package/lib/workflow-editor.umd.workflow-editor.umd~62bcfb54.js +0 -14764
  159. package/lib/workflow-editor.umd.workflow-editor.umd~95b80cda.js +0 -3300
  160. package/lib/workflow-editor.umd.workflow-editor.umd~e19cd708.js +0 -1585
  161. package/lib/workflow-editor.umd.workflow-editor.umd~e2e93592.js +0 -1293
  162. package/lib/workflow-editor.umd.yarn.async-validator~7864cd12.js +0 -1223
  163. package/lib/workflow-editor.umd.yarn.buffer~7e5e8261.js +0 -1801
  164. package/lib/workflow-editor.umd.yarn.core-js~2b13b260.js +0 -5078
  165. package/lib/workflow-editor.umd.yarn.imatrix-ui~f5767151.js +0 -2256
  166. package/lib/workflow-editor.umd.yarn.prismjs~0bd0e877.js +0 -2028
  167. package/lib/workflow-editor.umd.yarn.readable-stream~2b6d3a99.js +0 -2435
  168. package/lib/workflow-editor.umd.yarn.sax~95191fae.js +0 -1576
  169. package/lib/workflow-editor.umd.yarn.vue-i18n~02576867.js +0 -2259
@@ -1,1801 +0,0 @@
1
- ((typeof self !== 'undefined' ? self : this)["webpackJsonpworkflow_editor"] = (typeof self !== 'undefined' ? self : this)["webpackJsonpworkflow_editor"] || []).push([[9],{
2
-
3
- /***/ "b639":
4
- /***/ (function(module, exports, __webpack_require__) {
5
-
6
- "use strict";
7
- /* WEBPACK VAR INJECTION */(function(global) {/*!
8
- * The buffer module from node.js, for the browser.
9
- *
10
- * @author Feross Aboukhadijeh <http://feross.org>
11
- * @license MIT
12
- */
13
- /* eslint-disable no-proto */
14
-
15
-
16
-
17
- var base64 = __webpack_require__("1fb5")
18
- var ieee754 = __webpack_require__("9152")
19
- var isArray = __webpack_require__("e3db")
20
-
21
- exports.Buffer = Buffer
22
- exports.SlowBuffer = SlowBuffer
23
- exports.INSPECT_MAX_BYTES = 50
24
-
25
- /**
26
- * If `Buffer.TYPED_ARRAY_SUPPORT`:
27
- * === true Use Uint8Array implementation (fastest)
28
- * === false Use Object implementation (most compatible, even IE6)
29
- *
30
- * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
31
- * Opera 11.6+, iOS 4.2+.
32
- *
33
- * Due to various browser bugs, sometimes the Object implementation will be used even
34
- * when the browser supports typed arrays.
35
- *
36
- * Note:
37
- *
38
- * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
39
- * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
40
- *
41
- * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
42
- *
43
- * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
44
- * incorrect length in some situations.
45
-
46
- * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
47
- * get the Object implementation, which is slower but behaves correctly.
48
- */
49
- Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
50
- ? global.TYPED_ARRAY_SUPPORT
51
- : typedArraySupport()
52
-
53
- /*
54
- * Export kMaxLength after typed array support is determined.
55
- */
56
- exports.kMaxLength = kMaxLength()
57
-
58
- function typedArraySupport () {
59
- try {
60
- var arr = new Uint8Array(1)
61
- arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
62
- return arr.foo() === 42 && // typed array instances can be augmented
63
- typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
64
- arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
65
- } catch (e) {
66
- return false
67
- }
68
- }
69
-
70
- function kMaxLength () {
71
- return Buffer.TYPED_ARRAY_SUPPORT
72
- ? 0x7fffffff
73
- : 0x3fffffff
74
- }
75
-
76
- function createBuffer (that, length) {
77
- if (kMaxLength() < length) {
78
- throw new RangeError('Invalid typed array length')
79
- }
80
- if (Buffer.TYPED_ARRAY_SUPPORT) {
81
- // Return an augmented `Uint8Array` instance, for best performance
82
- that = new Uint8Array(length)
83
- that.__proto__ = Buffer.prototype
84
- } else {
85
- // Fallback: Return an object instance of the Buffer class
86
- if (that === null) {
87
- that = new Buffer(length)
88
- }
89
- that.length = length
90
- }
91
-
92
- return that
93
- }
94
-
95
- /**
96
- * The Buffer constructor returns instances of `Uint8Array` that have their
97
- * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
98
- * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
99
- * and the `Uint8Array` methods. Square bracket notation works as expected -- it
100
- * returns a single octet.
101
- *
102
- * The `Uint8Array` prototype remains unmodified.
103
- */
104
-
105
- function Buffer (arg, encodingOrOffset, length) {
106
- if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
107
- return new Buffer(arg, encodingOrOffset, length)
108
- }
109
-
110
- // Common case.
111
- if (typeof arg === 'number') {
112
- if (typeof encodingOrOffset === 'string') {
113
- throw new Error(
114
- 'If encoding is specified then the first argument must be a string'
115
- )
116
- }
117
- return allocUnsafe(this, arg)
118
- }
119
- return from(this, arg, encodingOrOffset, length)
120
- }
121
-
122
- Buffer.poolSize = 8192 // not used by this implementation
123
-
124
- // TODO: Legacy, not needed anymore. Remove in next major version.
125
- Buffer._augment = function (arr) {
126
- arr.__proto__ = Buffer.prototype
127
- return arr
128
- }
129
-
130
- function from (that, value, encodingOrOffset, length) {
131
- if (typeof value === 'number') {
132
- throw new TypeError('"value" argument must not be a number')
133
- }
134
-
135
- if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
136
- return fromArrayBuffer(that, value, encodingOrOffset, length)
137
- }
138
-
139
- if (typeof value === 'string') {
140
- return fromString(that, value, encodingOrOffset)
141
- }
142
-
143
- return fromObject(that, value)
144
- }
145
-
146
- /**
147
- * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
148
- * if value is a number.
149
- * Buffer.from(str[, encoding])
150
- * Buffer.from(array)
151
- * Buffer.from(buffer)
152
- * Buffer.from(arrayBuffer[, byteOffset[, length]])
153
- **/
154
- Buffer.from = function (value, encodingOrOffset, length) {
155
- return from(null, value, encodingOrOffset, length)
156
- }
157
-
158
- if (Buffer.TYPED_ARRAY_SUPPORT) {
159
- Buffer.prototype.__proto__ = Uint8Array.prototype
160
- Buffer.__proto__ = Uint8Array
161
- if (typeof Symbol !== 'undefined' && Symbol.species &&
162
- Buffer[Symbol.species] === Buffer) {
163
- // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
164
- Object.defineProperty(Buffer, Symbol.species, {
165
- value: null,
166
- configurable: true
167
- })
168
- }
169
- }
170
-
171
- function assertSize (size) {
172
- if (typeof size !== 'number') {
173
- throw new TypeError('"size" argument must be a number')
174
- } else if (size < 0) {
175
- throw new RangeError('"size" argument must not be negative')
176
- }
177
- }
178
-
179
- function alloc (that, size, fill, encoding) {
180
- assertSize(size)
181
- if (size <= 0) {
182
- return createBuffer(that, size)
183
- }
184
- if (fill !== undefined) {
185
- // Only pay attention to encoding if it's a string. This
186
- // prevents accidentally sending in a number that would
187
- // be interpretted as a start offset.
188
- return typeof encoding === 'string'
189
- ? createBuffer(that, size).fill(fill, encoding)
190
- : createBuffer(that, size).fill(fill)
191
- }
192
- return createBuffer(that, size)
193
- }
194
-
195
- /**
196
- * Creates a new filled Buffer instance.
197
- * alloc(size[, fill[, encoding]])
198
- **/
199
- Buffer.alloc = function (size, fill, encoding) {
200
- return alloc(null, size, fill, encoding)
201
- }
202
-
203
- function allocUnsafe (that, size) {
204
- assertSize(size)
205
- that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
206
- if (!Buffer.TYPED_ARRAY_SUPPORT) {
207
- for (var i = 0; i < size; ++i) {
208
- that[i] = 0
209
- }
210
- }
211
- return that
212
- }
213
-
214
- /**
215
- * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
216
- * */
217
- Buffer.allocUnsafe = function (size) {
218
- return allocUnsafe(null, size)
219
- }
220
- /**
221
- * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
222
- */
223
- Buffer.allocUnsafeSlow = function (size) {
224
- return allocUnsafe(null, size)
225
- }
226
-
227
- function fromString (that, string, encoding) {
228
- if (typeof encoding !== 'string' || encoding === '') {
229
- encoding = 'utf8'
230
- }
231
-
232
- if (!Buffer.isEncoding(encoding)) {
233
- throw new TypeError('"encoding" must be a valid string encoding')
234
- }
235
-
236
- var length = byteLength(string, encoding) | 0
237
- that = createBuffer(that, length)
238
-
239
- var actual = that.write(string, encoding)
240
-
241
- if (actual !== length) {
242
- // Writing a hex string, for example, that contains invalid characters will
243
- // cause everything after the first invalid character to be ignored. (e.g.
244
- // 'abxxcd' will be treated as 'ab')
245
- that = that.slice(0, actual)
246
- }
247
-
248
- return that
249
- }
250
-
251
- function fromArrayLike (that, array) {
252
- var length = array.length < 0 ? 0 : checked(array.length) | 0
253
- that = createBuffer(that, length)
254
- for (var i = 0; i < length; i += 1) {
255
- that[i] = array[i] & 255
256
- }
257
- return that
258
- }
259
-
260
- function fromArrayBuffer (that, array, byteOffset, length) {
261
- array.byteLength // this throws if `array` is not a valid ArrayBuffer
262
-
263
- if (byteOffset < 0 || array.byteLength < byteOffset) {
264
- throw new RangeError('\'offset\' is out of bounds')
265
- }
266
-
267
- if (array.byteLength < byteOffset + (length || 0)) {
268
- throw new RangeError('\'length\' is out of bounds')
269
- }
270
-
271
- if (byteOffset === undefined && length === undefined) {
272
- array = new Uint8Array(array)
273
- } else if (length === undefined) {
274
- array = new Uint8Array(array, byteOffset)
275
- } else {
276
- array = new Uint8Array(array, byteOffset, length)
277
- }
278
-
279
- if (Buffer.TYPED_ARRAY_SUPPORT) {
280
- // Return an augmented `Uint8Array` instance, for best performance
281
- that = array
282
- that.__proto__ = Buffer.prototype
283
- } else {
284
- // Fallback: Return an object instance of the Buffer class
285
- that = fromArrayLike(that, array)
286
- }
287
- return that
288
- }
289
-
290
- function fromObject (that, obj) {
291
- if (Buffer.isBuffer(obj)) {
292
- var len = checked(obj.length) | 0
293
- that = createBuffer(that, len)
294
-
295
- if (that.length === 0) {
296
- return that
297
- }
298
-
299
- obj.copy(that, 0, 0, len)
300
- return that
301
- }
302
-
303
- if (obj) {
304
- if ((typeof ArrayBuffer !== 'undefined' &&
305
- obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
306
- if (typeof obj.length !== 'number' || isnan(obj.length)) {
307
- return createBuffer(that, 0)
308
- }
309
- return fromArrayLike(that, obj)
310
- }
311
-
312
- if (obj.type === 'Buffer' && isArray(obj.data)) {
313
- return fromArrayLike(that, obj.data)
314
- }
315
- }
316
-
317
- throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
318
- }
319
-
320
- function checked (length) {
321
- // Note: cannot use `length < kMaxLength()` here because that fails when
322
- // length is NaN (which is otherwise coerced to zero.)
323
- if (length >= kMaxLength()) {
324
- throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
325
- 'size: 0x' + kMaxLength().toString(16) + ' bytes')
326
- }
327
- return length | 0
328
- }
329
-
330
- function SlowBuffer (length) {
331
- if (+length != length) { // eslint-disable-line eqeqeq
332
- length = 0
333
- }
334
- return Buffer.alloc(+length)
335
- }
336
-
337
- Buffer.isBuffer = function isBuffer (b) {
338
- return !!(b != null && b._isBuffer)
339
- }
340
-
341
- Buffer.compare = function compare (a, b) {
342
- if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
343
- throw new TypeError('Arguments must be Buffers')
344
- }
345
-
346
- if (a === b) return 0
347
-
348
- var x = a.length
349
- var y = b.length
350
-
351
- for (var i = 0, len = Math.min(x, y); i < len; ++i) {
352
- if (a[i] !== b[i]) {
353
- x = a[i]
354
- y = b[i]
355
- break
356
- }
357
- }
358
-
359
- if (x < y) return -1
360
- if (y < x) return 1
361
- return 0
362
- }
363
-
364
- Buffer.isEncoding = function isEncoding (encoding) {
365
- switch (String(encoding).toLowerCase()) {
366
- case 'hex':
367
- case 'utf8':
368
- case 'utf-8':
369
- case 'ascii':
370
- case 'latin1':
371
- case 'binary':
372
- case 'base64':
373
- case 'ucs2':
374
- case 'ucs-2':
375
- case 'utf16le':
376
- case 'utf-16le':
377
- return true
378
- default:
379
- return false
380
- }
381
- }
382
-
383
- Buffer.concat = function concat (list, length) {
384
- if (!isArray(list)) {
385
- throw new TypeError('"list" argument must be an Array of Buffers')
386
- }
387
-
388
- if (list.length === 0) {
389
- return Buffer.alloc(0)
390
- }
391
-
392
- var i
393
- if (length === undefined) {
394
- length = 0
395
- for (i = 0; i < list.length; ++i) {
396
- length += list[i].length
397
- }
398
- }
399
-
400
- var buffer = Buffer.allocUnsafe(length)
401
- var pos = 0
402
- for (i = 0; i < list.length; ++i) {
403
- var buf = list[i]
404
- if (!Buffer.isBuffer(buf)) {
405
- throw new TypeError('"list" argument must be an Array of Buffers')
406
- }
407
- buf.copy(buffer, pos)
408
- pos += buf.length
409
- }
410
- return buffer
411
- }
412
-
413
- function byteLength (string, encoding) {
414
- if (Buffer.isBuffer(string)) {
415
- return string.length
416
- }
417
- if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
418
- (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
419
- return string.byteLength
420
- }
421
- if (typeof string !== 'string') {
422
- string = '' + string
423
- }
424
-
425
- var len = string.length
426
- if (len === 0) return 0
427
-
428
- // Use a for loop to avoid recursion
429
- var loweredCase = false
430
- for (;;) {
431
- switch (encoding) {
432
- case 'ascii':
433
- case 'latin1':
434
- case 'binary':
435
- return len
436
- case 'utf8':
437
- case 'utf-8':
438
- case undefined:
439
- return utf8ToBytes(string).length
440
- case 'ucs2':
441
- case 'ucs-2':
442
- case 'utf16le':
443
- case 'utf-16le':
444
- return len * 2
445
- case 'hex':
446
- return len >>> 1
447
- case 'base64':
448
- return base64ToBytes(string).length
449
- default:
450
- if (loweredCase) return utf8ToBytes(string).length // assume utf8
451
- encoding = ('' + encoding).toLowerCase()
452
- loweredCase = true
453
- }
454
- }
455
- }
456
- Buffer.byteLength = byteLength
457
-
458
- function slowToString (encoding, start, end) {
459
- var loweredCase = false
460
-
461
- // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
462
- // property of a typed array.
463
-
464
- // This behaves neither like String nor Uint8Array in that we set start/end
465
- // to their upper/lower bounds if the value passed is out of range.
466
- // undefined is handled specially as per ECMA-262 6th Edition,
467
- // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
468
- if (start === undefined || start < 0) {
469
- start = 0
470
- }
471
- // Return early if start > this.length. Done here to prevent potential uint32
472
- // coercion fail below.
473
- if (start > this.length) {
474
- return ''
475
- }
476
-
477
- if (end === undefined || end > this.length) {
478
- end = this.length
479
- }
480
-
481
- if (end <= 0) {
482
- return ''
483
- }
484
-
485
- // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
486
- end >>>= 0
487
- start >>>= 0
488
-
489
- if (end <= start) {
490
- return ''
491
- }
492
-
493
- if (!encoding) encoding = 'utf8'
494
-
495
- while (true) {
496
- switch (encoding) {
497
- case 'hex':
498
- return hexSlice(this, start, end)
499
-
500
- case 'utf8':
501
- case 'utf-8':
502
- return utf8Slice(this, start, end)
503
-
504
- case 'ascii':
505
- return asciiSlice(this, start, end)
506
-
507
- case 'latin1':
508
- case 'binary':
509
- return latin1Slice(this, start, end)
510
-
511
- case 'base64':
512
- return base64Slice(this, start, end)
513
-
514
- case 'ucs2':
515
- case 'ucs-2':
516
- case 'utf16le':
517
- case 'utf-16le':
518
- return utf16leSlice(this, start, end)
519
-
520
- default:
521
- if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
522
- encoding = (encoding + '').toLowerCase()
523
- loweredCase = true
524
- }
525
- }
526
- }
527
-
528
- // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
529
- // Buffer instances.
530
- Buffer.prototype._isBuffer = true
531
-
532
- function swap (b, n, m) {
533
- var i = b[n]
534
- b[n] = b[m]
535
- b[m] = i
536
- }
537
-
538
- Buffer.prototype.swap16 = function swap16 () {
539
- var len = this.length
540
- if (len % 2 !== 0) {
541
- throw new RangeError('Buffer size must be a multiple of 16-bits')
542
- }
543
- for (var i = 0; i < len; i += 2) {
544
- swap(this, i, i + 1)
545
- }
546
- return this
547
- }
548
-
549
- Buffer.prototype.swap32 = function swap32 () {
550
- var len = this.length
551
- if (len % 4 !== 0) {
552
- throw new RangeError('Buffer size must be a multiple of 32-bits')
553
- }
554
- for (var i = 0; i < len; i += 4) {
555
- swap(this, i, i + 3)
556
- swap(this, i + 1, i + 2)
557
- }
558
- return this
559
- }
560
-
561
- Buffer.prototype.swap64 = function swap64 () {
562
- var len = this.length
563
- if (len % 8 !== 0) {
564
- throw new RangeError('Buffer size must be a multiple of 64-bits')
565
- }
566
- for (var i = 0; i < len; i += 8) {
567
- swap(this, i, i + 7)
568
- swap(this, i + 1, i + 6)
569
- swap(this, i + 2, i + 5)
570
- swap(this, i + 3, i + 4)
571
- }
572
- return this
573
- }
574
-
575
- Buffer.prototype.toString = function toString () {
576
- var length = this.length | 0
577
- if (length === 0) return ''
578
- if (arguments.length === 0) return utf8Slice(this, 0, length)
579
- return slowToString.apply(this, arguments)
580
- }
581
-
582
- Buffer.prototype.equals = function equals (b) {
583
- if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
584
- if (this === b) return true
585
- return Buffer.compare(this, b) === 0
586
- }
587
-
588
- Buffer.prototype.inspect = function inspect () {
589
- var str = ''
590
- var max = exports.INSPECT_MAX_BYTES
591
- if (this.length > 0) {
592
- str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
593
- if (this.length > max) str += ' ... '
594
- }
595
- return '<Buffer ' + str + '>'
596
- }
597
-
598
- Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
599
- if (!Buffer.isBuffer(target)) {
600
- throw new TypeError('Argument must be a Buffer')
601
- }
602
-
603
- if (start === undefined) {
604
- start = 0
605
- }
606
- if (end === undefined) {
607
- end = target ? target.length : 0
608
- }
609
- if (thisStart === undefined) {
610
- thisStart = 0
611
- }
612
- if (thisEnd === undefined) {
613
- thisEnd = this.length
614
- }
615
-
616
- if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
617
- throw new RangeError('out of range index')
618
- }
619
-
620
- if (thisStart >= thisEnd && start >= end) {
621
- return 0
622
- }
623
- if (thisStart >= thisEnd) {
624
- return -1
625
- }
626
- if (start >= end) {
627
- return 1
628
- }
629
-
630
- start >>>= 0
631
- end >>>= 0
632
- thisStart >>>= 0
633
- thisEnd >>>= 0
634
-
635
- if (this === target) return 0
636
-
637
- var x = thisEnd - thisStart
638
- var y = end - start
639
- var len = Math.min(x, y)
640
-
641
- var thisCopy = this.slice(thisStart, thisEnd)
642
- var targetCopy = target.slice(start, end)
643
-
644
- for (var i = 0; i < len; ++i) {
645
- if (thisCopy[i] !== targetCopy[i]) {
646
- x = thisCopy[i]
647
- y = targetCopy[i]
648
- break
649
- }
650
- }
651
-
652
- if (x < y) return -1
653
- if (y < x) return 1
654
- return 0
655
- }
656
-
657
- // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
658
- // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
659
- //
660
- // Arguments:
661
- // - buffer - a Buffer to search
662
- // - val - a string, Buffer, or number
663
- // - byteOffset - an index into `buffer`; will be clamped to an int32
664
- // - encoding - an optional encoding, relevant is val is a string
665
- // - dir - true for indexOf, false for lastIndexOf
666
- function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
667
- // Empty buffer means no match
668
- if (buffer.length === 0) return -1
669
-
670
- // Normalize byteOffset
671
- if (typeof byteOffset === 'string') {
672
- encoding = byteOffset
673
- byteOffset = 0
674
- } else if (byteOffset > 0x7fffffff) {
675
- byteOffset = 0x7fffffff
676
- } else if (byteOffset < -0x80000000) {
677
- byteOffset = -0x80000000
678
- }
679
- byteOffset = +byteOffset // Coerce to Number.
680
- if (isNaN(byteOffset)) {
681
- // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
682
- byteOffset = dir ? 0 : (buffer.length - 1)
683
- }
684
-
685
- // Normalize byteOffset: negative offsets start from the end of the buffer
686
- if (byteOffset < 0) byteOffset = buffer.length + byteOffset
687
- if (byteOffset >= buffer.length) {
688
- if (dir) return -1
689
- else byteOffset = buffer.length - 1
690
- } else if (byteOffset < 0) {
691
- if (dir) byteOffset = 0
692
- else return -1
693
- }
694
-
695
- // Normalize val
696
- if (typeof val === 'string') {
697
- val = Buffer.from(val, encoding)
698
- }
699
-
700
- // Finally, search either indexOf (if dir is true) or lastIndexOf
701
- if (Buffer.isBuffer(val)) {
702
- // Special case: looking for empty string/buffer always fails
703
- if (val.length === 0) {
704
- return -1
705
- }
706
- return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
707
- } else if (typeof val === 'number') {
708
- val = val & 0xFF // Search for a byte value [0-255]
709
- if (Buffer.TYPED_ARRAY_SUPPORT &&
710
- typeof Uint8Array.prototype.indexOf === 'function') {
711
- if (dir) {
712
- return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
713
- } else {
714
- return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
715
- }
716
- }
717
- return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
718
- }
719
-
720
- throw new TypeError('val must be string, number or Buffer')
721
- }
722
-
723
- function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
724
- var indexSize = 1
725
- var arrLength = arr.length
726
- var valLength = val.length
727
-
728
- if (encoding !== undefined) {
729
- encoding = String(encoding).toLowerCase()
730
- if (encoding === 'ucs2' || encoding === 'ucs-2' ||
731
- encoding === 'utf16le' || encoding === 'utf-16le') {
732
- if (arr.length < 2 || val.length < 2) {
733
- return -1
734
- }
735
- indexSize = 2
736
- arrLength /= 2
737
- valLength /= 2
738
- byteOffset /= 2
739
- }
740
- }
741
-
742
- function read (buf, i) {
743
- if (indexSize === 1) {
744
- return buf[i]
745
- } else {
746
- return buf.readUInt16BE(i * indexSize)
747
- }
748
- }
749
-
750
- var i
751
- if (dir) {
752
- var foundIndex = -1
753
- for (i = byteOffset; i < arrLength; i++) {
754
- if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
755
- if (foundIndex === -1) foundIndex = i
756
- if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
757
- } else {
758
- if (foundIndex !== -1) i -= i - foundIndex
759
- foundIndex = -1
760
- }
761
- }
762
- } else {
763
- if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
764
- for (i = byteOffset; i >= 0; i--) {
765
- var found = true
766
- for (var j = 0; j < valLength; j++) {
767
- if (read(arr, i + j) !== read(val, j)) {
768
- found = false
769
- break
770
- }
771
- }
772
- if (found) return i
773
- }
774
- }
775
-
776
- return -1
777
- }
778
-
779
- Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
780
- return this.indexOf(val, byteOffset, encoding) !== -1
781
- }
782
-
783
- Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
784
- return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
785
- }
786
-
787
- Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
788
- return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
789
- }
790
-
791
- function hexWrite (buf, string, offset, length) {
792
- offset = Number(offset) || 0
793
- var remaining = buf.length - offset
794
- if (!length) {
795
- length = remaining
796
- } else {
797
- length = Number(length)
798
- if (length > remaining) {
799
- length = remaining
800
- }
801
- }
802
-
803
- // must be an even number of digits
804
- var strLen = string.length
805
- if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
806
-
807
- if (length > strLen / 2) {
808
- length = strLen / 2
809
- }
810
- for (var i = 0; i < length; ++i) {
811
- var parsed = parseInt(string.substr(i * 2, 2), 16)
812
- if (isNaN(parsed)) return i
813
- buf[offset + i] = parsed
814
- }
815
- return i
816
- }
817
-
818
- function utf8Write (buf, string, offset, length) {
819
- return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
820
- }
821
-
822
- function asciiWrite (buf, string, offset, length) {
823
- return blitBuffer(asciiToBytes(string), buf, offset, length)
824
- }
825
-
826
- function latin1Write (buf, string, offset, length) {
827
- return asciiWrite(buf, string, offset, length)
828
- }
829
-
830
- function base64Write (buf, string, offset, length) {
831
- return blitBuffer(base64ToBytes(string), buf, offset, length)
832
- }
833
-
834
- function ucs2Write (buf, string, offset, length) {
835
- return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
836
- }
837
-
838
- Buffer.prototype.write = function write (string, offset, length, encoding) {
839
- // Buffer#write(string)
840
- if (offset === undefined) {
841
- encoding = 'utf8'
842
- length = this.length
843
- offset = 0
844
- // Buffer#write(string, encoding)
845
- } else if (length === undefined && typeof offset === 'string') {
846
- encoding = offset
847
- length = this.length
848
- offset = 0
849
- // Buffer#write(string, offset[, length][, encoding])
850
- } else if (isFinite(offset)) {
851
- offset = offset | 0
852
- if (isFinite(length)) {
853
- length = length | 0
854
- if (encoding === undefined) encoding = 'utf8'
855
- } else {
856
- encoding = length
857
- length = undefined
858
- }
859
- // legacy write(string, encoding, offset, length) - remove in v0.13
860
- } else {
861
- throw new Error(
862
- 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
863
- )
864
- }
865
-
866
- var remaining = this.length - offset
867
- if (length === undefined || length > remaining) length = remaining
868
-
869
- if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
870
- throw new RangeError('Attempt to write outside buffer bounds')
871
- }
872
-
873
- if (!encoding) encoding = 'utf8'
874
-
875
- var loweredCase = false
876
- for (;;) {
877
- switch (encoding) {
878
- case 'hex':
879
- return hexWrite(this, string, offset, length)
880
-
881
- case 'utf8':
882
- case 'utf-8':
883
- return utf8Write(this, string, offset, length)
884
-
885
- case 'ascii':
886
- return asciiWrite(this, string, offset, length)
887
-
888
- case 'latin1':
889
- case 'binary':
890
- return latin1Write(this, string, offset, length)
891
-
892
- case 'base64':
893
- // Warning: maxLength not taken into account in base64Write
894
- return base64Write(this, string, offset, length)
895
-
896
- case 'ucs2':
897
- case 'ucs-2':
898
- case 'utf16le':
899
- case 'utf-16le':
900
- return ucs2Write(this, string, offset, length)
901
-
902
- default:
903
- if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
904
- encoding = ('' + encoding).toLowerCase()
905
- loweredCase = true
906
- }
907
- }
908
- }
909
-
910
- Buffer.prototype.toJSON = function toJSON () {
911
- return {
912
- type: 'Buffer',
913
- data: Array.prototype.slice.call(this._arr || this, 0)
914
- }
915
- }
916
-
917
- function base64Slice (buf, start, end) {
918
- if (start === 0 && end === buf.length) {
919
- return base64.fromByteArray(buf)
920
- } else {
921
- return base64.fromByteArray(buf.slice(start, end))
922
- }
923
- }
924
-
925
- function utf8Slice (buf, start, end) {
926
- end = Math.min(buf.length, end)
927
- var res = []
928
-
929
- var i = start
930
- while (i < end) {
931
- var firstByte = buf[i]
932
- var codePoint = null
933
- var bytesPerSequence = (firstByte > 0xEF) ? 4
934
- : (firstByte > 0xDF) ? 3
935
- : (firstByte > 0xBF) ? 2
936
- : 1
937
-
938
- if (i + bytesPerSequence <= end) {
939
- var secondByte, thirdByte, fourthByte, tempCodePoint
940
-
941
- switch (bytesPerSequence) {
942
- case 1:
943
- if (firstByte < 0x80) {
944
- codePoint = firstByte
945
- }
946
- break
947
- case 2:
948
- secondByte = buf[i + 1]
949
- if ((secondByte & 0xC0) === 0x80) {
950
- tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
951
- if (tempCodePoint > 0x7F) {
952
- codePoint = tempCodePoint
953
- }
954
- }
955
- break
956
- case 3:
957
- secondByte = buf[i + 1]
958
- thirdByte = buf[i + 2]
959
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
960
- tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
961
- if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
962
- codePoint = tempCodePoint
963
- }
964
- }
965
- break
966
- case 4:
967
- secondByte = buf[i + 1]
968
- thirdByte = buf[i + 2]
969
- fourthByte = buf[i + 3]
970
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
971
- tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
972
- if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
973
- codePoint = tempCodePoint
974
- }
975
- }
976
- }
977
- }
978
-
979
- if (codePoint === null) {
980
- // we did not generate a valid codePoint so insert a
981
- // replacement char (U+FFFD) and advance only 1 byte
982
- codePoint = 0xFFFD
983
- bytesPerSequence = 1
984
- } else if (codePoint > 0xFFFF) {
985
- // encode to utf16 (surrogate pair dance)
986
- codePoint -= 0x10000
987
- res.push(codePoint >>> 10 & 0x3FF | 0xD800)
988
- codePoint = 0xDC00 | codePoint & 0x3FF
989
- }
990
-
991
- res.push(codePoint)
992
- i += bytesPerSequence
993
- }
994
-
995
- return decodeCodePointsArray(res)
996
- }
997
-
998
- // Based on http://stackoverflow.com/a/22747272/680742, the browser with
999
- // the lowest limit is Chrome, with 0x10000 args.
1000
- // We go 1 magnitude less, for safety
1001
- var MAX_ARGUMENTS_LENGTH = 0x1000
1002
-
1003
- function decodeCodePointsArray (codePoints) {
1004
- var len = codePoints.length
1005
- if (len <= MAX_ARGUMENTS_LENGTH) {
1006
- return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
1007
- }
1008
-
1009
- // Decode in chunks to avoid "call stack size exceeded".
1010
- var res = ''
1011
- var i = 0
1012
- while (i < len) {
1013
- res += String.fromCharCode.apply(
1014
- String,
1015
- codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
1016
- )
1017
- }
1018
- return res
1019
- }
1020
-
1021
- function asciiSlice (buf, start, end) {
1022
- var ret = ''
1023
- end = Math.min(buf.length, end)
1024
-
1025
- for (var i = start; i < end; ++i) {
1026
- ret += String.fromCharCode(buf[i] & 0x7F)
1027
- }
1028
- return ret
1029
- }
1030
-
1031
- function latin1Slice (buf, start, end) {
1032
- var ret = ''
1033
- end = Math.min(buf.length, end)
1034
-
1035
- for (var i = start; i < end; ++i) {
1036
- ret += String.fromCharCode(buf[i])
1037
- }
1038
- return ret
1039
- }
1040
-
1041
- function hexSlice (buf, start, end) {
1042
- var len = buf.length
1043
-
1044
- if (!start || start < 0) start = 0
1045
- if (!end || end < 0 || end > len) end = len
1046
-
1047
- var out = ''
1048
- for (var i = start; i < end; ++i) {
1049
- out += toHex(buf[i])
1050
- }
1051
- return out
1052
- }
1053
-
1054
- function utf16leSlice (buf, start, end) {
1055
- var bytes = buf.slice(start, end)
1056
- var res = ''
1057
- for (var i = 0; i < bytes.length; i += 2) {
1058
- res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
1059
- }
1060
- return res
1061
- }
1062
-
1063
- Buffer.prototype.slice = function slice (start, end) {
1064
- var len = this.length
1065
- start = ~~start
1066
- end = end === undefined ? len : ~~end
1067
-
1068
- if (start < 0) {
1069
- start += len
1070
- if (start < 0) start = 0
1071
- } else if (start > len) {
1072
- start = len
1073
- }
1074
-
1075
- if (end < 0) {
1076
- end += len
1077
- if (end < 0) end = 0
1078
- } else if (end > len) {
1079
- end = len
1080
- }
1081
-
1082
- if (end < start) end = start
1083
-
1084
- var newBuf
1085
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1086
- newBuf = this.subarray(start, end)
1087
- newBuf.__proto__ = Buffer.prototype
1088
- } else {
1089
- var sliceLen = end - start
1090
- newBuf = new Buffer(sliceLen, undefined)
1091
- for (var i = 0; i < sliceLen; ++i) {
1092
- newBuf[i] = this[i + start]
1093
- }
1094
- }
1095
-
1096
- return newBuf
1097
- }
1098
-
1099
- /*
1100
- * Need to make sure that buffer isn't trying to write out of bounds.
1101
- */
1102
- function checkOffset (offset, ext, length) {
1103
- if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
1104
- if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
1105
- }
1106
-
1107
- Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
1108
- offset = offset | 0
1109
- byteLength = byteLength | 0
1110
- if (!noAssert) checkOffset(offset, byteLength, this.length)
1111
-
1112
- var val = this[offset]
1113
- var mul = 1
1114
- var i = 0
1115
- while (++i < byteLength && (mul *= 0x100)) {
1116
- val += this[offset + i] * mul
1117
- }
1118
-
1119
- return val
1120
- }
1121
-
1122
- Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
1123
- offset = offset | 0
1124
- byteLength = byteLength | 0
1125
- if (!noAssert) {
1126
- checkOffset(offset, byteLength, this.length)
1127
- }
1128
-
1129
- var val = this[offset + --byteLength]
1130
- var mul = 1
1131
- while (byteLength > 0 && (mul *= 0x100)) {
1132
- val += this[offset + --byteLength] * mul
1133
- }
1134
-
1135
- return val
1136
- }
1137
-
1138
- Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
1139
- if (!noAssert) checkOffset(offset, 1, this.length)
1140
- return this[offset]
1141
- }
1142
-
1143
- Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
1144
- if (!noAssert) checkOffset(offset, 2, this.length)
1145
- return this[offset] | (this[offset + 1] << 8)
1146
- }
1147
-
1148
- Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
1149
- if (!noAssert) checkOffset(offset, 2, this.length)
1150
- return (this[offset] << 8) | this[offset + 1]
1151
- }
1152
-
1153
- Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
1154
- if (!noAssert) checkOffset(offset, 4, this.length)
1155
-
1156
- return ((this[offset]) |
1157
- (this[offset + 1] << 8) |
1158
- (this[offset + 2] << 16)) +
1159
- (this[offset + 3] * 0x1000000)
1160
- }
1161
-
1162
- Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
1163
- if (!noAssert) checkOffset(offset, 4, this.length)
1164
-
1165
- return (this[offset] * 0x1000000) +
1166
- ((this[offset + 1] << 16) |
1167
- (this[offset + 2] << 8) |
1168
- this[offset + 3])
1169
- }
1170
-
1171
- Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
1172
- offset = offset | 0
1173
- byteLength = byteLength | 0
1174
- if (!noAssert) checkOffset(offset, byteLength, this.length)
1175
-
1176
- var val = this[offset]
1177
- var mul = 1
1178
- var i = 0
1179
- while (++i < byteLength && (mul *= 0x100)) {
1180
- val += this[offset + i] * mul
1181
- }
1182
- mul *= 0x80
1183
-
1184
- if (val >= mul) val -= Math.pow(2, 8 * byteLength)
1185
-
1186
- return val
1187
- }
1188
-
1189
- Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
1190
- offset = offset | 0
1191
- byteLength = byteLength | 0
1192
- if (!noAssert) checkOffset(offset, byteLength, this.length)
1193
-
1194
- var i = byteLength
1195
- var mul = 1
1196
- var val = this[offset + --i]
1197
- while (i > 0 && (mul *= 0x100)) {
1198
- val += this[offset + --i] * mul
1199
- }
1200
- mul *= 0x80
1201
-
1202
- if (val >= mul) val -= Math.pow(2, 8 * byteLength)
1203
-
1204
- return val
1205
- }
1206
-
1207
- Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
1208
- if (!noAssert) checkOffset(offset, 1, this.length)
1209
- if (!(this[offset] & 0x80)) return (this[offset])
1210
- return ((0xff - this[offset] + 1) * -1)
1211
- }
1212
-
1213
- Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
1214
- if (!noAssert) checkOffset(offset, 2, this.length)
1215
- var val = this[offset] | (this[offset + 1] << 8)
1216
- return (val & 0x8000) ? val | 0xFFFF0000 : val
1217
- }
1218
-
1219
- Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
1220
- if (!noAssert) checkOffset(offset, 2, this.length)
1221
- var val = this[offset + 1] | (this[offset] << 8)
1222
- return (val & 0x8000) ? val | 0xFFFF0000 : val
1223
- }
1224
-
1225
- Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
1226
- if (!noAssert) checkOffset(offset, 4, this.length)
1227
-
1228
- return (this[offset]) |
1229
- (this[offset + 1] << 8) |
1230
- (this[offset + 2] << 16) |
1231
- (this[offset + 3] << 24)
1232
- }
1233
-
1234
- Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
1235
- if (!noAssert) checkOffset(offset, 4, this.length)
1236
-
1237
- return (this[offset] << 24) |
1238
- (this[offset + 1] << 16) |
1239
- (this[offset + 2] << 8) |
1240
- (this[offset + 3])
1241
- }
1242
-
1243
- Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
1244
- if (!noAssert) checkOffset(offset, 4, this.length)
1245
- return ieee754.read(this, offset, true, 23, 4)
1246
- }
1247
-
1248
- Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
1249
- if (!noAssert) checkOffset(offset, 4, this.length)
1250
- return ieee754.read(this, offset, false, 23, 4)
1251
- }
1252
-
1253
- Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
1254
- if (!noAssert) checkOffset(offset, 8, this.length)
1255
- return ieee754.read(this, offset, true, 52, 8)
1256
- }
1257
-
1258
- Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
1259
- if (!noAssert) checkOffset(offset, 8, this.length)
1260
- return ieee754.read(this, offset, false, 52, 8)
1261
- }
1262
-
1263
- function checkInt (buf, value, offset, ext, max, min) {
1264
- if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
1265
- if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
1266
- if (offset + ext > buf.length) throw new RangeError('Index out of range')
1267
- }
1268
-
1269
- Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
1270
- value = +value
1271
- offset = offset | 0
1272
- byteLength = byteLength | 0
1273
- if (!noAssert) {
1274
- var maxBytes = Math.pow(2, 8 * byteLength) - 1
1275
- checkInt(this, value, offset, byteLength, maxBytes, 0)
1276
- }
1277
-
1278
- var mul = 1
1279
- var i = 0
1280
- this[offset] = value & 0xFF
1281
- while (++i < byteLength && (mul *= 0x100)) {
1282
- this[offset + i] = (value / mul) & 0xFF
1283
- }
1284
-
1285
- return offset + byteLength
1286
- }
1287
-
1288
- Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
1289
- value = +value
1290
- offset = offset | 0
1291
- byteLength = byteLength | 0
1292
- if (!noAssert) {
1293
- var maxBytes = Math.pow(2, 8 * byteLength) - 1
1294
- checkInt(this, value, offset, byteLength, maxBytes, 0)
1295
- }
1296
-
1297
- var i = byteLength - 1
1298
- var mul = 1
1299
- this[offset + i] = value & 0xFF
1300
- while (--i >= 0 && (mul *= 0x100)) {
1301
- this[offset + i] = (value / mul) & 0xFF
1302
- }
1303
-
1304
- return offset + byteLength
1305
- }
1306
-
1307
- Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
1308
- value = +value
1309
- offset = offset | 0
1310
- if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
1311
- if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
1312
- this[offset] = (value & 0xff)
1313
- return offset + 1
1314
- }
1315
-
1316
- function objectWriteUInt16 (buf, value, offset, littleEndian) {
1317
- if (value < 0) value = 0xffff + value + 1
1318
- for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
1319
- buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
1320
- (littleEndian ? i : 1 - i) * 8
1321
- }
1322
- }
1323
-
1324
- Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
1325
- value = +value
1326
- offset = offset | 0
1327
- if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
1328
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1329
- this[offset] = (value & 0xff)
1330
- this[offset + 1] = (value >>> 8)
1331
- } else {
1332
- objectWriteUInt16(this, value, offset, true)
1333
- }
1334
- return offset + 2
1335
- }
1336
-
1337
- Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
1338
- value = +value
1339
- offset = offset | 0
1340
- if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
1341
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1342
- this[offset] = (value >>> 8)
1343
- this[offset + 1] = (value & 0xff)
1344
- } else {
1345
- objectWriteUInt16(this, value, offset, false)
1346
- }
1347
- return offset + 2
1348
- }
1349
-
1350
- function objectWriteUInt32 (buf, value, offset, littleEndian) {
1351
- if (value < 0) value = 0xffffffff + value + 1
1352
- for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
1353
- buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
1354
- }
1355
- }
1356
-
1357
- Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
1358
- value = +value
1359
- offset = offset | 0
1360
- if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
1361
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1362
- this[offset + 3] = (value >>> 24)
1363
- this[offset + 2] = (value >>> 16)
1364
- this[offset + 1] = (value >>> 8)
1365
- this[offset] = (value & 0xff)
1366
- } else {
1367
- objectWriteUInt32(this, value, offset, true)
1368
- }
1369
- return offset + 4
1370
- }
1371
-
1372
- Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
1373
- value = +value
1374
- offset = offset | 0
1375
- if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
1376
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1377
- this[offset] = (value >>> 24)
1378
- this[offset + 1] = (value >>> 16)
1379
- this[offset + 2] = (value >>> 8)
1380
- this[offset + 3] = (value & 0xff)
1381
- } else {
1382
- objectWriteUInt32(this, value, offset, false)
1383
- }
1384
- return offset + 4
1385
- }
1386
-
1387
- Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
1388
- value = +value
1389
- offset = offset | 0
1390
- if (!noAssert) {
1391
- var limit = Math.pow(2, 8 * byteLength - 1)
1392
-
1393
- checkInt(this, value, offset, byteLength, limit - 1, -limit)
1394
- }
1395
-
1396
- var i = 0
1397
- var mul = 1
1398
- var sub = 0
1399
- this[offset] = value & 0xFF
1400
- while (++i < byteLength && (mul *= 0x100)) {
1401
- if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
1402
- sub = 1
1403
- }
1404
- this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
1405
- }
1406
-
1407
- return offset + byteLength
1408
- }
1409
-
1410
- Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
1411
- value = +value
1412
- offset = offset | 0
1413
- if (!noAssert) {
1414
- var limit = Math.pow(2, 8 * byteLength - 1)
1415
-
1416
- checkInt(this, value, offset, byteLength, limit - 1, -limit)
1417
- }
1418
-
1419
- var i = byteLength - 1
1420
- var mul = 1
1421
- var sub = 0
1422
- this[offset + i] = value & 0xFF
1423
- while (--i >= 0 && (mul *= 0x100)) {
1424
- if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
1425
- sub = 1
1426
- }
1427
- this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
1428
- }
1429
-
1430
- return offset + byteLength
1431
- }
1432
-
1433
- Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
1434
- value = +value
1435
- offset = offset | 0
1436
- if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
1437
- if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
1438
- if (value < 0) value = 0xff + value + 1
1439
- this[offset] = (value & 0xff)
1440
- return offset + 1
1441
- }
1442
-
1443
- Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
1444
- value = +value
1445
- offset = offset | 0
1446
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
1447
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1448
- this[offset] = (value & 0xff)
1449
- this[offset + 1] = (value >>> 8)
1450
- } else {
1451
- objectWriteUInt16(this, value, offset, true)
1452
- }
1453
- return offset + 2
1454
- }
1455
-
1456
- Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
1457
- value = +value
1458
- offset = offset | 0
1459
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
1460
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1461
- this[offset] = (value >>> 8)
1462
- this[offset + 1] = (value & 0xff)
1463
- } else {
1464
- objectWriteUInt16(this, value, offset, false)
1465
- }
1466
- return offset + 2
1467
- }
1468
-
1469
- Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
1470
- value = +value
1471
- offset = offset | 0
1472
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
1473
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1474
- this[offset] = (value & 0xff)
1475
- this[offset + 1] = (value >>> 8)
1476
- this[offset + 2] = (value >>> 16)
1477
- this[offset + 3] = (value >>> 24)
1478
- } else {
1479
- objectWriteUInt32(this, value, offset, true)
1480
- }
1481
- return offset + 4
1482
- }
1483
-
1484
- Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
1485
- value = +value
1486
- offset = offset | 0
1487
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
1488
- if (value < 0) value = 0xffffffff + value + 1
1489
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1490
- this[offset] = (value >>> 24)
1491
- this[offset + 1] = (value >>> 16)
1492
- this[offset + 2] = (value >>> 8)
1493
- this[offset + 3] = (value & 0xff)
1494
- } else {
1495
- objectWriteUInt32(this, value, offset, false)
1496
- }
1497
- return offset + 4
1498
- }
1499
-
1500
- function checkIEEE754 (buf, value, offset, ext, max, min) {
1501
- if (offset + ext > buf.length) throw new RangeError('Index out of range')
1502
- if (offset < 0) throw new RangeError('Index out of range')
1503
- }
1504
-
1505
- function writeFloat (buf, value, offset, littleEndian, noAssert) {
1506
- if (!noAssert) {
1507
- checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
1508
- }
1509
- ieee754.write(buf, value, offset, littleEndian, 23, 4)
1510
- return offset + 4
1511
- }
1512
-
1513
- Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
1514
- return writeFloat(this, value, offset, true, noAssert)
1515
- }
1516
-
1517
- Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
1518
- return writeFloat(this, value, offset, false, noAssert)
1519
- }
1520
-
1521
- function writeDouble (buf, value, offset, littleEndian, noAssert) {
1522
- if (!noAssert) {
1523
- checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
1524
- }
1525
- ieee754.write(buf, value, offset, littleEndian, 52, 8)
1526
- return offset + 8
1527
- }
1528
-
1529
- Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
1530
- return writeDouble(this, value, offset, true, noAssert)
1531
- }
1532
-
1533
- Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
1534
- return writeDouble(this, value, offset, false, noAssert)
1535
- }
1536
-
1537
- // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
1538
- Buffer.prototype.copy = function copy (target, targetStart, start, end) {
1539
- if (!start) start = 0
1540
- if (!end && end !== 0) end = this.length
1541
- if (targetStart >= target.length) targetStart = target.length
1542
- if (!targetStart) targetStart = 0
1543
- if (end > 0 && end < start) end = start
1544
-
1545
- // Copy 0 bytes; we're done
1546
- if (end === start) return 0
1547
- if (target.length === 0 || this.length === 0) return 0
1548
-
1549
- // Fatal error conditions
1550
- if (targetStart < 0) {
1551
- throw new RangeError('targetStart out of bounds')
1552
- }
1553
- if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
1554
- if (end < 0) throw new RangeError('sourceEnd out of bounds')
1555
-
1556
- // Are we oob?
1557
- if (end > this.length) end = this.length
1558
- if (target.length - targetStart < end - start) {
1559
- end = target.length - targetStart + start
1560
- }
1561
-
1562
- var len = end - start
1563
- var i
1564
-
1565
- if (this === target && start < targetStart && targetStart < end) {
1566
- // descending copy from end
1567
- for (i = len - 1; i >= 0; --i) {
1568
- target[i + targetStart] = this[i + start]
1569
- }
1570
- } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
1571
- // ascending copy from start
1572
- for (i = 0; i < len; ++i) {
1573
- target[i + targetStart] = this[i + start]
1574
- }
1575
- } else {
1576
- Uint8Array.prototype.set.call(
1577
- target,
1578
- this.subarray(start, start + len),
1579
- targetStart
1580
- )
1581
- }
1582
-
1583
- return len
1584
- }
1585
-
1586
- // Usage:
1587
- // buffer.fill(number[, offset[, end]])
1588
- // buffer.fill(buffer[, offset[, end]])
1589
- // buffer.fill(string[, offset[, end]][, encoding])
1590
- Buffer.prototype.fill = function fill (val, start, end, encoding) {
1591
- // Handle string cases:
1592
- if (typeof val === 'string') {
1593
- if (typeof start === 'string') {
1594
- encoding = start
1595
- start = 0
1596
- end = this.length
1597
- } else if (typeof end === 'string') {
1598
- encoding = end
1599
- end = this.length
1600
- }
1601
- if (val.length === 1) {
1602
- var code = val.charCodeAt(0)
1603
- if (code < 256) {
1604
- val = code
1605
- }
1606
- }
1607
- if (encoding !== undefined && typeof encoding !== 'string') {
1608
- throw new TypeError('encoding must be a string')
1609
- }
1610
- if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
1611
- throw new TypeError('Unknown encoding: ' + encoding)
1612
- }
1613
- } else if (typeof val === 'number') {
1614
- val = val & 255
1615
- }
1616
-
1617
- // Invalid ranges are not set to a default, so can range check early.
1618
- if (start < 0 || this.length < start || this.length < end) {
1619
- throw new RangeError('Out of range index')
1620
- }
1621
-
1622
- if (end <= start) {
1623
- return this
1624
- }
1625
-
1626
- start = start >>> 0
1627
- end = end === undefined ? this.length : end >>> 0
1628
-
1629
- if (!val) val = 0
1630
-
1631
- var i
1632
- if (typeof val === 'number') {
1633
- for (i = start; i < end; ++i) {
1634
- this[i] = val
1635
- }
1636
- } else {
1637
- var bytes = Buffer.isBuffer(val)
1638
- ? val
1639
- : utf8ToBytes(new Buffer(val, encoding).toString())
1640
- var len = bytes.length
1641
- for (i = 0; i < end - start; ++i) {
1642
- this[i + start] = bytes[i % len]
1643
- }
1644
- }
1645
-
1646
- return this
1647
- }
1648
-
1649
- // HELPER FUNCTIONS
1650
- // ================
1651
-
1652
- var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
1653
-
1654
- function base64clean (str) {
1655
- // Node strips out invalid characters like \n and \t from the string, base64-js does not
1656
- str = stringtrim(str).replace(INVALID_BASE64_RE, '')
1657
- // Node converts strings with length < 2 to ''
1658
- if (str.length < 2) return ''
1659
- // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
1660
- while (str.length % 4 !== 0) {
1661
- str = str + '='
1662
- }
1663
- return str
1664
- }
1665
-
1666
- function stringtrim (str) {
1667
- if (str.trim) return str.trim()
1668
- return str.replace(/^\s+|\s+$/g, '')
1669
- }
1670
-
1671
- function toHex (n) {
1672
- if (n < 16) return '0' + n.toString(16)
1673
- return n.toString(16)
1674
- }
1675
-
1676
- function utf8ToBytes (string, units) {
1677
- units = units || Infinity
1678
- var codePoint
1679
- var length = string.length
1680
- var leadSurrogate = null
1681
- var bytes = []
1682
-
1683
- for (var i = 0; i < length; ++i) {
1684
- codePoint = string.charCodeAt(i)
1685
-
1686
- // is surrogate component
1687
- if (codePoint > 0xD7FF && codePoint < 0xE000) {
1688
- // last char was a lead
1689
- if (!leadSurrogate) {
1690
- // no lead yet
1691
- if (codePoint > 0xDBFF) {
1692
- // unexpected trail
1693
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
1694
- continue
1695
- } else if (i + 1 === length) {
1696
- // unpaired lead
1697
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
1698
- continue
1699
- }
1700
-
1701
- // valid lead
1702
- leadSurrogate = codePoint
1703
-
1704
- continue
1705
- }
1706
-
1707
- // 2 leads in a row
1708
- if (codePoint < 0xDC00) {
1709
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
1710
- leadSurrogate = codePoint
1711
- continue
1712
- }
1713
-
1714
- // valid surrogate pair
1715
- codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
1716
- } else if (leadSurrogate) {
1717
- // valid bmp char, but last char was a lead
1718
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
1719
- }
1720
-
1721
- leadSurrogate = null
1722
-
1723
- // encode utf8
1724
- if (codePoint < 0x80) {
1725
- if ((units -= 1) < 0) break
1726
- bytes.push(codePoint)
1727
- } else if (codePoint < 0x800) {
1728
- if ((units -= 2) < 0) break
1729
- bytes.push(
1730
- codePoint >> 0x6 | 0xC0,
1731
- codePoint & 0x3F | 0x80
1732
- )
1733
- } else if (codePoint < 0x10000) {
1734
- if ((units -= 3) < 0) break
1735
- bytes.push(
1736
- codePoint >> 0xC | 0xE0,
1737
- codePoint >> 0x6 & 0x3F | 0x80,
1738
- codePoint & 0x3F | 0x80
1739
- )
1740
- } else if (codePoint < 0x110000) {
1741
- if ((units -= 4) < 0) break
1742
- bytes.push(
1743
- codePoint >> 0x12 | 0xF0,
1744
- codePoint >> 0xC & 0x3F | 0x80,
1745
- codePoint >> 0x6 & 0x3F | 0x80,
1746
- codePoint & 0x3F | 0x80
1747
- )
1748
- } else {
1749
- throw new Error('Invalid code point')
1750
- }
1751
- }
1752
-
1753
- return bytes
1754
- }
1755
-
1756
- function asciiToBytes (str) {
1757
- var byteArray = []
1758
- for (var i = 0; i < str.length; ++i) {
1759
- // Node's code seems to be doing this and not & 0x7F..
1760
- byteArray.push(str.charCodeAt(i) & 0xFF)
1761
- }
1762
- return byteArray
1763
- }
1764
-
1765
- function utf16leToBytes (str, units) {
1766
- var c, hi, lo
1767
- var byteArray = []
1768
- for (var i = 0; i < str.length; ++i) {
1769
- if ((units -= 2) < 0) break
1770
-
1771
- c = str.charCodeAt(i)
1772
- hi = c >> 8
1773
- lo = c % 256
1774
- byteArray.push(lo)
1775
- byteArray.push(hi)
1776
- }
1777
-
1778
- return byteArray
1779
- }
1780
-
1781
- function base64ToBytes (str) {
1782
- return base64.toByteArray(base64clean(str))
1783
- }
1784
-
1785
- function blitBuffer (src, dst, offset, length) {
1786
- for (var i = 0; i < length; ++i) {
1787
- if ((i + offset >= dst.length) || (i >= src.length)) break
1788
- dst[i + offset] = src[i]
1789
- }
1790
- return i
1791
- }
1792
-
1793
- function isnan (val) {
1794
- return val !== val // eslint-disable-line no-self-compare
1795
- }
1796
-
1797
- /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__("c8ba")))
1798
-
1799
- /***/ })
1800
-
1801
- }]);