source: trip-planner-front/node_modules/hdr-histogram-js/dist/encoding.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.0 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.encodeIntoCompressedBase64 = exports.decodeFromCompressedBase64 = exports.decompress = void 0;
4/*
5 * This is a TypeScript port of the original Java version, which was written by
6 * Gil Tene as described in
7 * https://github.com/HdrHistogram/HdrHistogram
8 * and released to the public domain, as explained at
9 * http://creativecommons.org/publicdomain/zero/1.0/
10 */
11const JsHistogram_1 = require("./JsHistogram");
12const ByteBuffer_1 = require("./ByteBuffer");
13const wasm_1 = require("./wasm");
14// @ts-ignore
15const base64 = require("base64-js");
16const JsHistogram_encoding_1 = require("./JsHistogram.encoding");
17const V2CompressedEncodingCookieBase = 0x1c849304;
18const compressedEncodingCookie = V2CompressedEncodingCookieBase | 0x10; // LSBit of wordsize byte indicates TLZE Encoding
19function decompress(data) {
20 const buffer = new ByteBuffer_1.default(data);
21 const initialTargetPosition = buffer.position;
22 const cookie = buffer.getInt32();
23 if ((cookie & ~0xf0) !== V2CompressedEncodingCookieBase) {
24 throw new Error("Encoding not supported, only V2 is supported");
25 }
26 const lengthOfCompressedContents = buffer.getInt32();
27 const uncompressedBuffer = JsHistogram_encoding_1.inflate(buffer.data.slice(initialTargetPosition + 8, initialTargetPosition + 8 + lengthOfCompressedContents));
28 return uncompressedBuffer;
29}
30exports.decompress = decompress;
31exports.decodeFromCompressedBase64 = (base64String, bitBucketSize = 32, useWebAssembly = false, minBarForHighestTrackableValue = 0) => {
32 const data = base64.toByteArray(base64String.trim());
33 const uncompressedData = decompress(data);
34 if (useWebAssembly) {
35 return wasm_1.WasmHistogram.decode(uncompressedData, bitBucketSize, minBarForHighestTrackableValue);
36 }
37 return JsHistogram_1.JsHistogram.decode(uncompressedData, bitBucketSize, minBarForHighestTrackableValue);
38};
39function encodeWasmIntoCompressedBase64(compressionLevel) {
40 const compressionOptions = compressionLevel
41 ? { level: compressionLevel }
42 : {};
43 const self = this;
44 const targetBuffer = ByteBuffer_1.default.allocate();
45 targetBuffer.putInt32(compressedEncodingCookie);
46 const uncompressedData = self.encode();
47 const compressedData = JsHistogram_encoding_1.deflate(uncompressedData, compressionOptions);
48 targetBuffer.putInt32(compressedData.byteLength);
49 targetBuffer.putArray(compressedData);
50 return base64.fromByteArray(targetBuffer.data);
51}
52wasm_1.WasmHistogram.prototype.encodeIntoCompressedBase64 = encodeWasmIntoCompressedBase64;
53exports.encodeIntoCompressedBase64 = (histogram, compressionLevel) => {
54 if (histogram instanceof wasm_1.WasmHistogram) {
55 return histogram.encodeIntoCompressedBase64(compressionLevel);
56 }
57 if (histogram instanceof JsHistogram_1.JsHistogram) {
58 return histogram.encodeIntoCompressedBase64(compressionLevel);
59 }
60 throw new Error("Unsupported Histogram implementation");
61};
62//# sourceMappingURL=encoding.js.map
Note: See TracBrowser for help on using the repository browser.