Add helper utility to compress data.

This commit is contained in:
Kavin 2023-02-03 16:45:13 +00:00
parent 8376723f31
commit e79ebc2429
No known key found for this signature in database
GPG key ID: 6E4598CA5C92C41F
3 changed files with 26 additions and 0 deletions

View file

@ -21,6 +21,7 @@
"linkify-html": "4.1.1", "linkify-html": "4.1.1",
"linkifyjs": "4.1.1", "linkifyjs": "4.1.1",
"mux.js": "6.3.0", "mux.js": "6.3.0",
"pako": "2.1.0",
"qrcode": "^1.5.3", "qrcode": "^1.5.3",
"shaka-player": "4.4.1", "shaka-player": "4.4.1",
"stream-browserify": "3.0.0", "stream-browserify": "3.0.0",

View file

@ -38,6 +38,9 @@ dependencies:
mux.js: mux.js:
specifier: 6.3.0 specifier: 6.3.0
version: 6.3.0 version: 6.3.0
pako:
specifier: 2.1.0
version: 2.1.0
qrcode: qrcode:
specifier: ^1.5.3 specifier: ^1.5.3
version: 1.5.3 version: 1.5.3
@ -4177,6 +4180,10 @@ packages:
engines: {node: '>=6'} engines: {node: '>=6'}
dev: false dev: false
/pako@2.1.0:
resolution: {integrity: sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==}
dev: false
/parent-module@1.0.1: /parent-module@1.0.1:
resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==} resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==}
engines: {node: '>=6'} engines: {node: '>=6'}

View file

@ -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);
}
};