From 7fd4ba308b5d606d50cc16a27619473ede74d653 Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Tue, 22 Feb 2022 16:38:16 +0200 Subject: [PATCH 01/16] remove decompress for v3 --- dist/services/IPFSService.js | 4 ++++ dist/types.d.ts | 2 +- src/services/IPFSService.ts | 5 +++++ src/types.ts | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dist/services/IPFSService.js b/dist/services/IPFSService.js index fa99b55..bb58b1a 100644 --- a/dist/services/IPFSService.js +++ b/dist/services/IPFSService.js @@ -62,6 +62,10 @@ class IPFSDataRetriever { const decodedZip = new TextDecoder().decode(decryptedZip); return (0, common_1.decompressData)(decodedZip); } + if (ipfsVersion === 'v3') { + console.log('v3 directly returns decrypted files without decompress'); + return decryptedZip; + } const decompressed = (0, common_1.decompressData)(decryptedZip); return decompressed; }); diff --git a/dist/types.d.ts b/dist/types.d.ts index e346f22..33d7099 100644 --- a/dist/types.d.ts +++ b/dist/types.d.ts @@ -23,7 +23,7 @@ export interface IpfsAttachmentData { head: string; contentType: string; } -export declare type IpfsDataVersion = undefined | "v2"; +export declare type IpfsDataVersion = undefined | "v2" | "v3"; export interface IpfsData { version: IpfsDataVersion; plaintText: IpfsContentData; diff --git a/src/services/IPFSService.ts b/src/services/IPFSService.ts index c2644aa..3b554f2 100644 --- a/src/services/IPFSService.ts +++ b/src/services/IPFSService.ts @@ -78,6 +78,11 @@ class IPFSDataRetriever { return decompressData(decodedZip); } + if (ipfsVersion === "v3") { + console.log("v3 directly returns decrypted files without decompress"); + return decryptedZip; + } + const decompressed = decompressData(decryptedZip); return decompressed; } diff --git a/src/types.ts b/src/types.ts index be29d59..8b0c39a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -28,7 +28,7 @@ export interface IpfsAttachmentData { contentType: string; } -export type IpfsDataVersion = undefined | "v2"; +export type IpfsDataVersion = undefined | "v2" | "v3"; export interface IpfsData { version: IpfsDataVersion; -- GitLab From d23418133ce70d7423082a496ccb46e534885d3b Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Tue, 22 Feb 2022 17:05:12 +0200 Subject: [PATCH 02/16] add build --- dist/services/IPFSService.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/services/IPFSService.js b/dist/services/IPFSService.js index bb58b1a..c82f8cf 100644 --- a/dist/services/IPFSService.js +++ b/dist/services/IPFSService.js @@ -62,8 +62,8 @@ class IPFSDataRetriever { const decodedZip = new TextDecoder().decode(decryptedZip); return (0, common_1.decompressData)(decodedZip); } - if (ipfsVersion === 'v3') { - console.log('v3 directly returns decrypted files without decompress'); + if (ipfsVersion === "v3") { + console.log("v3 directly returns decrypted files without decompress"); return decryptedZip; } const decompressed = (0, common_1.decompressData)(decryptedZip); -- GitLab From a512761ec5994eabe58c312c24822a0b140925ff Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Wed, 23 Feb 2022 09:40:22 +0200 Subject: [PATCH 03/16] CLOUD_BUILD add v3 --- dist/services/IPFSService.js | 2 +- src/services/IPFSService.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/services/IPFSService.js b/dist/services/IPFSService.js index c82f8cf..b8f1d16 100644 --- a/dist/services/IPFSService.js +++ b/dist/services/IPFSService.js @@ -39,7 +39,7 @@ class IPFSDataRetriever { }); ipfsFileContent = (0, common_1.base64ToArrayBuffer)(response.data); } - else if (ipfsVersion === "v2") { + else if (ipfsVersion === "v2" || ipfsVersion === "v3") { const result = yield axios_1.default.get(`${this.ipfsUrl}${GET_CONTENT_PATH}/${cid}`, { responseType: "arraybuffer" }); ipfsFileContent = Buffer.from(result.data); } diff --git a/src/services/IPFSService.ts b/src/services/IPFSService.ts index 3b554f2..5b8c87d 100644 --- a/src/services/IPFSService.ts +++ b/src/services/IPFSService.ts @@ -39,7 +39,7 @@ class IPFSDataRetriever { }); ipfsFileContent = base64ToArrayBuffer(response.data); - } else if (ipfsVersion === "v2") { + } else if (ipfsVersion === "v2" || ipfsVersion === "v3") { const result = await axios.get( `${this.ipfsUrl}${GET_CONTENT_PATH}/${cid}`, { responseType: "arraybuffer" } -- GitLab From ae405ec557265b3e25399631725e2f77c8d6f08c Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Wed, 23 Feb 2022 12:01:17 +0200 Subject: [PATCH 04/16] add timers for compression --- dist/utils/common.js | 5 ++++- src/utils/common.ts | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/dist/utils/common.js b/dist/utils/common.js index dbbdd8d..eea1ec7 100644 --- a/dist/utils/common.js +++ b/dist/utils/common.js @@ -39,8 +39,11 @@ const ensureUint8Array = (data) => { }; exports.ensureUint8Array = ensureUint8Array; const compressData = (binary) => { + console.time('compression'); const deflate = new zlib_min_1.Zlib.Deflate((0, exports.ensureUint8Array)(binary)); - return deflate.compress(); + const result = deflate.compress(); + console.timeEnd('compression'); + return result; }; exports.compressData = compressData; const decompressData = (binary) => { diff --git a/src/utils/common.ts b/src/utils/common.ts index 02d2372..b59594c 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -30,8 +30,12 @@ export const ensureUint8Array = ( }; export const compressData = (binary: string | ArrayBuffer): ArrayBuffer => { + console.time("compression"); const deflate = new Zlib.Deflate(ensureUint8Array(binary)); - return deflate.compress(); + const result = deflate.compress(); + console.timeEnd("compression"); + + return result; }; export const decompressData = (binary: string | ArrayBuffer): ArrayBuffer => { -- GitLab From 016d5c73ac73209340e8cd2a55e625355be04f9f Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Wed, 23 Feb 2022 12:29:29 +0200 Subject: [PATCH 05/16] timers --- dist/utils/common.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/utils/common.js b/dist/utils/common.js index eea1ec7..5df327e 100644 --- a/dist/utils/common.js +++ b/dist/utils/common.js @@ -39,10 +39,10 @@ const ensureUint8Array = (data) => { }; exports.ensureUint8Array = ensureUint8Array; const compressData = (binary) => { - console.time('compression'); + console.time("compression"); const deflate = new zlib_min_1.Zlib.Deflate((0, exports.ensureUint8Array)(binary)); const result = deflate.compress(); - console.timeEnd('compression'); + console.timeEnd("compression"); return result; }; exports.compressData = compressData; -- GitLab From e8ae9bcb88106720e7c74eaf4b0e19361f959769 Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Wed, 23 Feb 2022 13:45:28 +0200 Subject: [PATCH 06/16] gzip instead inflate --- dist/utils/common.js | 4 ++-- src/utils/common.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/utils/common.js b/dist/utils/common.js index 5df327e..7879c7c 100644 --- a/dist/utils/common.js +++ b/dist/utils/common.js @@ -40,14 +40,14 @@ const ensureUint8Array = (data) => { exports.ensureUint8Array = ensureUint8Array; const compressData = (binary) => { console.time("compression"); - const deflate = new zlib_min_1.Zlib.Deflate((0, exports.ensureUint8Array)(binary)); + const deflate = new zlib_min_1.Zlib.Gzip((0, exports.ensureUint8Array)(binary)); const result = deflate.compress(); console.timeEnd("compression"); return result; }; exports.compressData = compressData; const decompressData = (binary) => { - const inflate = new zlib_min_1.Zlib.Inflate((0, exports.ensureUint8Array)(binary)); + const inflate = new zlib_min_1.Zlib.Gzip((0, exports.ensureUint8Array)(binary)); return inflate.decompress(); }; exports.decompressData = decompressData; diff --git a/src/utils/common.ts b/src/utils/common.ts index b59594c..8925be3 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -31,7 +31,7 @@ export const ensureUint8Array = ( export const compressData = (binary: string | ArrayBuffer): ArrayBuffer => { console.time("compression"); - const deflate = new Zlib.Deflate(ensureUint8Array(binary)); + const deflate = new Zlib.Gzip(ensureUint8Array(binary)); const result = deflate.compress(); console.timeEnd("compression"); @@ -39,7 +39,7 @@ export const compressData = (binary: string | ArrayBuffer): ArrayBuffer => { }; export const decompressData = (binary: string | ArrayBuffer): ArrayBuffer => { - const inflate = new Zlib.Inflate(ensureUint8Array(binary)); + const inflate = new Zlib.Gzip(ensureUint8Array(binary)); return inflate.decompress(); }; -- GitLab From 10a486a47024842055d2f1da16ce0d5d3dee81e5 Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Wed, 23 Feb 2022 14:02:53 +0200 Subject: [PATCH 07/16] gzip --- dist/utils/common.js | 6 +++--- src/utils/common.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/utils/common.js b/dist/utils/common.js index 7879c7c..46f1736 100644 --- a/dist/utils/common.js +++ b/dist/utils/common.js @@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isNode = exports.getMerkleTreeRootHash = exports.decodeBase64URL = exports.encodeBase64Url = exports.arrayBufferToHex = exports.decompressData = exports.compressData = exports.ensureUint8Array = exports.ensureArrayBuffer = exports.ensureBase64 = exports.base64ToArrayBuffer = exports.arrayBufferToBase64 = void 0; -const zlib_min_1 = require("zlibjs/bin/zlib.min"); +const gzip_min_1 = require("zlibjs/bin/gzip.min"); const index_1 = require("../index"); const arrayBufferToBase64 = (buffer) => { return Buffer.from(buffer).toString("base64"); @@ -40,14 +40,14 @@ const ensureUint8Array = (data) => { exports.ensureUint8Array = ensureUint8Array; const compressData = (binary) => { console.time("compression"); - const deflate = new zlib_min_1.Zlib.Gzip((0, exports.ensureUint8Array)(binary)); + const deflate = new gzip_min_1.Zlib.Gzip((0, exports.ensureUint8Array)(binary)); const result = deflate.compress(); console.timeEnd("compression"); return result; }; exports.compressData = compressData; const decompressData = (binary) => { - const inflate = new zlib_min_1.Zlib.Gzip((0, exports.ensureUint8Array)(binary)); + const inflate = new gzip_min_1.Zlib.Gunzip((0, exports.ensureUint8Array)(binary)); return inflate.decompress(); }; exports.decompressData = decompressData; diff --git a/src/utils/common.ts b/src/utils/common.ts index 8925be3..474c8e8 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -1,4 +1,4 @@ -import { Zlib } from "zlibjs/bin/zlib.min"; +import { Zlib } from "zlibjs/bin/gzip.min"; import { CryptoService } from "../index"; export const arrayBufferToBase64 = (buffer: ArrayBuffer): string => { @@ -39,7 +39,7 @@ export const compressData = (binary: string | ArrayBuffer): ArrayBuffer => { }; export const decompressData = (binary: string | ArrayBuffer): ArrayBuffer => { - const inflate = new Zlib.Gzip(ensureUint8Array(binary)); + const inflate = new Zlib.Gunzip(ensureUint8Array(binary)); return inflate.decompress(); }; -- GitLab From 213c5a3fb12be32c6dad739b81c0be9657f30660 Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Wed, 23 Feb 2022 14:34:58 +0200 Subject: [PATCH 08/16] fflate for gzip --- dist/utils/common.js | 25 +++++++++++++++++++++++-- package.json | 1 + src/utils/common.ts | 7 +++++-- yarn.lock | 5 +++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/dist/utils/common.js b/dist/utils/common.js index 46f1736..a86caae 100644 --- a/dist/utils/common.js +++ b/dist/utils/common.js @@ -1,4 +1,23 @@ "use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { @@ -11,6 +30,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", { value: true }); exports.isNode = exports.getMerkleTreeRootHash = exports.decodeBase64URL = exports.encodeBase64Url = exports.arrayBufferToHex = exports.decompressData = exports.compressData = exports.ensureUint8Array = exports.ensureArrayBuffer = exports.ensureBase64 = exports.base64ToArrayBuffer = exports.arrayBufferToBase64 = void 0; const gzip_min_1 = require("zlibjs/bin/gzip.min"); +const fflate = __importStar(require("fflate")); const index_1 = require("../index"); const arrayBufferToBase64 = (buffer) => { return Buffer.from(buffer).toString("base64"); @@ -40,9 +60,10 @@ const ensureUint8Array = (data) => { exports.ensureUint8Array = ensureUint8Array; const compressData = (binary) => { console.time("compression"); - const deflate = new gzip_min_1.Zlib.Gzip((0, exports.ensureUint8Array)(binary)); - const result = deflate.compress(); + const result = fflate.gzipSync((0, exports.ensureUint8Array)(binary)); console.timeEnd("compression"); + // const deflate = new Zlib.Gzip(ensureUint8Array(binary)); + // const result = deflate.compress(); return result; }; exports.compressData = compressData; diff --git a/package.json b/package.json index dcb129d..676a058 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "easyqrcodejs": "^4.3.1", "easyqrcodejs-nodejs": "^4.4.2", "eventemitter2": "^6.4.3", + "fflate": "^0.7.3", "google-protobuf": "^3.13.0", "js-md5": "^0.7.3", "penpal": "^5.3.0", diff --git a/src/utils/common.ts b/src/utils/common.ts index 474c8e8..2739660 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -1,4 +1,5 @@ import { Zlib } from "zlibjs/bin/gzip.min"; +import * as fflate from "fflate"; import { CryptoService } from "../index"; export const arrayBufferToBase64 = (buffer: ArrayBuffer): string => { @@ -31,10 +32,12 @@ export const ensureUint8Array = ( export const compressData = (binary: string | ArrayBuffer): ArrayBuffer => { console.time("compression"); - const deflate = new Zlib.Gzip(ensureUint8Array(binary)); - const result = deflate.compress(); + const result = fflate.gzipSync(ensureUint8Array(binary)); console.timeEnd("compression"); + // const deflate = new Zlib.Gzip(ensureUint8Array(binary)); + // const result = deflate.compress(); + return result; }; diff --git a/yarn.lock b/yarn.lock index 804a82d..707e39d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2662,6 +2662,11 @@ fd-slicer@~1.1.0: dependencies: pend "~1.2.0" +fflate@^0.7.3: + version "0.7.3" + resolved "https://registry.yarnpkg.com/fflate/-/fflate-0.7.3.tgz#288b034ff0e9c380eaa2feff48c787b8371b7fa5" + integrity sha512-0Zz1jOzJWERhyhsimS54VTqOteCNwRtIlh8isdL0AXLo0g7xNTfTL7oWrkmCnPhZGocKIkWHBistBrrpoNH3aw== + file-entry-cache@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-6.0.1.tgz#211b2dd9659cb0394b073e7323ac3c933d522027" -- GitLab From 66221c5300168a71dbc8a6f85a1722b08fa92794 Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Wed, 23 Feb 2022 15:06:20 +0200 Subject: [PATCH 09/16] fflate gzip with level 9 --- dist/utils/common.js | 2 +- src/utils/common.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/utils/common.js b/dist/utils/common.js index a86caae..c2d2c7f 100644 --- a/dist/utils/common.js +++ b/dist/utils/common.js @@ -60,7 +60,7 @@ const ensureUint8Array = (data) => { exports.ensureUint8Array = ensureUint8Array; const compressData = (binary) => { console.time("compression"); - const result = fflate.gzipSync((0, exports.ensureUint8Array)(binary)); + const result = fflate.gzipSync((0, exports.ensureUint8Array)(binary), { level: 9 }); console.timeEnd("compression"); // const deflate = new Zlib.Gzip(ensureUint8Array(binary)); // const result = deflate.compress(); diff --git a/src/utils/common.ts b/src/utils/common.ts index 2739660..be20fbc 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -32,7 +32,7 @@ export const ensureUint8Array = ( export const compressData = (binary: string | ArrayBuffer): ArrayBuffer => { console.time("compression"); - const result = fflate.gzipSync(ensureUint8Array(binary)); + const result = fflate.gzipSync(ensureUint8Array(binary), { level: 9 }); console.timeEnd("compression"); // const deflate = new Zlib.Gzip(ensureUint8Array(binary)); -- GitLab From 247d62996ddae1e124755a0e3c9d539fae09dc0a Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Wed, 23 Feb 2022 15:24:23 +0200 Subject: [PATCH 10/16] level 9 --- dist/utils/common.js | 1 + src/utils/common.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/dist/utils/common.js b/dist/utils/common.js index c2d2c7f..e6caf89 100644 --- a/dist/utils/common.js +++ b/dist/utils/common.js @@ -59,6 +59,7 @@ const ensureUint8Array = (data) => { }; exports.ensureUint8Array = ensureUint8Array; const compressData = (binary) => { + console.log('level 9'); console.time("compression"); const result = fflate.gzipSync((0, exports.ensureUint8Array)(binary), { level: 9 }); console.timeEnd("compression"); diff --git a/src/utils/common.ts b/src/utils/common.ts index be20fbc..9f6e636 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -31,6 +31,7 @@ export const ensureUint8Array = ( }; export const compressData = (binary: string | ArrayBuffer): ArrayBuffer => { + console.log("level 9"); console.time("compression"); const result = fflate.gzipSync(ensureUint8Array(binary), { level: 9 }); console.timeEnd("compression"); -- GitLab From d81453e4f2d0ea60751dbd6a694a22500a3701ec Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Wed, 23 Feb 2022 16:22:47 +0200 Subject: [PATCH 11/16] cleanup --- dist/services/IPFSService.js | 6 +----- dist/utils/common.js | 19 +++++++++---------- src/services/IPFSService.ts | 7 +------ src/utils/common.ts | 20 ++++++++------------ 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/dist/services/IPFSService.js b/dist/services/IPFSService.js index b8f1d16..fa99b55 100644 --- a/dist/services/IPFSService.js +++ b/dist/services/IPFSService.js @@ -39,7 +39,7 @@ class IPFSDataRetriever { }); ipfsFileContent = (0, common_1.base64ToArrayBuffer)(response.data); } - else if (ipfsVersion === "v2" || ipfsVersion === "v3") { + else if (ipfsVersion === "v2") { const result = yield axios_1.default.get(`${this.ipfsUrl}${GET_CONTENT_PATH}/${cid}`, { responseType: "arraybuffer" }); ipfsFileContent = Buffer.from(result.data); } @@ -62,10 +62,6 @@ class IPFSDataRetriever { const decodedZip = new TextDecoder().decode(decryptedZip); return (0, common_1.decompressData)(decodedZip); } - if (ipfsVersion === "v3") { - console.log("v3 directly returns decrypted files without decompress"); - return decryptedZip; - } const decompressed = (0, common_1.decompressData)(decryptedZip); return decompressed; }); diff --git a/dist/utils/common.js b/dist/utils/common.js index e6caf89..e8ac19a 100644 --- a/dist/utils/common.js +++ b/dist/utils/common.js @@ -29,7 +29,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isNode = exports.getMerkleTreeRootHash = exports.decodeBase64URL = exports.encodeBase64Url = exports.arrayBufferToHex = exports.decompressData = exports.compressData = exports.ensureUint8Array = exports.ensureArrayBuffer = exports.ensureBase64 = exports.base64ToArrayBuffer = exports.arrayBufferToBase64 = void 0; -const gzip_min_1 = require("zlibjs/bin/gzip.min"); +const zlib_min_1 = require("zlibjs/bin/zlib.min"); const fflate = __importStar(require("fflate")); const index_1 = require("../index"); const arrayBufferToBase64 = (buffer) => { @@ -59,18 +59,17 @@ const ensureUint8Array = (data) => { }; exports.ensureUint8Array = ensureUint8Array; const compressData = (binary) => { - console.log('level 9'); - console.time("compression"); - const result = fflate.gzipSync((0, exports.ensureUint8Array)(binary), { level: 9 }); - console.timeEnd("compression"); - // const deflate = new Zlib.Gzip(ensureUint8Array(binary)); - // const result = deflate.compress(); - return result; + return fflate.gzipSync((0, exports.ensureUint8Array)(binary)); }; exports.compressData = compressData; const decompressData = (binary) => { - const inflate = new gzip_min_1.Zlib.Gunzip((0, exports.ensureUint8Array)(binary)); - return inflate.decompress(); + try { + const inflate = new zlib_min_1.Zlib.Inflate((0, exports.ensureUint8Array)(binary)); + return inflate.decompress(); + } + catch (e) { + return fflate.gunzipSync((0, exports.ensureUint8Array)(binary)); + } }; exports.decompressData = decompressData; const arrayBufferToHex = (buffer) => { diff --git a/src/services/IPFSService.ts b/src/services/IPFSService.ts index 5b8c87d..c2644aa 100644 --- a/src/services/IPFSService.ts +++ b/src/services/IPFSService.ts @@ -39,7 +39,7 @@ class IPFSDataRetriever { }); ipfsFileContent = base64ToArrayBuffer(response.data); - } else if (ipfsVersion === "v2" || ipfsVersion === "v3") { + } else if (ipfsVersion === "v2") { const result = await axios.get( `${this.ipfsUrl}${GET_CONTENT_PATH}/${cid}`, { responseType: "arraybuffer" } @@ -78,11 +78,6 @@ class IPFSDataRetriever { return decompressData(decodedZip); } - if (ipfsVersion === "v3") { - console.log("v3 directly returns decrypted files without decompress"); - return decryptedZip; - } - const decompressed = decompressData(decryptedZip); return decompressed; } diff --git a/src/utils/common.ts b/src/utils/common.ts index 9f6e636..f0dc2d3 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -1,4 +1,4 @@ -import { Zlib } from "zlibjs/bin/gzip.min"; +import { Zlib } from "zlibjs/bin/zlib.min"; import * as fflate from "fflate"; import { CryptoService } from "../index"; @@ -31,20 +31,16 @@ export const ensureUint8Array = ( }; export const compressData = (binary: string | ArrayBuffer): ArrayBuffer => { - console.log("level 9"); - console.time("compression"); - const result = fflate.gzipSync(ensureUint8Array(binary), { level: 9 }); - console.timeEnd("compression"); - - // const deflate = new Zlib.Gzip(ensureUint8Array(binary)); - // const result = deflate.compress(); - - return result; + return fflate.gzipSync(ensureUint8Array(binary)); }; export const decompressData = (binary: string | ArrayBuffer): ArrayBuffer => { - const inflate = new Zlib.Gunzip(ensureUint8Array(binary)); - return inflate.decompress(); + try { + const inflate = new Zlib.Inflate(ensureUint8Array(binary)); + return inflate.decompress(); + } catch (e) { + return fflate.gunzipSync(ensureUint8Array(binary)); + } }; export const arrayBufferToHex = (buffer: ArrayBuffer): string => { -- GitLab From 871e4dcae11e144f689d9ff9504f0e6fa1a7ce4c Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Wed, 23 Feb 2022 16:23:30 +0200 Subject: [PATCH 12/16] cleanup --- dist/types.d.ts | 2 +- src/types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/types.d.ts b/dist/types.d.ts index 33d7099..e346f22 100644 --- a/dist/types.d.ts +++ b/dist/types.d.ts @@ -23,7 +23,7 @@ export interface IpfsAttachmentData { head: string; contentType: string; } -export declare type IpfsDataVersion = undefined | "v2" | "v3"; +export declare type IpfsDataVersion = undefined | "v2"; export interface IpfsData { version: IpfsDataVersion; plaintText: IpfsContentData; diff --git a/src/types.ts b/src/types.ts index 8b0c39a..be29d59 100644 --- a/src/types.ts +++ b/src/types.ts @@ -28,7 +28,7 @@ export interface IpfsAttachmentData { contentType: string; } -export type IpfsDataVersion = undefined | "v2" | "v3"; +export type IpfsDataVersion = undefined | "v2"; export interface IpfsData { version: IpfsDataVersion; -- GitLab From b8cf9c3ae37d714ca2899f5c731915c373357624 Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Thu, 24 Feb 2022 10:33:31 +0200 Subject: [PATCH 13/16] only fflate for decompress --- dist/utils/common.js | 15 +++++++-------- src/utils/common.ts | 14 ++++++++------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/dist/utils/common.js b/dist/utils/common.js index e8ac19a..f6ff3ff 100644 --- a/dist/utils/common.js +++ b/dist/utils/common.js @@ -29,7 +29,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isNode = exports.getMerkleTreeRootHash = exports.decodeBase64URL = exports.encodeBase64Url = exports.arrayBufferToHex = exports.decompressData = exports.compressData = exports.ensureUint8Array = exports.ensureArrayBuffer = exports.ensureBase64 = exports.base64ToArrayBuffer = exports.arrayBufferToBase64 = void 0; -const zlib_min_1 = require("zlibjs/bin/zlib.min"); const fflate = __importStar(require("fflate")); const index_1 = require("../index"); const arrayBufferToBase64 = (buffer) => { @@ -63,13 +62,13 @@ const compressData = (binary) => { }; exports.compressData = compressData; const decompressData = (binary) => { - try { - const inflate = new zlib_min_1.Zlib.Inflate((0, exports.ensureUint8Array)(binary)); - return inflate.decompress(); - } - catch (e) { - return fflate.gunzipSync((0, exports.ensureUint8Array)(binary)); - } + return fflate.decompressSync((0, exports.ensureUint8Array)(binary)); + // try { + // const inflate = new Zlib.Inflate(ensureUint8Array(binary)); + // return inflate.decompress(); + // } catch (e) { + // return fflate.gunzipSync(ensureUint8Array(binary)); + // } }; exports.decompressData = decompressData; const arrayBufferToHex = (buffer) => { diff --git a/src/utils/common.ts b/src/utils/common.ts index f0dc2d3..b2fca02 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -35,12 +35,14 @@ export const compressData = (binary: string | ArrayBuffer): ArrayBuffer => { }; export const decompressData = (binary: string | ArrayBuffer): ArrayBuffer => { - try { - const inflate = new Zlib.Inflate(ensureUint8Array(binary)); - return inflate.decompress(); - } catch (e) { - return fflate.gunzipSync(ensureUint8Array(binary)); - } + return fflate.decompressSync(ensureUint8Array(binary)); + + // try { + // const inflate = new Zlib.Inflate(ensureUint8Array(binary)); + // return inflate.decompress(); + // } catch (e) { + // return fflate.gunzipSync(ensureUint8Array(binary)); + // } }; export const arrayBufferToHex = (buffer: ArrayBuffer): string => { -- GitLab From 0b2b7f4f253ebd5866e988db2442a62fa576c31e Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Thu, 24 Feb 2022 10:48:22 +0200 Subject: [PATCH 14/16] clean-up --- dist/utils/common.js | 6 ------ src/utils/common.ts | 7 ------- 2 files changed, 13 deletions(-) diff --git a/dist/utils/common.js b/dist/utils/common.js index f6ff3ff..0233c1a 100644 --- a/dist/utils/common.js +++ b/dist/utils/common.js @@ -63,12 +63,6 @@ const compressData = (binary) => { exports.compressData = compressData; const decompressData = (binary) => { return fflate.decompressSync((0, exports.ensureUint8Array)(binary)); - // try { - // const inflate = new Zlib.Inflate(ensureUint8Array(binary)); - // return inflate.decompress(); - // } catch (e) { - // return fflate.gunzipSync(ensureUint8Array(binary)); - // } }; exports.decompressData = decompressData; const arrayBufferToHex = (buffer) => { diff --git a/src/utils/common.ts b/src/utils/common.ts index b2fca02..be0aec4 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -36,13 +36,6 @@ export const compressData = (binary: string | ArrayBuffer): ArrayBuffer => { export const decompressData = (binary: string | ArrayBuffer): ArrayBuffer => { return fflate.decompressSync(ensureUint8Array(binary)); - - // try { - // const inflate = new Zlib.Inflate(ensureUint8Array(binary)); - // return inflate.decompress(); - // } catch (e) { - // return fflate.gunzipSync(ensureUint8Array(binary)); - // } }; export const arrayBufferToHex = (buffer: ArrayBuffer): string => { -- GitLab From 6966cc300863e4544a0971adc9a48896b354c2d8 Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Fri, 25 Feb 2022 10:27:57 +0200 Subject: [PATCH 15/16] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 676a058..a3f4d4f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vereign/light-utils", - "version": "v2.0.7", + "version": "v2.0.8", "license": "MIT", "main": "./dist/index.js", "types": "./dist/index.d.ts", -- GitLab From 28b750ec6c0b92a34511d69a50eb181dbdeadb83 Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Fri, 25 Feb 2022 10:29:47 +0200 Subject: [PATCH 16/16] remove zlib --- package.json | 3 +-- src/utils/common.ts | 1 - yarn.lock | 5 ----- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/package.json b/package.json index a3f4d4f..f9fef52 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,7 @@ "js-md5": "^0.7.3", "penpal": "^5.3.0", "protobufjs": "^6.10.1", - "url-parse": "^1.4.7", - "zlibjs": "^0.3.1" + "url-parse": "^1.4.7" }, "peerDependencies": {} } diff --git a/src/utils/common.ts b/src/utils/common.ts index be0aec4..b74f072 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -1,4 +1,3 @@ -import { Zlib } from "zlibjs/bin/zlib.min"; import * as fflate from "fflate"; import { CryptoService } from "../index"; diff --git a/yarn.lock b/yarn.lock index 707e39d..2978c27 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5727,8 +5727,3 @@ yocto-queue@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== - -zlibjs@^0.3.1: - version "0.3.1" - resolved "https://registry.yarnpkg.com/zlibjs/-/zlibjs-0.3.1.tgz#50197edb28a1c42ca659cc8b4e6a9ddd6d444554" - integrity sha1-UBl+2yihxCymWcyLTmqd3W1ERVQ= -- GitLab