@contrail/util 1.1.8 → 1.1.9-alpha-1
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.
|
@@ -2,28 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.decompressFromString = exports.compressIntoString = void 0;
|
|
4
4
|
const fflate_1 = require("fflate");
|
|
5
|
-
const bufferToString = (buffer) => {
|
|
6
|
-
let result = '';
|
|
7
|
-
for (let value of buffer)
|
|
8
|
-
result += String.fromCharCode(value);
|
|
9
|
-
return result;
|
|
10
|
-
};
|
|
11
|
-
const stringToBuffer = (str) => {
|
|
12
|
-
let result = new Uint8Array(str.length);
|
|
13
|
-
for (let i = 0; i < str.length; ++i)
|
|
14
|
-
result[i] = str.charCodeAt(i);
|
|
15
|
-
return result;
|
|
16
|
-
};
|
|
17
5
|
function compressIntoString(obj) {
|
|
18
|
-
const
|
|
19
|
-
const buffer =
|
|
6
|
+
const jsonStr = JSON.stringify(obj === undefined ? null : obj);
|
|
7
|
+
const buffer = new TextEncoder().encode(jsonStr);
|
|
20
8
|
const compressed = (0, fflate_1.compressSync)(buffer);
|
|
21
|
-
return
|
|
9
|
+
return Buffer.from(compressed).toString('base64');
|
|
22
10
|
}
|
|
23
11
|
exports.compressIntoString = compressIntoString;
|
|
24
12
|
function decompressFromString(str) {
|
|
25
|
-
const
|
|
26
|
-
const decompressed = (0, fflate_1.decompressSync)(
|
|
13
|
+
const compressed = Buffer.from(str, 'base64');
|
|
14
|
+
const decompressed = (0, fflate_1.decompressSync)(compressed);
|
|
27
15
|
const originalText = new TextDecoder().decode(decompressed);
|
|
28
16
|
return JSON.parse(originalText);
|
|
29
17
|
}
|