Skip to content

Commit

Permalink
Add helper utility to compress data.
Browse files Browse the repository at this point in the history
  • Loading branch information
FireMasterK committed Feb 9, 2023
1 parent 55c0e51 commit b6895a8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"hotkeys-js": "3.10.1",
"javascript-time-ago": "2.5.9",
"mux.js": "6.2.0",
"pako": "2.1.0",
"shaka-player": "4.3.4",
"stream-browserify": "3.0.0",
"vue": "3.2.47",
Expand Down
18 changes: 18 additions & 0 deletions src/utils/compressionUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const compressGzip = async data => {
// Firefox does not support CompressionStream yet
if (typeof CompressionStream !== "undefined") {
let bytes = new TextEncoder().encode(data);
// eslint-disable-next-line no-undef
const cs = new CompressionStream("gzip");
const writer = cs.writable.getWriter();
writer.write(bytes);
writer.close();
const compAb = await new Response(cs.readable).arrayBuffer();
bytes = new Uint8Array(compAb);

return bytes;
} else {
const pako = require("pako");
return pako.gzip(data);
}
};
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4011,6 +4011,11 @@ p-locate@^5.0.0:
dependencies:
p-limit "^3.0.2"

[email protected]:
version "2.1.0"
resolved "https://registry.yarnpkg.com/pako/-/pako-2.1.0.tgz#266cc37f98c7d883545d11335c00fbd4062c9a86"
integrity sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==

parent-module@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2"
Expand Down

0 comments on commit b6895a8

Please sign in to comment.