mirror of
https://github.com/TeamPiped/Piped.git
synced 2024-08-14 23:57:27 +00:00
Add helper utility to compress data.
This commit is contained in:
parent
8376723f31
commit
e79ebc2429
3 changed files with 26 additions and 0 deletions
|
@ -21,6 +21,7 @@
|
|||
"linkify-html": "4.1.1",
|
||||
"linkifyjs": "4.1.1",
|
||||
"mux.js": "6.3.0",
|
||||
"pako": "2.1.0",
|
||||
"qrcode": "^1.5.3",
|
||||
"shaka-player": "4.4.1",
|
||||
"stream-browserify": "3.0.0",
|
||||
|
|
|
@ -38,6 +38,9 @@ dependencies:
|
|||
mux.js:
|
||||
specifier: 6.3.0
|
||||
version: 6.3.0
|
||||
pako:
|
||||
specifier: 2.1.0
|
||||
version: 2.1.0
|
||||
qrcode:
|
||||
specifier: ^1.5.3
|
||||
version: 1.5.3
|
||||
|
@ -4177,6 +4180,10 @@ packages:
|
|||
engines: {node: '>=6'}
|
||||
dev: false
|
||||
|
||||
/pako@2.1.0:
|
||||
resolution: {integrity: sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==}
|
||||
dev: false
|
||||
|
||||
/parent-module@1.0.1:
|
||||
resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==}
|
||||
engines: {node: '>=6'}
|
||||
|
|
18
src/utils/compressionUtils.js
Normal file
18
src/utils/compressionUtils.js
Normal 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);
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue