@kitware/vtk.js 20.1.4 → 20.2.3

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 (314) hide show
  1. package/Common/Core/Base64.d.ts +14 -2
  2. package/Common/Core/Base64.js +31 -2
  3. package/Common/Core/Math/index.js +1 -1
  4. package/Common/Core/Math.d.ts +168 -158
  5. package/Common/Core/Math.js +1 -1
  6. package/Common/Core/MatrixBuilder.js +39 -41
  7. package/Common/DataModel/Box.d.ts +73 -0
  8. package/Common/DataModel/ImageData.js +12 -14
  9. package/Common/Transform/LandmarkTransform.js +6 -7
  10. package/Filters/General/PaintFilter/PaintFilter.worker.js +8 -8
  11. package/Filters/General/PaintFilter.js +11 -11
  12. package/Filters/Sources/CubeSource.d.ts +7 -6
  13. package/Filters/Sources/PlaneSource.js +12 -13
  14. package/IO/Core/BinaryHelper.js +2 -4
  15. package/IO/Core/DataAccessHelper/HtmlDataAccessHelper.js +1 -1
  16. package/IO/Core/DataAccessHelper/HttpDataAccessHelper.js +1 -1
  17. package/IO/Core/DataAccessHelper/JSZipDataAccessHelper.js +2 -2
  18. package/IO/Core/ZipMultiDataSetReader.js +1 -1
  19. package/IO/Core/ZipMultiDataSetWriter.js +1 -1
  20. package/IO/Geometry/STLWriter.js +4 -4
  21. package/IO/Misc/OBJReader.d.ts +9 -8
  22. package/IO/Misc/SkyboxReader.js +1 -1
  23. package/IO/XML/XMLReader.js +3 -4
  24. package/IO/XML/XMLWriter.js +5 -6
  25. package/Imaging/Core/ImageReslice.js +18 -19
  26. package/Interaction/Manipulators/MouseCameraAxisRotateManipulator.js +27 -28
  27. package/Interaction/Manipulators/MouseCameraTrackballRollManipulator.js +8 -9
  28. package/Interaction/Manipulators/MouseCameraTrackballRotateManipulator.js +14 -15
  29. package/Interaction/Manipulators/MouseCameraUnicamRotateManipulator.js +12 -13
  30. package/Interaction/Widgets/ImageCroppingRegionsWidget.js +5 -6
  31. package/Interaction/Widgets/PiecewiseGaussianWidget/ComputeHistogram.worker.js +1 -1
  32. package/Interaction/Widgets/PiecewiseGaussianWidget.js +2 -2
  33. package/Interaction/Widgets/ResliceCursor/ResliceCursorRepresentation.js +8 -9
  34. package/Rendering/Core/Actor.js +3 -4
  35. package/Rendering/Core/AnnotatedCubeActor.d.ts +5 -6
  36. package/Rendering/Core/Camera.js +81 -84
  37. package/Rendering/Core/CellPicker.js +2 -2
  38. package/Rendering/Core/CubeAxesActor.js +37 -34
  39. package/Rendering/Core/Follower.js +20 -21
  40. package/Rendering/Core/Glyph3DMapper.js +30 -32
  41. package/Rendering/Core/ImageMapper.js +2 -2
  42. package/Rendering/Core/ImageSlice.js +5 -6
  43. package/Rendering/Core/Picker.d.ts +5 -5
  44. package/Rendering/Core/Picker.js +5 -6
  45. package/Rendering/Core/PixelSpaceCallbackMapper.js +3 -4
  46. package/Rendering/Core/Prop3D.js +24 -25
  47. package/Rendering/Core/Renderer.js +11 -12
  48. package/Rendering/Core/ScalarBarActor.js +37 -34
  49. package/Rendering/Core/Volume.js +3 -4
  50. package/Rendering/OpenGL/Actor.js +9 -10
  51. package/Rendering/OpenGL/Camera.js +8 -9
  52. package/Rendering/OpenGL/CellArrayBufferObject.js +6 -8
  53. package/Rendering/OpenGL/Glyph3DMapper.js +8 -9
  54. package/Rendering/OpenGL/ImageMapper.js +7 -7
  55. package/Rendering/OpenGL/ImageSlice.js +4 -4
  56. package/Rendering/OpenGL/PolyDataMapper.js +11 -13
  57. package/Rendering/OpenGL/RenderWindow.d.ts +21 -35
  58. package/Rendering/OpenGL/ShaderCache.js +1 -1
  59. package/Rendering/OpenGL/Skybox.js +4 -5
  60. package/Rendering/OpenGL/SphereMapper.js +2 -2
  61. package/Rendering/OpenGL/StickMapper.js +3 -4
  62. package/Rendering/OpenGL/SurfaceLIC/SurfaceLICInterface.js +1 -1
  63. package/Rendering/OpenGL/Volume.js +6 -7
  64. package/Rendering/OpenGL/VolumeMapper.js +47 -49
  65. package/Rendering/OpenGL/glsl/vtkPolyDataFS.glsl.js +1 -1
  66. package/Rendering/WebGPU/Actor.js +8 -8
  67. package/Rendering/WebGPU/Camera.js +8 -8
  68. package/Rendering/WebGPU/ImageMapper.js +18 -19
  69. package/Rendering/WebGPU/ImageSlice.js +9 -9
  70. package/Rendering/WebGPU/PolyDataMapper.js +3 -4
  71. package/Rendering/WebGPU/Renderer.js +6 -7
  72. package/Rendering/WebGPU/Volume.js +3 -3
  73. package/Rendering/WebGPU/VolumePassFSQ.js +10 -10
  74. package/ThirdParty/index.js +2 -2
  75. package/Widgets/Manipulators/TrackballManipulator.js +5 -6
  76. package/Widgets/Representations/ArrowHandleRepresentation.js +10 -12
  77. package/Widgets/Representations/CircleContextRepresentation.js +4 -5
  78. package/Widgets/Representations/RectangleContextRepresentation.js +3 -3
  79. package/Widgets/Widgets3D/EllipseWidget/behavior.js +5 -5
  80. package/Widgets/Widgets3D/ImageCroppingWidget/helpers.js +6 -8
  81. package/Widgets/Widgets3D/PaintWidget/behavior.js +2 -2
  82. package/Widgets/Widgets3D/ResliceCursorWidget.js +6 -7
  83. package/Widgets/Widgets3D/ShapeWidget/behavior.js +10 -10
  84. package/Widgets/Widgets3D/SplineWidget/behavior.js +5 -5
  85. package/_virtual/rollup-plugin-worker-loader__module_Sources/Filters/General/PaintFilter/PaintFilter.worker.js +1 -1
  86. package/_virtual/rollup-plugin-worker-loader__module_Sources/Interaction/Widgets/PiecewiseGaussianWidget/ComputeHistogram.worker.js +1 -1
  87. package/package.json +2 -2
  88. package/types.d.ts +1 -0
  89. package/vtk.js +2 -2
  90. package/_vendor/base64-js/index.js_commonjs-exports.js +0 -1
  91. package/_vendor/blueimp-md5/js/md5.js_commonjs-module.js +0 -3
  92. package/_vendor/define-properties/index.js_commonjs-proxy.js +0 -1
  93. package/_vendor/globalthis/implementation.browser.js_commonjs-module.js +0 -3
  94. package/_vendor/globalthis/implementation.browser.js_commonjs-proxy.js +0 -1
  95. package/_vendor/globalthis/polyfill.js_commonjs-proxy.js +0 -1
  96. package/_vendor/globalthis/shim.js_commonjs-proxy.js +0 -2
  97. package/_vendor/jszip/dist/jszip.min.js_commonjs-module.js +0 -3
  98. package/_vendor/object-keys/implementation.js_commonjs-proxy.js +0 -1
  99. package/_vendor/object-keys/index.js_commonjs-proxy.js +0 -1
  100. package/_vendor/object-keys/isArguments.js_commonjs-proxy.js +0 -1
  101. package/_vendor/seedrandom/lib/alea.js_commonjs-module.js +0 -3
  102. package/_vendor/seedrandom/lib/alea.js_commonjs-proxy.js +0 -1
  103. package/_vendor/seedrandom/lib/tychei.js_commonjs-module.js +0 -3
  104. package/_vendor/seedrandom/lib/tychei.js_commonjs-proxy.js +0 -1
  105. package/_vendor/seedrandom/lib/xor128.js_commonjs-module.js +0 -3
  106. package/_vendor/seedrandom/lib/xor128.js_commonjs-proxy.js +0 -1
  107. package/_vendor/seedrandom/lib/xor4096.js_commonjs-module.js +0 -3
  108. package/_vendor/seedrandom/lib/xor4096.js_commonjs-proxy.js +0 -1
  109. package/_vendor/seedrandom/lib/xorshift7.js_commonjs-module.js +0 -3
  110. package/_vendor/seedrandom/lib/xorshift7.js_commonjs-proxy.js +0 -1
  111. package/_vendor/seedrandom/lib/xorwow.js_commonjs-module.js +0 -3
  112. package/_vendor/seedrandom/lib/xorwow.js_commonjs-proxy.js +0 -1
  113. package/_vendor/seedrandom/seedrandom.js_commonjs-module.js +0 -3
  114. package/_vendor/seedrandom/seedrandom.js_commonjs-proxy.js +0 -1
  115. package/_vendor/webworker-promise/lib/register.js_commonjs-module.js +0 -3
  116. package/_vendor/webworker-promise/lib/tiny-emitter.js_commonjs-proxy.js +0 -1
  117. package/_vendor/webworker-promise/src/tiny-emitter.js_commonjs-proxy.js +0 -1
  118. package/_vendor/xmlbuilder2/lib/xmlbuilder2.min.js_commonjs-module.js +0 -3
  119. package/_virtual/_rollup_plugin_ignore_empty_module_placeholder_commonjs-proxy.js +0 -6
  120. package/_virtual/commonjsHelpers.js +0 -22
  121. package/_virtual/polyfill-node.buffer.js +0 -1971
  122. package/_virtual/polyfill-node.global.js +0 -5
  123. package/_virtual/rollup_plugin_ignore_empty_module_placeholder.js +0 -8
  124. package/vendor/base64-js/index.js +0 -72
  125. package/vendor/blueimp-md5/js/md5.js +0 -402
  126. package/vendor/d3-array/src/array.js +0 -1
  127. package/vendor/d3-array/src/ascending.js +0 -5
  128. package/vendor/d3-array/src/bin.js +0 -1
  129. package/vendor/d3-array/src/bisect.js +0 -10
  130. package/vendor/d3-array/src/bisector.js +0 -46
  131. package/vendor/d3-array/src/constant.js +0 -1
  132. package/vendor/d3-array/src/count.js +0 -1
  133. package/vendor/d3-array/src/cross.js +0 -1
  134. package/vendor/d3-array/src/cumsum.js +0 -1
  135. package/vendor/d3-array/src/descending.js +0 -1
  136. package/vendor/d3-array/src/deviation.js +0 -1
  137. package/vendor/d3-array/src/difference.js +0 -1
  138. package/vendor/d3-array/src/disjoint.js +0 -1
  139. package/vendor/d3-array/src/every.js +0 -1
  140. package/vendor/d3-array/src/extent.js +0 -1
  141. package/vendor/d3-array/src/filter.js +0 -1
  142. package/vendor/d3-array/src/fsum.js +0 -1
  143. package/vendor/d3-array/src/greatest.js +0 -1
  144. package/vendor/d3-array/src/greatestIndex.js +0 -1
  145. package/vendor/d3-array/src/group.js +0 -1
  146. package/vendor/d3-array/src/groupSort.js +0 -1
  147. package/vendor/d3-array/src/identity.js +0 -1
  148. package/vendor/d3-array/src/index.js +0 -1
  149. package/vendor/d3-array/src/intersection.js +0 -1
  150. package/vendor/d3-array/src/least.js +0 -1
  151. package/vendor/d3-array/src/leastIndex.js +0 -1
  152. package/vendor/d3-array/src/map.js +0 -1
  153. package/vendor/d3-array/src/max.js +0 -1
  154. package/vendor/d3-array/src/maxIndex.js +0 -1
  155. package/vendor/d3-array/src/mean.js +0 -1
  156. package/vendor/d3-array/src/median.js +0 -1
  157. package/vendor/d3-array/src/merge.js +0 -1
  158. package/vendor/d3-array/src/min.js +0 -1
  159. package/vendor/d3-array/src/minIndex.js +0 -1
  160. package/vendor/d3-array/src/mode.js +0 -1
  161. package/vendor/d3-array/src/nice.js +0 -1
  162. package/vendor/d3-array/src/number.js +0 -5
  163. package/vendor/d3-array/src/pairs.js +0 -1
  164. package/vendor/d3-array/src/permute.js +0 -1
  165. package/vendor/d3-array/src/quantile.js +0 -1
  166. package/vendor/d3-array/src/quickselect.js +0 -1
  167. package/vendor/d3-array/src/range.js +0 -1
  168. package/vendor/d3-array/src/reduce.js +0 -1
  169. package/vendor/d3-array/src/reverse.js +0 -1
  170. package/vendor/d3-array/src/scan.js +0 -1
  171. package/vendor/d3-array/src/set.js +0 -1
  172. package/vendor/d3-array/src/shuffle.js +0 -1
  173. package/vendor/d3-array/src/some.js +0 -1
  174. package/vendor/d3-array/src/sort.js +0 -1
  175. package/vendor/d3-array/src/subset.js +0 -1
  176. package/vendor/d3-array/src/sum.js +0 -1
  177. package/vendor/d3-array/src/superset.js +0 -1
  178. package/vendor/d3-array/src/threshold/freedmanDiaconis.js +0 -1
  179. package/vendor/d3-array/src/threshold/scott.js +0 -1
  180. package/vendor/d3-array/src/threshold/sturges.js +0 -1
  181. package/vendor/d3-array/src/ticks.js +0 -56
  182. package/vendor/d3-array/src/transpose.js +0 -1
  183. package/vendor/d3-array/src/union.js +0 -1
  184. package/vendor/d3-array/src/variance.js +0 -1
  185. package/vendor/d3-array/src/zip.js +0 -1
  186. package/vendor/d3-color/src/color.js +0 -373
  187. package/vendor/d3-color/src/cubehelix.js +0 -1
  188. package/vendor/d3-color/src/define.js +0 -12
  189. package/vendor/d3-color/src/index.js +0 -1
  190. package/vendor/d3-color/src/lab.js +0 -1
  191. package/vendor/d3-color/src/math.js +0 -1
  192. package/vendor/d3-format/src/defaultLocale.js +0 -20
  193. package/vendor/d3-format/src/exponent.js +0 -7
  194. package/vendor/d3-format/src/formatDecimal.js +0 -22
  195. package/vendor/d3-format/src/formatGroup.js +0 -20
  196. package/vendor/d3-format/src/formatNumerals.js +0 -9
  197. package/vendor/d3-format/src/formatPrefixAuto.js +0 -18
  198. package/vendor/d3-format/src/formatRounded.js +0 -13
  199. package/vendor/d3-format/src/formatSpecifier.js +0 -49
  200. package/vendor/d3-format/src/formatTrim.js +0 -13
  201. package/vendor/d3-format/src/formatTypes.js +0 -21
  202. package/vendor/d3-format/src/identity.js +0 -5
  203. package/vendor/d3-format/src/index.js +0 -1
  204. package/vendor/d3-format/src/locale.js +0 -150
  205. package/vendor/d3-format/src/precisionFixed.js +0 -7
  206. package/vendor/d3-format/src/precisionPrefix.js +0 -7
  207. package/vendor/d3-format/src/precisionRound.js +0 -8
  208. package/vendor/d3-interpolate/src/array.js +0 -19
  209. package/vendor/d3-interpolate/src/basis.js +0 -1
  210. package/vendor/d3-interpolate/src/basisClosed.js +0 -1
  211. package/vendor/d3-interpolate/src/color.js +0 -26
  212. package/vendor/d3-interpolate/src/constant.js +0 -3
  213. package/vendor/d3-interpolate/src/cubehelix.js +0 -1
  214. package/vendor/d3-interpolate/src/date.js +0 -8
  215. package/vendor/d3-interpolate/src/discrete.js +0 -1
  216. package/vendor/d3-interpolate/src/hcl.js +0 -1
  217. package/vendor/d3-interpolate/src/hsl.js +0 -1
  218. package/vendor/d3-interpolate/src/hue.js +0 -1
  219. package/vendor/d3-interpolate/src/index.js +0 -1
  220. package/vendor/d3-interpolate/src/lab.js +0 -1
  221. package/vendor/d3-interpolate/src/number.js +0 -7
  222. package/vendor/d3-interpolate/src/numberArray.js +0 -16
  223. package/vendor/d3-interpolate/src/object.js +0 -25
  224. package/vendor/d3-interpolate/src/piecewise.js +0 -1
  225. package/vendor/d3-interpolate/src/quantize.js +0 -1
  226. package/vendor/d3-interpolate/src/rgb.js +0 -26
  227. package/vendor/d3-interpolate/src/round.js +0 -7
  228. package/vendor/d3-interpolate/src/string.js +0 -66
  229. package/vendor/d3-interpolate/src/transform/decompose.js +0 -1
  230. package/vendor/d3-interpolate/src/transform/index.js +0 -1
  231. package/vendor/d3-interpolate/src/transform/parse.js +0 -1
  232. package/vendor/d3-interpolate/src/value.js +0 -24
  233. package/vendor/d3-interpolate/src/zoom.js +0 -1
  234. package/vendor/d3-scale/src/band.js +0 -1
  235. package/vendor/d3-scale/src/constant.js +0 -7
  236. package/vendor/d3-scale/src/continuous.js +0 -129
  237. package/vendor/d3-scale/src/diverging.js +0 -1
  238. package/vendor/d3-scale/src/identity.js +0 -1
  239. package/vendor/d3-scale/src/index.js +0 -1
  240. package/vendor/d3-scale/src/init.js +0 -10
  241. package/vendor/d3-scale/src/linear.js +0 -72
  242. package/vendor/d3-scale/src/log.js +0 -1
  243. package/vendor/d3-scale/src/nice.js +0 -1
  244. package/vendor/d3-scale/src/number.js +0 -5
  245. package/vendor/d3-scale/src/ordinal.js +0 -1
  246. package/vendor/d3-scale/src/pow.js +0 -1
  247. package/vendor/d3-scale/src/quantile.js +0 -1
  248. package/vendor/d3-scale/src/quantize.js +0 -1
  249. package/vendor/d3-scale/src/radial.js +0 -1
  250. package/vendor/d3-scale/src/sequential.js +0 -1
  251. package/vendor/d3-scale/src/sequentialQuantile.js +0 -1
  252. package/vendor/d3-scale/src/symlog.js +0 -1
  253. package/vendor/d3-scale/src/threshold.js +0 -1
  254. package/vendor/d3-scale/src/tickFormat.js +0 -35
  255. package/vendor/d3-scale/src/time.js +0 -1
  256. package/vendor/d3-scale/src/utcTime.js +0 -1
  257. package/vendor/d3-time/src/day.js +0 -1
  258. package/vendor/d3-time/src/duration.js +0 -1
  259. package/vendor/d3-time/src/hour.js +0 -1
  260. package/vendor/d3-time/src/index.js +0 -1
  261. package/vendor/d3-time/src/interval.js +0 -1
  262. package/vendor/d3-time/src/millisecond.js +0 -1
  263. package/vendor/d3-time/src/minute.js +0 -1
  264. package/vendor/d3-time/src/month.js +0 -1
  265. package/vendor/d3-time/src/second.js +0 -1
  266. package/vendor/d3-time/src/ticks.js +0 -1
  267. package/vendor/d3-time/src/utcDay.js +0 -1
  268. package/vendor/d3-time/src/utcHour.js +0 -1
  269. package/vendor/d3-time/src/utcMinute.js +0 -1
  270. package/vendor/d3-time/src/utcMonth.js +0 -1
  271. package/vendor/d3-time/src/utcWeek.js +0 -1
  272. package/vendor/d3-time/src/utcYear.js +0 -1
  273. package/vendor/d3-time/src/week.js +0 -1
  274. package/vendor/d3-time/src/year.js +0 -1
  275. package/vendor/d3-time-format/src/defaultLocale.js +0 -1
  276. package/vendor/d3-time-format/src/index.js +0 -1
  277. package/vendor/d3-time-format/src/isoFormat.js +0 -1
  278. package/vendor/d3-time-format/src/isoParse.js +0 -1
  279. package/vendor/d3-time-format/src/locale.js +0 -1
  280. package/vendor/define-properties/index.js +0 -60
  281. package/vendor/gl-matrix/esm/common.js +0 -30
  282. package/vendor/gl-matrix/esm/index.js +0 -1
  283. package/vendor/gl-matrix/esm/mat2.js +0 -1
  284. package/vendor/gl-matrix/esm/mat2d.js +0 -1
  285. package/vendor/gl-matrix/esm/mat3.js +0 -817
  286. package/vendor/gl-matrix/esm/mat4.js +0 -1868
  287. package/vendor/gl-matrix/esm/quat.js +0 -330
  288. package/vendor/gl-matrix/esm/quat2.js +0 -1
  289. package/vendor/gl-matrix/esm/vec2.js +0 -1
  290. package/vendor/gl-matrix/esm/vec3.js +0 -842
  291. package/vendor/gl-matrix/esm/vec4.js +0 -153
  292. package/vendor/globalthis/implementation.browser.js +0 -11
  293. package/vendor/globalthis/index.js +0 -25
  294. package/vendor/globalthis/polyfill.js +0 -14
  295. package/vendor/globalthis/shim.js +0 -25
  296. package/vendor/internmap/src/index.js +0 -1
  297. package/vendor/jszip/dist/jszip.min.js +0 -11
  298. package/vendor/object-keys/implementation.js +0 -124
  299. package/vendor/object-keys/index.js +0 -35
  300. package/vendor/object-keys/isArguments.js +0 -17
  301. package/vendor/pako/dist/pako.esm.mjs.js +0 -6707
  302. package/vendor/seedrandom/index.js +0 -77
  303. package/vendor/seedrandom/lib/alea.js +0 -117
  304. package/vendor/seedrandom/lib/tychei.js +0 -105
  305. package/vendor/seedrandom/lib/xor128.js +0 -84
  306. package/vendor/seedrandom/lib/xor4096.js +0 -150
  307. package/vendor/seedrandom/lib/xorshift7.js +0 -101
  308. package/vendor/seedrandom/lib/xorwow.js +0 -89
  309. package/vendor/seedrandom/seedrandom.js +0 -256
  310. package/vendor/webworker-promise/lib/register.js +0 -158
  311. package/vendor/webworker-promise/lib/tiny-emitter.js +0 -89
  312. package/vendor/webworker-promise/src/index.js +0 -110
  313. package/vendor/webworker-promise/src/tiny-emitter.js +0 -51
  314. package/vendor/xmlbuilder2/lib/xmlbuilder2.min.js +0 -13
@@ -1,1971 +0,0 @@
1
- import { g as global } from './polyfill-node.global.js';
2
-
3
- var lookup = [];
4
- var revLookup = [];
5
- var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
6
- var inited = false;
7
- function init () {
8
- inited = true;
9
- var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
10
- for (var i = 0, len = code.length; i < len; ++i) {
11
- lookup[i] = code[i];
12
- revLookup[code.charCodeAt(i)] = i;
13
- }
14
-
15
- revLookup['-'.charCodeAt(0)] = 62;
16
- revLookup['_'.charCodeAt(0)] = 63;
17
- }
18
-
19
- function toByteArray (b64) {
20
- if (!inited) {
21
- init();
22
- }
23
- var i, j, l, tmp, placeHolders, arr;
24
- var len = b64.length;
25
-
26
- if (len % 4 > 0) {
27
- throw new Error('Invalid string. Length must be a multiple of 4')
28
- }
29
-
30
- // the number of equal signs (place holders)
31
- // if there are two placeholders, than the two characters before it
32
- // represent one byte
33
- // if there is only one, then the three characters before it represent 2 bytes
34
- // this is just a cheap hack to not do indexOf twice
35
- placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0;
36
-
37
- // base64 is 4/3 + up to two characters of the original data
38
- arr = new Arr(len * 3 / 4 - placeHolders);
39
-
40
- // if there are placeholders, only get up to the last complete 4 chars
41
- l = placeHolders > 0 ? len - 4 : len;
42
-
43
- var L = 0;
44
-
45
- for (i = 0, j = 0; i < l; i += 4, j += 3) {
46
- tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)];
47
- arr[L++] = (tmp >> 16) & 0xFF;
48
- arr[L++] = (tmp >> 8) & 0xFF;
49
- arr[L++] = tmp & 0xFF;
50
- }
51
-
52
- if (placeHolders === 2) {
53
- tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);
54
- arr[L++] = tmp & 0xFF;
55
- } else if (placeHolders === 1) {
56
- tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2);
57
- arr[L++] = (tmp >> 8) & 0xFF;
58
- arr[L++] = tmp & 0xFF;
59
- }
60
-
61
- return arr
62
- }
63
-
64
- function tripletToBase64 (num) {
65
- return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
66
- }
67
-
68
- function encodeChunk (uint8, start, end) {
69
- var tmp;
70
- var output = [];
71
- for (var i = start; i < end; i += 3) {
72
- tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
73
- output.push(tripletToBase64(tmp));
74
- }
75
- return output.join('')
76
- }
77
-
78
- function fromByteArray (uint8) {
79
- if (!inited) {
80
- init();
81
- }
82
- var tmp;
83
- var len = uint8.length;
84
- var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
85
- var output = '';
86
- var parts = [];
87
- var maxChunkLength = 16383; // must be multiple of 3
88
-
89
- // go through the array every three bytes, we'll deal with trailing stuff later
90
- for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
91
- parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
92
- }
93
-
94
- // pad the end with zeros, but make sure to not forget the extra bytes
95
- if (extraBytes === 1) {
96
- tmp = uint8[len - 1];
97
- output += lookup[tmp >> 2];
98
- output += lookup[(tmp << 4) & 0x3F];
99
- output += '==';
100
- } else if (extraBytes === 2) {
101
- tmp = (uint8[len - 2] << 8) + (uint8[len - 1]);
102
- output += lookup[tmp >> 10];
103
- output += lookup[(tmp >> 4) & 0x3F];
104
- output += lookup[(tmp << 2) & 0x3F];
105
- output += '=';
106
- }
107
-
108
- parts.push(output);
109
-
110
- return parts.join('')
111
- }
112
-
113
- function read (buffer, offset, isLE, mLen, nBytes) {
114
- var e, m;
115
- var eLen = nBytes * 8 - mLen - 1;
116
- var eMax = (1 << eLen) - 1;
117
- var eBias = eMax >> 1;
118
- var nBits = -7;
119
- var i = isLE ? (nBytes - 1) : 0;
120
- var d = isLE ? -1 : 1;
121
- var s = buffer[offset + i];
122
-
123
- i += d;
124
-
125
- e = s & ((1 << (-nBits)) - 1);
126
- s >>= (-nBits);
127
- nBits += eLen;
128
- for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
129
-
130
- m = e & ((1 << (-nBits)) - 1);
131
- e >>= (-nBits);
132
- nBits += mLen;
133
- for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
134
-
135
- if (e === 0) {
136
- e = 1 - eBias;
137
- } else if (e === eMax) {
138
- return m ? NaN : ((s ? -1 : 1) * Infinity)
139
- } else {
140
- m = m + Math.pow(2, mLen);
141
- e = e - eBias;
142
- }
143
- return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
144
- }
145
-
146
- function write (buffer, value, offset, isLE, mLen, nBytes) {
147
- var e, m, c;
148
- var eLen = nBytes * 8 - mLen - 1;
149
- var eMax = (1 << eLen) - 1;
150
- var eBias = eMax >> 1;
151
- var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
152
- var i = isLE ? 0 : (nBytes - 1);
153
- var d = isLE ? 1 : -1;
154
- var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
155
-
156
- value = Math.abs(value);
157
-
158
- if (isNaN(value) || value === Infinity) {
159
- m = isNaN(value) ? 1 : 0;
160
- e = eMax;
161
- } else {
162
- e = Math.floor(Math.log(value) / Math.LN2);
163
- if (value * (c = Math.pow(2, -e)) < 1) {
164
- e--;
165
- c *= 2;
166
- }
167
- if (e + eBias >= 1) {
168
- value += rt / c;
169
- } else {
170
- value += rt * Math.pow(2, 1 - eBias);
171
- }
172
- if (value * c >= 2) {
173
- e++;
174
- c /= 2;
175
- }
176
-
177
- if (e + eBias >= eMax) {
178
- m = 0;
179
- e = eMax;
180
- } else if (e + eBias >= 1) {
181
- m = (value * c - 1) * Math.pow(2, mLen);
182
- e = e + eBias;
183
- } else {
184
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
185
- e = 0;
186
- }
187
- }
188
-
189
- for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
190
-
191
- e = (e << mLen) | m;
192
- eLen += mLen;
193
- for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
194
-
195
- buffer[offset + i - d] |= s * 128;
196
- }
197
-
198
- var toString = {}.toString;
199
-
200
- var isArray = Array.isArray || function (arr) {
201
- return toString.call(arr) == '[object Array]';
202
- };
203
-
204
- /*!
205
- * The buffer module from node.js, for the browser.
206
- *
207
- * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
208
- * @license MIT
209
- */
210
-
211
- var INSPECT_MAX_BYTES = 50;
212
-
213
- /**
214
- * If `Buffer.TYPED_ARRAY_SUPPORT`:
215
- * === true Use Uint8Array implementation (fastest)
216
- * === false Use Object implementation (most compatible, even IE6)
217
- *
218
- * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
219
- * Opera 11.6+, iOS 4.2+.
220
- *
221
- * Due to various browser bugs, sometimes the Object implementation will be used even
222
- * when the browser supports typed arrays.
223
- *
224
- * Note:
225
- *
226
- * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
227
- * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
228
- *
229
- * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
230
- *
231
- * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
232
- * incorrect length in some situations.
233
-
234
- * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
235
- * get the Object implementation, which is slower but behaves correctly.
236
- */
237
- Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
238
- ? global.TYPED_ARRAY_SUPPORT
239
- : true;
240
-
241
- function kMaxLength () {
242
- return Buffer.TYPED_ARRAY_SUPPORT
243
- ? 0x7fffffff
244
- : 0x3fffffff
245
- }
246
-
247
- function createBuffer (that, length) {
248
- if (kMaxLength() < length) {
249
- throw new RangeError('Invalid typed array length')
250
- }
251
- if (Buffer.TYPED_ARRAY_SUPPORT) {
252
- // Return an augmented `Uint8Array` instance, for best performance
253
- that = new Uint8Array(length);
254
- that.__proto__ = Buffer.prototype;
255
- } else {
256
- // Fallback: Return an object instance of the Buffer class
257
- if (that === null) {
258
- that = new Buffer(length);
259
- }
260
- that.length = length;
261
- }
262
-
263
- return that
264
- }
265
-
266
- /**
267
- * The Buffer constructor returns instances of `Uint8Array` that have their
268
- * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
269
- * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
270
- * and the `Uint8Array` methods. Square bracket notation works as expected -- it
271
- * returns a single octet.
272
- *
273
- * The `Uint8Array` prototype remains unmodified.
274
- */
275
-
276
- function Buffer (arg, encodingOrOffset, length) {
277
- if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
278
- return new Buffer(arg, encodingOrOffset, length)
279
- }
280
-
281
- // Common case.
282
- if (typeof arg === 'number') {
283
- if (typeof encodingOrOffset === 'string') {
284
- throw new Error(
285
- 'If encoding is specified then the first argument must be a string'
286
- )
287
- }
288
- return allocUnsafe(this, arg)
289
- }
290
- return from(this, arg, encodingOrOffset, length)
291
- }
292
-
293
- Buffer.poolSize = 8192; // not used by this implementation
294
-
295
- // TODO: Legacy, not needed anymore. Remove in next major version.
296
- Buffer._augment = function (arr) {
297
- arr.__proto__ = Buffer.prototype;
298
- return arr
299
- };
300
-
301
- function from (that, value, encodingOrOffset, length) {
302
- if (typeof value === 'number') {
303
- throw new TypeError('"value" argument must not be a number')
304
- }
305
-
306
- if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
307
- return fromArrayBuffer(that, value, encodingOrOffset, length)
308
- }
309
-
310
- if (typeof value === 'string') {
311
- return fromString(that, value, encodingOrOffset)
312
- }
313
-
314
- return fromObject(that, value)
315
- }
316
-
317
- /**
318
- * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
319
- * if value is a number.
320
- * Buffer.from(str[, encoding])
321
- * Buffer.from(array)
322
- * Buffer.from(buffer)
323
- * Buffer.from(arrayBuffer[, byteOffset[, length]])
324
- **/
325
- Buffer.from = function (value, encodingOrOffset, length) {
326
- return from(null, value, encodingOrOffset, length)
327
- };
328
-
329
- if (Buffer.TYPED_ARRAY_SUPPORT) {
330
- Buffer.prototype.__proto__ = Uint8Array.prototype;
331
- Buffer.__proto__ = Uint8Array;
332
- }
333
-
334
- function assertSize (size) {
335
- if (typeof size !== 'number') {
336
- throw new TypeError('"size" argument must be a number')
337
- } else if (size < 0) {
338
- throw new RangeError('"size" argument must not be negative')
339
- }
340
- }
341
-
342
- function alloc (that, size, fill, encoding) {
343
- assertSize(size);
344
- if (size <= 0) {
345
- return createBuffer(that, size)
346
- }
347
- if (fill !== undefined) {
348
- // Only pay attention to encoding if it's a string. This
349
- // prevents accidentally sending in a number that would
350
- // be interpretted as a start offset.
351
- return typeof encoding === 'string'
352
- ? createBuffer(that, size).fill(fill, encoding)
353
- : createBuffer(that, size).fill(fill)
354
- }
355
- return createBuffer(that, size)
356
- }
357
-
358
- /**
359
- * Creates a new filled Buffer instance.
360
- * alloc(size[, fill[, encoding]])
361
- **/
362
- Buffer.alloc = function (size, fill, encoding) {
363
- return alloc(null, size, fill, encoding)
364
- };
365
-
366
- function allocUnsafe (that, size) {
367
- assertSize(size);
368
- that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
369
- if (!Buffer.TYPED_ARRAY_SUPPORT) {
370
- for (var i = 0; i < size; ++i) {
371
- that[i] = 0;
372
- }
373
- }
374
- return that
375
- }
376
-
377
- /**
378
- * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
379
- * */
380
- Buffer.allocUnsafe = function (size) {
381
- return allocUnsafe(null, size)
382
- };
383
- /**
384
- * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
385
- */
386
- Buffer.allocUnsafeSlow = function (size) {
387
- return allocUnsafe(null, size)
388
- };
389
-
390
- function fromString (that, string, encoding) {
391
- if (typeof encoding !== 'string' || encoding === '') {
392
- encoding = 'utf8';
393
- }
394
-
395
- if (!Buffer.isEncoding(encoding)) {
396
- throw new TypeError('"encoding" must be a valid string encoding')
397
- }
398
-
399
- var length = byteLength(string, encoding) | 0;
400
- that = createBuffer(that, length);
401
-
402
- var actual = that.write(string, encoding);
403
-
404
- if (actual !== length) {
405
- // Writing a hex string, for example, that contains invalid characters will
406
- // cause everything after the first invalid character to be ignored. (e.g.
407
- // 'abxxcd' will be treated as 'ab')
408
- that = that.slice(0, actual);
409
- }
410
-
411
- return that
412
- }
413
-
414
- function fromArrayLike (that, array) {
415
- var length = array.length < 0 ? 0 : checked(array.length) | 0;
416
- that = createBuffer(that, length);
417
- for (var i = 0; i < length; i += 1) {
418
- that[i] = array[i] & 255;
419
- }
420
- return that
421
- }
422
-
423
- function fromArrayBuffer (that, array, byteOffset, length) {
424
- array.byteLength; // this throws if `array` is not a valid ArrayBuffer
425
-
426
- if (byteOffset < 0 || array.byteLength < byteOffset) {
427
- throw new RangeError('\'offset\' is out of bounds')
428
- }
429
-
430
- if (array.byteLength < byteOffset + (length || 0)) {
431
- throw new RangeError('\'length\' is out of bounds')
432
- }
433
-
434
- if (byteOffset === undefined && length === undefined) {
435
- array = new Uint8Array(array);
436
- } else if (length === undefined) {
437
- array = new Uint8Array(array, byteOffset);
438
- } else {
439
- array = new Uint8Array(array, byteOffset, length);
440
- }
441
-
442
- if (Buffer.TYPED_ARRAY_SUPPORT) {
443
- // Return an augmented `Uint8Array` instance, for best performance
444
- that = array;
445
- that.__proto__ = Buffer.prototype;
446
- } else {
447
- // Fallback: Return an object instance of the Buffer class
448
- that = fromArrayLike(that, array);
449
- }
450
- return that
451
- }
452
-
453
- function fromObject (that, obj) {
454
- if (internalIsBuffer(obj)) {
455
- var len = checked(obj.length) | 0;
456
- that = createBuffer(that, len);
457
-
458
- if (that.length === 0) {
459
- return that
460
- }
461
-
462
- obj.copy(that, 0, 0, len);
463
- return that
464
- }
465
-
466
- if (obj) {
467
- if ((typeof ArrayBuffer !== 'undefined' &&
468
- obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
469
- if (typeof obj.length !== 'number' || isnan(obj.length)) {
470
- return createBuffer(that, 0)
471
- }
472
- return fromArrayLike(that, obj)
473
- }
474
-
475
- if (obj.type === 'Buffer' && isArray(obj.data)) {
476
- return fromArrayLike(that, obj.data)
477
- }
478
- }
479
-
480
- throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
481
- }
482
-
483
- function checked (length) {
484
- // Note: cannot use `length < kMaxLength()` here because that fails when
485
- // length is NaN (which is otherwise coerced to zero.)
486
- if (length >= kMaxLength()) {
487
- throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
488
- 'size: 0x' + kMaxLength().toString(16) + ' bytes')
489
- }
490
- return length | 0
491
- }
492
- Buffer.isBuffer = isBuffer;
493
- function internalIsBuffer (b) {
494
- return !!(b != null && b._isBuffer)
495
- }
496
-
497
- Buffer.compare = function compare (a, b) {
498
- if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
499
- throw new TypeError('Arguments must be Buffers')
500
- }
501
-
502
- if (a === b) return 0
503
-
504
- var x = a.length;
505
- var y = b.length;
506
-
507
- for (var i = 0, len = Math.min(x, y); i < len; ++i) {
508
- if (a[i] !== b[i]) {
509
- x = a[i];
510
- y = b[i];
511
- break
512
- }
513
- }
514
-
515
- if (x < y) return -1
516
- if (y < x) return 1
517
- return 0
518
- };
519
-
520
- Buffer.isEncoding = function isEncoding (encoding) {
521
- switch (String(encoding).toLowerCase()) {
522
- case 'hex':
523
- case 'utf8':
524
- case 'utf-8':
525
- case 'ascii':
526
- case 'latin1':
527
- case 'binary':
528
- case 'base64':
529
- case 'ucs2':
530
- case 'ucs-2':
531
- case 'utf16le':
532
- case 'utf-16le':
533
- return true
534
- default:
535
- return false
536
- }
537
- };
538
-
539
- Buffer.concat = function concat (list, length) {
540
- if (!isArray(list)) {
541
- throw new TypeError('"list" argument must be an Array of Buffers')
542
- }
543
-
544
- if (list.length === 0) {
545
- return Buffer.alloc(0)
546
- }
547
-
548
- var i;
549
- if (length === undefined) {
550
- length = 0;
551
- for (i = 0; i < list.length; ++i) {
552
- length += list[i].length;
553
- }
554
- }
555
-
556
- var buffer = Buffer.allocUnsafe(length);
557
- var pos = 0;
558
- for (i = 0; i < list.length; ++i) {
559
- var buf = list[i];
560
- if (!internalIsBuffer(buf)) {
561
- throw new TypeError('"list" argument must be an Array of Buffers')
562
- }
563
- buf.copy(buffer, pos);
564
- pos += buf.length;
565
- }
566
- return buffer
567
- };
568
-
569
- function byteLength (string, encoding) {
570
- if (internalIsBuffer(string)) {
571
- return string.length
572
- }
573
- if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
574
- (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
575
- return string.byteLength
576
- }
577
- if (typeof string !== 'string') {
578
- string = '' + string;
579
- }
580
-
581
- var len = string.length;
582
- if (len === 0) return 0
583
-
584
- // Use a for loop to avoid recursion
585
- var loweredCase = false;
586
- for (;;) {
587
- switch (encoding) {
588
- case 'ascii':
589
- case 'latin1':
590
- case 'binary':
591
- return len
592
- case 'utf8':
593
- case 'utf-8':
594
- case undefined:
595
- return utf8ToBytes(string).length
596
- case 'ucs2':
597
- case 'ucs-2':
598
- case 'utf16le':
599
- case 'utf-16le':
600
- return len * 2
601
- case 'hex':
602
- return len >>> 1
603
- case 'base64':
604
- return base64ToBytes(string).length
605
- default:
606
- if (loweredCase) return utf8ToBytes(string).length // assume utf8
607
- encoding = ('' + encoding).toLowerCase();
608
- loweredCase = true;
609
- }
610
- }
611
- }
612
- Buffer.byteLength = byteLength;
613
-
614
- function slowToString (encoding, start, end) {
615
- var loweredCase = false;
616
-
617
- // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
618
- // property of a typed array.
619
-
620
- // This behaves neither like String nor Uint8Array in that we set start/end
621
- // to their upper/lower bounds if the value passed is out of range.
622
- // undefined is handled specially as per ECMA-262 6th Edition,
623
- // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
624
- if (start === undefined || start < 0) {
625
- start = 0;
626
- }
627
- // Return early if start > this.length. Done here to prevent potential uint32
628
- // coercion fail below.
629
- if (start > this.length) {
630
- return ''
631
- }
632
-
633
- if (end === undefined || end > this.length) {
634
- end = this.length;
635
- }
636
-
637
- if (end <= 0) {
638
- return ''
639
- }
640
-
641
- // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
642
- end >>>= 0;
643
- start >>>= 0;
644
-
645
- if (end <= start) {
646
- return ''
647
- }
648
-
649
- if (!encoding) encoding = 'utf8';
650
-
651
- while (true) {
652
- switch (encoding) {
653
- case 'hex':
654
- return hexSlice(this, start, end)
655
-
656
- case 'utf8':
657
- case 'utf-8':
658
- return utf8Slice(this, start, end)
659
-
660
- case 'ascii':
661
- return asciiSlice(this, start, end)
662
-
663
- case 'latin1':
664
- case 'binary':
665
- return latin1Slice(this, start, end)
666
-
667
- case 'base64':
668
- return base64Slice(this, start, end)
669
-
670
- case 'ucs2':
671
- case 'ucs-2':
672
- case 'utf16le':
673
- case 'utf-16le':
674
- return utf16leSlice(this, start, end)
675
-
676
- default:
677
- if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
678
- encoding = (encoding + '').toLowerCase();
679
- loweredCase = true;
680
- }
681
- }
682
- }
683
-
684
- // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
685
- // Buffer instances.
686
- Buffer.prototype._isBuffer = true;
687
-
688
- function swap (b, n, m) {
689
- var i = b[n];
690
- b[n] = b[m];
691
- b[m] = i;
692
- }
693
-
694
- Buffer.prototype.swap16 = function swap16 () {
695
- var len = this.length;
696
- if (len % 2 !== 0) {
697
- throw new RangeError('Buffer size must be a multiple of 16-bits')
698
- }
699
- for (var i = 0; i < len; i += 2) {
700
- swap(this, i, i + 1);
701
- }
702
- return this
703
- };
704
-
705
- Buffer.prototype.swap32 = function swap32 () {
706
- var len = this.length;
707
- if (len % 4 !== 0) {
708
- throw new RangeError('Buffer size must be a multiple of 32-bits')
709
- }
710
- for (var i = 0; i < len; i += 4) {
711
- swap(this, i, i + 3);
712
- swap(this, i + 1, i + 2);
713
- }
714
- return this
715
- };
716
-
717
- Buffer.prototype.swap64 = function swap64 () {
718
- var len = this.length;
719
- if (len % 8 !== 0) {
720
- throw new RangeError('Buffer size must be a multiple of 64-bits')
721
- }
722
- for (var i = 0; i < len; i += 8) {
723
- swap(this, i, i + 7);
724
- swap(this, i + 1, i + 6);
725
- swap(this, i + 2, i + 5);
726
- swap(this, i + 3, i + 4);
727
- }
728
- return this
729
- };
730
-
731
- Buffer.prototype.toString = function toString () {
732
- var length = this.length | 0;
733
- if (length === 0) return ''
734
- if (arguments.length === 0) return utf8Slice(this, 0, length)
735
- return slowToString.apply(this, arguments)
736
- };
737
-
738
- Buffer.prototype.equals = function equals (b) {
739
- if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer')
740
- if (this === b) return true
741
- return Buffer.compare(this, b) === 0
742
- };
743
-
744
- Buffer.prototype.inspect = function inspect () {
745
- var str = '';
746
- var max = INSPECT_MAX_BYTES;
747
- if (this.length > 0) {
748
- str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
749
- if (this.length > max) str += ' ... ';
750
- }
751
- return '<Buffer ' + str + '>'
752
- };
753
-
754
- Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
755
- if (!internalIsBuffer(target)) {
756
- throw new TypeError('Argument must be a Buffer')
757
- }
758
-
759
- if (start === undefined) {
760
- start = 0;
761
- }
762
- if (end === undefined) {
763
- end = target ? target.length : 0;
764
- }
765
- if (thisStart === undefined) {
766
- thisStart = 0;
767
- }
768
- if (thisEnd === undefined) {
769
- thisEnd = this.length;
770
- }
771
-
772
- if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
773
- throw new RangeError('out of range index')
774
- }
775
-
776
- if (thisStart >= thisEnd && start >= end) {
777
- return 0
778
- }
779
- if (thisStart >= thisEnd) {
780
- return -1
781
- }
782
- if (start >= end) {
783
- return 1
784
- }
785
-
786
- start >>>= 0;
787
- end >>>= 0;
788
- thisStart >>>= 0;
789
- thisEnd >>>= 0;
790
-
791
- if (this === target) return 0
792
-
793
- var x = thisEnd - thisStart;
794
- var y = end - start;
795
- var len = Math.min(x, y);
796
-
797
- var thisCopy = this.slice(thisStart, thisEnd);
798
- var targetCopy = target.slice(start, end);
799
-
800
- for (var i = 0; i < len; ++i) {
801
- if (thisCopy[i] !== targetCopy[i]) {
802
- x = thisCopy[i];
803
- y = targetCopy[i];
804
- break
805
- }
806
- }
807
-
808
- if (x < y) return -1
809
- if (y < x) return 1
810
- return 0
811
- };
812
-
813
- // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
814
- // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
815
- //
816
- // Arguments:
817
- // - buffer - a Buffer to search
818
- // - val - a string, Buffer, or number
819
- // - byteOffset - an index into `buffer`; will be clamped to an int32
820
- // - encoding - an optional encoding, relevant is val is a string
821
- // - dir - true for indexOf, false for lastIndexOf
822
- function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
823
- // Empty buffer means no match
824
- if (buffer.length === 0) return -1
825
-
826
- // Normalize byteOffset
827
- if (typeof byteOffset === 'string') {
828
- encoding = byteOffset;
829
- byteOffset = 0;
830
- } else if (byteOffset > 0x7fffffff) {
831
- byteOffset = 0x7fffffff;
832
- } else if (byteOffset < -0x80000000) {
833
- byteOffset = -0x80000000;
834
- }
835
- byteOffset = +byteOffset; // Coerce to Number.
836
- if (isNaN(byteOffset)) {
837
- // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
838
- byteOffset = dir ? 0 : (buffer.length - 1);
839
- }
840
-
841
- // Normalize byteOffset: negative offsets start from the end of the buffer
842
- if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
843
- if (byteOffset >= buffer.length) {
844
- if (dir) return -1
845
- else byteOffset = buffer.length - 1;
846
- } else if (byteOffset < 0) {
847
- if (dir) byteOffset = 0;
848
- else return -1
849
- }
850
-
851
- // Normalize val
852
- if (typeof val === 'string') {
853
- val = Buffer.from(val, encoding);
854
- }
855
-
856
- // Finally, search either indexOf (if dir is true) or lastIndexOf
857
- if (internalIsBuffer(val)) {
858
- // Special case: looking for empty string/buffer always fails
859
- if (val.length === 0) {
860
- return -1
861
- }
862
- return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
863
- } else if (typeof val === 'number') {
864
- val = val & 0xFF; // Search for a byte value [0-255]
865
- if (Buffer.TYPED_ARRAY_SUPPORT &&
866
- typeof Uint8Array.prototype.indexOf === 'function') {
867
- if (dir) {
868
- return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
869
- } else {
870
- return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
871
- }
872
- }
873
- return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
874
- }
875
-
876
- throw new TypeError('val must be string, number or Buffer')
877
- }
878
-
879
- function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
880
- var indexSize = 1;
881
- var arrLength = arr.length;
882
- var valLength = val.length;
883
-
884
- if (encoding !== undefined) {
885
- encoding = String(encoding).toLowerCase();
886
- if (encoding === 'ucs2' || encoding === 'ucs-2' ||
887
- encoding === 'utf16le' || encoding === 'utf-16le') {
888
- if (arr.length < 2 || val.length < 2) {
889
- return -1
890
- }
891
- indexSize = 2;
892
- arrLength /= 2;
893
- valLength /= 2;
894
- byteOffset /= 2;
895
- }
896
- }
897
-
898
- function read (buf, i) {
899
- if (indexSize === 1) {
900
- return buf[i]
901
- } else {
902
- return buf.readUInt16BE(i * indexSize)
903
- }
904
- }
905
-
906
- var i;
907
- if (dir) {
908
- var foundIndex = -1;
909
- for (i = byteOffset; i < arrLength; i++) {
910
- if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
911
- if (foundIndex === -1) foundIndex = i;
912
- if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
913
- } else {
914
- if (foundIndex !== -1) i -= i - foundIndex;
915
- foundIndex = -1;
916
- }
917
- }
918
- } else {
919
- if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
920
- for (i = byteOffset; i >= 0; i--) {
921
- var found = true;
922
- for (var j = 0; j < valLength; j++) {
923
- if (read(arr, i + j) !== read(val, j)) {
924
- found = false;
925
- break
926
- }
927
- }
928
- if (found) return i
929
- }
930
- }
931
-
932
- return -1
933
- }
934
-
935
- Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
936
- return this.indexOf(val, byteOffset, encoding) !== -1
937
- };
938
-
939
- Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
940
- return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
941
- };
942
-
943
- Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
944
- return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
945
- };
946
-
947
- function hexWrite (buf, string, offset, length) {
948
- offset = Number(offset) || 0;
949
- var remaining = buf.length - offset;
950
- if (!length) {
951
- length = remaining;
952
- } else {
953
- length = Number(length);
954
- if (length > remaining) {
955
- length = remaining;
956
- }
957
- }
958
-
959
- // must be an even number of digits
960
- var strLen = string.length;
961
- if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
962
-
963
- if (length > strLen / 2) {
964
- length = strLen / 2;
965
- }
966
- for (var i = 0; i < length; ++i) {
967
- var parsed = parseInt(string.substr(i * 2, 2), 16);
968
- if (isNaN(parsed)) return i
969
- buf[offset + i] = parsed;
970
- }
971
- return i
972
- }
973
-
974
- function utf8Write (buf, string, offset, length) {
975
- return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
976
- }
977
-
978
- function asciiWrite (buf, string, offset, length) {
979
- return blitBuffer(asciiToBytes(string), buf, offset, length)
980
- }
981
-
982
- function latin1Write (buf, string, offset, length) {
983
- return asciiWrite(buf, string, offset, length)
984
- }
985
-
986
- function base64Write (buf, string, offset, length) {
987
- return blitBuffer(base64ToBytes(string), buf, offset, length)
988
- }
989
-
990
- function ucs2Write (buf, string, offset, length) {
991
- return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
992
- }
993
-
994
- Buffer.prototype.write = function write (string, offset, length, encoding) {
995
- // Buffer#write(string)
996
- if (offset === undefined) {
997
- encoding = 'utf8';
998
- length = this.length;
999
- offset = 0;
1000
- // Buffer#write(string, encoding)
1001
- } else if (length === undefined && typeof offset === 'string') {
1002
- encoding = offset;
1003
- length = this.length;
1004
- offset = 0;
1005
- // Buffer#write(string, offset[, length][, encoding])
1006
- } else if (isFinite(offset)) {
1007
- offset = offset | 0;
1008
- if (isFinite(length)) {
1009
- length = length | 0;
1010
- if (encoding === undefined) encoding = 'utf8';
1011
- } else {
1012
- encoding = length;
1013
- length = undefined;
1014
- }
1015
- // legacy write(string, encoding, offset, length) - remove in v0.13
1016
- } else {
1017
- throw new Error(
1018
- 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
1019
- )
1020
- }
1021
-
1022
- var remaining = this.length - offset;
1023
- if (length === undefined || length > remaining) length = remaining;
1024
-
1025
- if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
1026
- throw new RangeError('Attempt to write outside buffer bounds')
1027
- }
1028
-
1029
- if (!encoding) encoding = 'utf8';
1030
-
1031
- var loweredCase = false;
1032
- for (;;) {
1033
- switch (encoding) {
1034
- case 'hex':
1035
- return hexWrite(this, string, offset, length)
1036
-
1037
- case 'utf8':
1038
- case 'utf-8':
1039
- return utf8Write(this, string, offset, length)
1040
-
1041
- case 'ascii':
1042
- return asciiWrite(this, string, offset, length)
1043
-
1044
- case 'latin1':
1045
- case 'binary':
1046
- return latin1Write(this, string, offset, length)
1047
-
1048
- case 'base64':
1049
- // Warning: maxLength not taken into account in base64Write
1050
- return base64Write(this, string, offset, length)
1051
-
1052
- case 'ucs2':
1053
- case 'ucs-2':
1054
- case 'utf16le':
1055
- case 'utf-16le':
1056
- return ucs2Write(this, string, offset, length)
1057
-
1058
- default:
1059
- if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
1060
- encoding = ('' + encoding).toLowerCase();
1061
- loweredCase = true;
1062
- }
1063
- }
1064
- };
1065
-
1066
- Buffer.prototype.toJSON = function toJSON () {
1067
- return {
1068
- type: 'Buffer',
1069
- data: Array.prototype.slice.call(this._arr || this, 0)
1070
- }
1071
- };
1072
-
1073
- function base64Slice (buf, start, end) {
1074
- if (start === 0 && end === buf.length) {
1075
- return fromByteArray(buf)
1076
- } else {
1077
- return fromByteArray(buf.slice(start, end))
1078
- }
1079
- }
1080
-
1081
- function utf8Slice (buf, start, end) {
1082
- end = Math.min(buf.length, end);
1083
- var res = [];
1084
-
1085
- var i = start;
1086
- while (i < end) {
1087
- var firstByte = buf[i];
1088
- var codePoint = null;
1089
- var bytesPerSequence = (firstByte > 0xEF) ? 4
1090
- : (firstByte > 0xDF) ? 3
1091
- : (firstByte > 0xBF) ? 2
1092
- : 1;
1093
-
1094
- if (i + bytesPerSequence <= end) {
1095
- var secondByte, thirdByte, fourthByte, tempCodePoint;
1096
-
1097
- switch (bytesPerSequence) {
1098
- case 1:
1099
- if (firstByte < 0x80) {
1100
- codePoint = firstByte;
1101
- }
1102
- break
1103
- case 2:
1104
- secondByte = buf[i + 1];
1105
- if ((secondByte & 0xC0) === 0x80) {
1106
- tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
1107
- if (tempCodePoint > 0x7F) {
1108
- codePoint = tempCodePoint;
1109
- }
1110
- }
1111
- break
1112
- case 3:
1113
- secondByte = buf[i + 1];
1114
- thirdByte = buf[i + 2];
1115
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
1116
- tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
1117
- if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
1118
- codePoint = tempCodePoint;
1119
- }
1120
- }
1121
- break
1122
- case 4:
1123
- secondByte = buf[i + 1];
1124
- thirdByte = buf[i + 2];
1125
- fourthByte = buf[i + 3];
1126
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
1127
- tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
1128
- if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
1129
- codePoint = tempCodePoint;
1130
- }
1131
- }
1132
- }
1133
- }
1134
-
1135
- if (codePoint === null) {
1136
- // we did not generate a valid codePoint so insert a
1137
- // replacement char (U+FFFD) and advance only 1 byte
1138
- codePoint = 0xFFFD;
1139
- bytesPerSequence = 1;
1140
- } else if (codePoint > 0xFFFF) {
1141
- // encode to utf16 (surrogate pair dance)
1142
- codePoint -= 0x10000;
1143
- res.push(codePoint >>> 10 & 0x3FF | 0xD800);
1144
- codePoint = 0xDC00 | codePoint & 0x3FF;
1145
- }
1146
-
1147
- res.push(codePoint);
1148
- i += bytesPerSequence;
1149
- }
1150
-
1151
- return decodeCodePointsArray(res)
1152
- }
1153
-
1154
- // Based on http://stackoverflow.com/a/22747272/680742, the browser with
1155
- // the lowest limit is Chrome, with 0x10000 args.
1156
- // We go 1 magnitude less, for safety
1157
- var MAX_ARGUMENTS_LENGTH = 0x1000;
1158
-
1159
- function decodeCodePointsArray (codePoints) {
1160
- var len = codePoints.length;
1161
- if (len <= MAX_ARGUMENTS_LENGTH) {
1162
- return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
1163
- }
1164
-
1165
- // Decode in chunks to avoid "call stack size exceeded".
1166
- var res = '';
1167
- var i = 0;
1168
- while (i < len) {
1169
- res += String.fromCharCode.apply(
1170
- String,
1171
- codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
1172
- );
1173
- }
1174
- return res
1175
- }
1176
-
1177
- function asciiSlice (buf, start, end) {
1178
- var ret = '';
1179
- end = Math.min(buf.length, end);
1180
-
1181
- for (var i = start; i < end; ++i) {
1182
- ret += String.fromCharCode(buf[i] & 0x7F);
1183
- }
1184
- return ret
1185
- }
1186
-
1187
- function latin1Slice (buf, start, end) {
1188
- var ret = '';
1189
- end = Math.min(buf.length, end);
1190
-
1191
- for (var i = start; i < end; ++i) {
1192
- ret += String.fromCharCode(buf[i]);
1193
- }
1194
- return ret
1195
- }
1196
-
1197
- function hexSlice (buf, start, end) {
1198
- var len = buf.length;
1199
-
1200
- if (!start || start < 0) start = 0;
1201
- if (!end || end < 0 || end > len) end = len;
1202
-
1203
- var out = '';
1204
- for (var i = start; i < end; ++i) {
1205
- out += toHex(buf[i]);
1206
- }
1207
- return out
1208
- }
1209
-
1210
- function utf16leSlice (buf, start, end) {
1211
- var bytes = buf.slice(start, end);
1212
- var res = '';
1213
- for (var i = 0; i < bytes.length; i += 2) {
1214
- res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
1215
- }
1216
- return res
1217
- }
1218
-
1219
- Buffer.prototype.slice = function slice (start, end) {
1220
- var len = this.length;
1221
- start = ~~start;
1222
- end = end === undefined ? len : ~~end;
1223
-
1224
- if (start < 0) {
1225
- start += len;
1226
- if (start < 0) start = 0;
1227
- } else if (start > len) {
1228
- start = len;
1229
- }
1230
-
1231
- if (end < 0) {
1232
- end += len;
1233
- if (end < 0) end = 0;
1234
- } else if (end > len) {
1235
- end = len;
1236
- }
1237
-
1238
- if (end < start) end = start;
1239
-
1240
- var newBuf;
1241
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1242
- newBuf = this.subarray(start, end);
1243
- newBuf.__proto__ = Buffer.prototype;
1244
- } else {
1245
- var sliceLen = end - start;
1246
- newBuf = new Buffer(sliceLen, undefined);
1247
- for (var i = 0; i < sliceLen; ++i) {
1248
- newBuf[i] = this[i + start];
1249
- }
1250
- }
1251
-
1252
- return newBuf
1253
- };
1254
-
1255
- /*
1256
- * Need to make sure that buffer isn't trying to write out of bounds.
1257
- */
1258
- function checkOffset (offset, ext, length) {
1259
- if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
1260
- if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
1261
- }
1262
-
1263
- Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
1264
- offset = offset | 0;
1265
- byteLength = byteLength | 0;
1266
- if (!noAssert) checkOffset(offset, byteLength, this.length);
1267
-
1268
- var val = this[offset];
1269
- var mul = 1;
1270
- var i = 0;
1271
- while (++i < byteLength && (mul *= 0x100)) {
1272
- val += this[offset + i] * mul;
1273
- }
1274
-
1275
- return val
1276
- };
1277
-
1278
- Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
1279
- offset = offset | 0;
1280
- byteLength = byteLength | 0;
1281
- if (!noAssert) {
1282
- checkOffset(offset, byteLength, this.length);
1283
- }
1284
-
1285
- var val = this[offset + --byteLength];
1286
- var mul = 1;
1287
- while (byteLength > 0 && (mul *= 0x100)) {
1288
- val += this[offset + --byteLength] * mul;
1289
- }
1290
-
1291
- return val
1292
- };
1293
-
1294
- Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
1295
- if (!noAssert) checkOffset(offset, 1, this.length);
1296
- return this[offset]
1297
- };
1298
-
1299
- Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
1300
- if (!noAssert) checkOffset(offset, 2, this.length);
1301
- return this[offset] | (this[offset + 1] << 8)
1302
- };
1303
-
1304
- Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
1305
- if (!noAssert) checkOffset(offset, 2, this.length);
1306
- return (this[offset] << 8) | this[offset + 1]
1307
- };
1308
-
1309
- Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
1310
- if (!noAssert) checkOffset(offset, 4, this.length);
1311
-
1312
- return ((this[offset]) |
1313
- (this[offset + 1] << 8) |
1314
- (this[offset + 2] << 16)) +
1315
- (this[offset + 3] * 0x1000000)
1316
- };
1317
-
1318
- Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
1319
- if (!noAssert) checkOffset(offset, 4, this.length);
1320
-
1321
- return (this[offset] * 0x1000000) +
1322
- ((this[offset + 1] << 16) |
1323
- (this[offset + 2] << 8) |
1324
- this[offset + 3])
1325
- };
1326
-
1327
- Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
1328
- offset = offset | 0;
1329
- byteLength = byteLength | 0;
1330
- if (!noAssert) checkOffset(offset, byteLength, this.length);
1331
-
1332
- var val = this[offset];
1333
- var mul = 1;
1334
- var i = 0;
1335
- while (++i < byteLength && (mul *= 0x100)) {
1336
- val += this[offset + i] * mul;
1337
- }
1338
- mul *= 0x80;
1339
-
1340
- if (val >= mul) val -= Math.pow(2, 8 * byteLength);
1341
-
1342
- return val
1343
- };
1344
-
1345
- Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
1346
- offset = offset | 0;
1347
- byteLength = byteLength | 0;
1348
- if (!noAssert) checkOffset(offset, byteLength, this.length);
1349
-
1350
- var i = byteLength;
1351
- var mul = 1;
1352
- var val = this[offset + --i];
1353
- while (i > 0 && (mul *= 0x100)) {
1354
- val += this[offset + --i] * mul;
1355
- }
1356
- mul *= 0x80;
1357
-
1358
- if (val >= mul) val -= Math.pow(2, 8 * byteLength);
1359
-
1360
- return val
1361
- };
1362
-
1363
- Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
1364
- if (!noAssert) checkOffset(offset, 1, this.length);
1365
- if (!(this[offset] & 0x80)) return (this[offset])
1366
- return ((0xff - this[offset] + 1) * -1)
1367
- };
1368
-
1369
- Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
1370
- if (!noAssert) checkOffset(offset, 2, this.length);
1371
- var val = this[offset] | (this[offset + 1] << 8);
1372
- return (val & 0x8000) ? val | 0xFFFF0000 : val
1373
- };
1374
-
1375
- Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
1376
- if (!noAssert) checkOffset(offset, 2, this.length);
1377
- var val = this[offset + 1] | (this[offset] << 8);
1378
- return (val & 0x8000) ? val | 0xFFFF0000 : val
1379
- };
1380
-
1381
- Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
1382
- if (!noAssert) checkOffset(offset, 4, this.length);
1383
-
1384
- return (this[offset]) |
1385
- (this[offset + 1] << 8) |
1386
- (this[offset + 2] << 16) |
1387
- (this[offset + 3] << 24)
1388
- };
1389
-
1390
- Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
1391
- if (!noAssert) checkOffset(offset, 4, this.length);
1392
-
1393
- return (this[offset] << 24) |
1394
- (this[offset + 1] << 16) |
1395
- (this[offset + 2] << 8) |
1396
- (this[offset + 3])
1397
- };
1398
-
1399
- Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
1400
- if (!noAssert) checkOffset(offset, 4, this.length);
1401
- return read(this, offset, true, 23, 4)
1402
- };
1403
-
1404
- Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
1405
- if (!noAssert) checkOffset(offset, 4, this.length);
1406
- return read(this, offset, false, 23, 4)
1407
- };
1408
-
1409
- Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
1410
- if (!noAssert) checkOffset(offset, 8, this.length);
1411
- return read(this, offset, true, 52, 8)
1412
- };
1413
-
1414
- Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
1415
- if (!noAssert) checkOffset(offset, 8, this.length);
1416
- return read(this, offset, false, 52, 8)
1417
- };
1418
-
1419
- function checkInt (buf, value, offset, ext, max, min) {
1420
- if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
1421
- if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
1422
- if (offset + ext > buf.length) throw new RangeError('Index out of range')
1423
- }
1424
-
1425
- Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
1426
- value = +value;
1427
- offset = offset | 0;
1428
- byteLength = byteLength | 0;
1429
- if (!noAssert) {
1430
- var maxBytes = Math.pow(2, 8 * byteLength) - 1;
1431
- checkInt(this, value, offset, byteLength, maxBytes, 0);
1432
- }
1433
-
1434
- var mul = 1;
1435
- var i = 0;
1436
- this[offset] = value & 0xFF;
1437
- while (++i < byteLength && (mul *= 0x100)) {
1438
- this[offset + i] = (value / mul) & 0xFF;
1439
- }
1440
-
1441
- return offset + byteLength
1442
- };
1443
-
1444
- Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
1445
- value = +value;
1446
- offset = offset | 0;
1447
- byteLength = byteLength | 0;
1448
- if (!noAssert) {
1449
- var maxBytes = Math.pow(2, 8 * byteLength) - 1;
1450
- checkInt(this, value, offset, byteLength, maxBytes, 0);
1451
- }
1452
-
1453
- var i = byteLength - 1;
1454
- var mul = 1;
1455
- this[offset + i] = value & 0xFF;
1456
- while (--i >= 0 && (mul *= 0x100)) {
1457
- this[offset + i] = (value / mul) & 0xFF;
1458
- }
1459
-
1460
- return offset + byteLength
1461
- };
1462
-
1463
- Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
1464
- value = +value;
1465
- offset = offset | 0;
1466
- if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
1467
- if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
1468
- this[offset] = (value & 0xff);
1469
- return offset + 1
1470
- };
1471
-
1472
- function objectWriteUInt16 (buf, value, offset, littleEndian) {
1473
- if (value < 0) value = 0xffff + value + 1;
1474
- for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
1475
- buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
1476
- (littleEndian ? i : 1 - i) * 8;
1477
- }
1478
- }
1479
-
1480
- Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
1481
- value = +value;
1482
- offset = offset | 0;
1483
- if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
1484
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1485
- this[offset] = (value & 0xff);
1486
- this[offset + 1] = (value >>> 8);
1487
- } else {
1488
- objectWriteUInt16(this, value, offset, true);
1489
- }
1490
- return offset + 2
1491
- };
1492
-
1493
- Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
1494
- value = +value;
1495
- offset = offset | 0;
1496
- if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
1497
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1498
- this[offset] = (value >>> 8);
1499
- this[offset + 1] = (value & 0xff);
1500
- } else {
1501
- objectWriteUInt16(this, value, offset, false);
1502
- }
1503
- return offset + 2
1504
- };
1505
-
1506
- function objectWriteUInt32 (buf, value, offset, littleEndian) {
1507
- if (value < 0) value = 0xffffffff + value + 1;
1508
- for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
1509
- buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff;
1510
- }
1511
- }
1512
-
1513
- Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
1514
- value = +value;
1515
- offset = offset | 0;
1516
- if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
1517
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1518
- this[offset + 3] = (value >>> 24);
1519
- this[offset + 2] = (value >>> 16);
1520
- this[offset + 1] = (value >>> 8);
1521
- this[offset] = (value & 0xff);
1522
- } else {
1523
- objectWriteUInt32(this, value, offset, true);
1524
- }
1525
- return offset + 4
1526
- };
1527
-
1528
- Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
1529
- value = +value;
1530
- offset = offset | 0;
1531
- if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
1532
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1533
- this[offset] = (value >>> 24);
1534
- this[offset + 1] = (value >>> 16);
1535
- this[offset + 2] = (value >>> 8);
1536
- this[offset + 3] = (value & 0xff);
1537
- } else {
1538
- objectWriteUInt32(this, value, offset, false);
1539
- }
1540
- return offset + 4
1541
- };
1542
-
1543
- Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
1544
- value = +value;
1545
- offset = offset | 0;
1546
- if (!noAssert) {
1547
- var limit = Math.pow(2, 8 * byteLength - 1);
1548
-
1549
- checkInt(this, value, offset, byteLength, limit - 1, -limit);
1550
- }
1551
-
1552
- var i = 0;
1553
- var mul = 1;
1554
- var sub = 0;
1555
- this[offset] = value & 0xFF;
1556
- while (++i < byteLength && (mul *= 0x100)) {
1557
- if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
1558
- sub = 1;
1559
- }
1560
- this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
1561
- }
1562
-
1563
- return offset + byteLength
1564
- };
1565
-
1566
- Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
1567
- value = +value;
1568
- offset = offset | 0;
1569
- if (!noAssert) {
1570
- var limit = Math.pow(2, 8 * byteLength - 1);
1571
-
1572
- checkInt(this, value, offset, byteLength, limit - 1, -limit);
1573
- }
1574
-
1575
- var i = byteLength - 1;
1576
- var mul = 1;
1577
- var sub = 0;
1578
- this[offset + i] = value & 0xFF;
1579
- while (--i >= 0 && (mul *= 0x100)) {
1580
- if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
1581
- sub = 1;
1582
- }
1583
- this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
1584
- }
1585
-
1586
- return offset + byteLength
1587
- };
1588
-
1589
- Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
1590
- value = +value;
1591
- offset = offset | 0;
1592
- if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
1593
- if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
1594
- if (value < 0) value = 0xff + value + 1;
1595
- this[offset] = (value & 0xff);
1596
- return offset + 1
1597
- };
1598
-
1599
- Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
1600
- value = +value;
1601
- offset = offset | 0;
1602
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
1603
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1604
- this[offset] = (value & 0xff);
1605
- this[offset + 1] = (value >>> 8);
1606
- } else {
1607
- objectWriteUInt16(this, value, offset, true);
1608
- }
1609
- return offset + 2
1610
- };
1611
-
1612
- Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
1613
- value = +value;
1614
- offset = offset | 0;
1615
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
1616
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1617
- this[offset] = (value >>> 8);
1618
- this[offset + 1] = (value & 0xff);
1619
- } else {
1620
- objectWriteUInt16(this, value, offset, false);
1621
- }
1622
- return offset + 2
1623
- };
1624
-
1625
- Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
1626
- value = +value;
1627
- offset = offset | 0;
1628
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
1629
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1630
- this[offset] = (value & 0xff);
1631
- this[offset + 1] = (value >>> 8);
1632
- this[offset + 2] = (value >>> 16);
1633
- this[offset + 3] = (value >>> 24);
1634
- } else {
1635
- objectWriteUInt32(this, value, offset, true);
1636
- }
1637
- return offset + 4
1638
- };
1639
-
1640
- Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
1641
- value = +value;
1642
- offset = offset | 0;
1643
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
1644
- if (value < 0) value = 0xffffffff + value + 1;
1645
- if (Buffer.TYPED_ARRAY_SUPPORT) {
1646
- this[offset] = (value >>> 24);
1647
- this[offset + 1] = (value >>> 16);
1648
- this[offset + 2] = (value >>> 8);
1649
- this[offset + 3] = (value & 0xff);
1650
- } else {
1651
- objectWriteUInt32(this, value, offset, false);
1652
- }
1653
- return offset + 4
1654
- };
1655
-
1656
- function checkIEEE754 (buf, value, offset, ext, max, min) {
1657
- if (offset + ext > buf.length) throw new RangeError('Index out of range')
1658
- if (offset < 0) throw new RangeError('Index out of range')
1659
- }
1660
-
1661
- function writeFloat (buf, value, offset, littleEndian, noAssert) {
1662
- if (!noAssert) {
1663
- checkIEEE754(buf, value, offset, 4);
1664
- }
1665
- write(buf, value, offset, littleEndian, 23, 4);
1666
- return offset + 4
1667
- }
1668
-
1669
- Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
1670
- return writeFloat(this, value, offset, true, noAssert)
1671
- };
1672
-
1673
- Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
1674
- return writeFloat(this, value, offset, false, noAssert)
1675
- };
1676
-
1677
- function writeDouble (buf, value, offset, littleEndian, noAssert) {
1678
- if (!noAssert) {
1679
- checkIEEE754(buf, value, offset, 8);
1680
- }
1681
- write(buf, value, offset, littleEndian, 52, 8);
1682
- return offset + 8
1683
- }
1684
-
1685
- Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
1686
- return writeDouble(this, value, offset, true, noAssert)
1687
- };
1688
-
1689
- Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
1690
- return writeDouble(this, value, offset, false, noAssert)
1691
- };
1692
-
1693
- // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
1694
- Buffer.prototype.copy = function copy (target, targetStart, start, end) {
1695
- if (!start) start = 0;
1696
- if (!end && end !== 0) end = this.length;
1697
- if (targetStart >= target.length) targetStart = target.length;
1698
- if (!targetStart) targetStart = 0;
1699
- if (end > 0 && end < start) end = start;
1700
-
1701
- // Copy 0 bytes; we're done
1702
- if (end === start) return 0
1703
- if (target.length === 0 || this.length === 0) return 0
1704
-
1705
- // Fatal error conditions
1706
- if (targetStart < 0) {
1707
- throw new RangeError('targetStart out of bounds')
1708
- }
1709
- if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
1710
- if (end < 0) throw new RangeError('sourceEnd out of bounds')
1711
-
1712
- // Are we oob?
1713
- if (end > this.length) end = this.length;
1714
- if (target.length - targetStart < end - start) {
1715
- end = target.length - targetStart + start;
1716
- }
1717
-
1718
- var len = end - start;
1719
- var i;
1720
-
1721
- if (this === target && start < targetStart && targetStart < end) {
1722
- // descending copy from end
1723
- for (i = len - 1; i >= 0; --i) {
1724
- target[i + targetStart] = this[i + start];
1725
- }
1726
- } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
1727
- // ascending copy from start
1728
- for (i = 0; i < len; ++i) {
1729
- target[i + targetStart] = this[i + start];
1730
- }
1731
- } else {
1732
- Uint8Array.prototype.set.call(
1733
- target,
1734
- this.subarray(start, start + len),
1735
- targetStart
1736
- );
1737
- }
1738
-
1739
- return len
1740
- };
1741
-
1742
- // Usage:
1743
- // buffer.fill(number[, offset[, end]])
1744
- // buffer.fill(buffer[, offset[, end]])
1745
- // buffer.fill(string[, offset[, end]][, encoding])
1746
- Buffer.prototype.fill = function fill (val, start, end, encoding) {
1747
- // Handle string cases:
1748
- if (typeof val === 'string') {
1749
- if (typeof start === 'string') {
1750
- encoding = start;
1751
- start = 0;
1752
- end = this.length;
1753
- } else if (typeof end === 'string') {
1754
- encoding = end;
1755
- end = this.length;
1756
- }
1757
- if (val.length === 1) {
1758
- var code = val.charCodeAt(0);
1759
- if (code < 256) {
1760
- val = code;
1761
- }
1762
- }
1763
- if (encoding !== undefined && typeof encoding !== 'string') {
1764
- throw new TypeError('encoding must be a string')
1765
- }
1766
- if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
1767
- throw new TypeError('Unknown encoding: ' + encoding)
1768
- }
1769
- } else if (typeof val === 'number') {
1770
- val = val & 255;
1771
- }
1772
-
1773
- // Invalid ranges are not set to a default, so can range check early.
1774
- if (start < 0 || this.length < start || this.length < end) {
1775
- throw new RangeError('Out of range index')
1776
- }
1777
-
1778
- if (end <= start) {
1779
- return this
1780
- }
1781
-
1782
- start = start >>> 0;
1783
- end = end === undefined ? this.length : end >>> 0;
1784
-
1785
- if (!val) val = 0;
1786
-
1787
- var i;
1788
- if (typeof val === 'number') {
1789
- for (i = start; i < end; ++i) {
1790
- this[i] = val;
1791
- }
1792
- } else {
1793
- var bytes = internalIsBuffer(val)
1794
- ? val
1795
- : utf8ToBytes(new Buffer(val, encoding).toString());
1796
- var len = bytes.length;
1797
- for (i = 0; i < end - start; ++i) {
1798
- this[i + start] = bytes[i % len];
1799
- }
1800
- }
1801
-
1802
- return this
1803
- };
1804
-
1805
- // HELPER FUNCTIONS
1806
- // ================
1807
-
1808
- var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
1809
-
1810
- function base64clean (str) {
1811
- // Node strips out invalid characters like \n and \t from the string, base64-js does not
1812
- str = stringtrim(str).replace(INVALID_BASE64_RE, '');
1813
- // Node converts strings with length < 2 to ''
1814
- if (str.length < 2) return ''
1815
- // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
1816
- while (str.length % 4 !== 0) {
1817
- str = str + '=';
1818
- }
1819
- return str
1820
- }
1821
-
1822
- function stringtrim (str) {
1823
- if (str.trim) return str.trim()
1824
- return str.replace(/^\s+|\s+$/g, '')
1825
- }
1826
-
1827
- function toHex (n) {
1828
- if (n < 16) return '0' + n.toString(16)
1829
- return n.toString(16)
1830
- }
1831
-
1832
- function utf8ToBytes (string, units) {
1833
- units = units || Infinity;
1834
- var codePoint;
1835
- var length = string.length;
1836
- var leadSurrogate = null;
1837
- var bytes = [];
1838
-
1839
- for (var i = 0; i < length; ++i) {
1840
- codePoint = string.charCodeAt(i);
1841
-
1842
- // is surrogate component
1843
- if (codePoint > 0xD7FF && codePoint < 0xE000) {
1844
- // last char was a lead
1845
- if (!leadSurrogate) {
1846
- // no lead yet
1847
- if (codePoint > 0xDBFF) {
1848
- // unexpected trail
1849
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1850
- continue
1851
- } else if (i + 1 === length) {
1852
- // unpaired lead
1853
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1854
- continue
1855
- }
1856
-
1857
- // valid lead
1858
- leadSurrogate = codePoint;
1859
-
1860
- continue
1861
- }
1862
-
1863
- // 2 leads in a row
1864
- if (codePoint < 0xDC00) {
1865
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1866
- leadSurrogate = codePoint;
1867
- continue
1868
- }
1869
-
1870
- // valid surrogate pair
1871
- codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
1872
- } else if (leadSurrogate) {
1873
- // valid bmp char, but last char was a lead
1874
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1875
- }
1876
-
1877
- leadSurrogate = null;
1878
-
1879
- // encode utf8
1880
- if (codePoint < 0x80) {
1881
- if ((units -= 1) < 0) break
1882
- bytes.push(codePoint);
1883
- } else if (codePoint < 0x800) {
1884
- if ((units -= 2) < 0) break
1885
- bytes.push(
1886
- codePoint >> 0x6 | 0xC0,
1887
- codePoint & 0x3F | 0x80
1888
- );
1889
- } else if (codePoint < 0x10000) {
1890
- if ((units -= 3) < 0) break
1891
- bytes.push(
1892
- codePoint >> 0xC | 0xE0,
1893
- codePoint >> 0x6 & 0x3F | 0x80,
1894
- codePoint & 0x3F | 0x80
1895
- );
1896
- } else if (codePoint < 0x110000) {
1897
- if ((units -= 4) < 0) break
1898
- bytes.push(
1899
- codePoint >> 0x12 | 0xF0,
1900
- codePoint >> 0xC & 0x3F | 0x80,
1901
- codePoint >> 0x6 & 0x3F | 0x80,
1902
- codePoint & 0x3F | 0x80
1903
- );
1904
- } else {
1905
- throw new Error('Invalid code point')
1906
- }
1907
- }
1908
-
1909
- return bytes
1910
- }
1911
-
1912
- function asciiToBytes (str) {
1913
- var byteArray = [];
1914
- for (var i = 0; i < str.length; ++i) {
1915
- // Node's code seems to be doing this and not & 0x7F..
1916
- byteArray.push(str.charCodeAt(i) & 0xFF);
1917
- }
1918
- return byteArray
1919
- }
1920
-
1921
- function utf16leToBytes (str, units) {
1922
- var c, hi, lo;
1923
- var byteArray = [];
1924
- for (var i = 0; i < str.length; ++i) {
1925
- if ((units -= 2) < 0) break
1926
-
1927
- c = str.charCodeAt(i);
1928
- hi = c >> 8;
1929
- lo = c % 256;
1930
- byteArray.push(lo);
1931
- byteArray.push(hi);
1932
- }
1933
-
1934
- return byteArray
1935
- }
1936
-
1937
-
1938
- function base64ToBytes (str) {
1939
- return toByteArray(base64clean(str))
1940
- }
1941
-
1942
- function blitBuffer (src, dst, offset, length) {
1943
- for (var i = 0; i < length; ++i) {
1944
- if ((i + offset >= dst.length) || (i >= src.length)) break
1945
- dst[i + offset] = src[i];
1946
- }
1947
- return i
1948
- }
1949
-
1950
- function isnan (val) {
1951
- return val !== val // eslint-disable-line no-self-compare
1952
- }
1953
-
1954
-
1955
- // the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
1956
- // The _isBuffer check is for Safari 5-7 support, because it's missing
1957
- // Object.prototype.constructor. Remove this eventually
1958
- function isBuffer(obj) {
1959
- return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
1960
- }
1961
-
1962
- function isFastBuffer (obj) {
1963
- return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
1964
- }
1965
-
1966
- // For Node v0.10 support. Remove this eventually.
1967
- function isSlowBuffer (obj) {
1968
- return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0))
1969
- }
1970
-
1971
- export { Buffer as B };