mirror of
https://github.com/TeamPiped/Piped.git
synced 2024-08-14 23:57:27 +00:00
Add gzip decompression helper.
This commit is contained in:
parent
1265044854
commit
2d7801eb67
1 changed files with 20 additions and 0 deletions
|
@ -16,3 +16,23 @@ export const compressGzip = async data => {
|
|||
return pako.gzip(data);
|
||||
}
|
||||
};
|
||||
|
||||
export const decompressGzip = async compressedData => {
|
||||
// Firefox does not support DecompressionStream yet
|
||||
if (typeof DecompressionStream !== "undefined") {
|
||||
// eslint-disable-next-line no-undef
|
||||
const ds = new DecompressionStream("gzip");
|
||||
const writer = ds.writable.getWriter();
|
||||
writer.write(compressedData);
|
||||
writer.close();
|
||||
const decompAb = await new Response(ds.readable).arrayBuffer();
|
||||
const bytes = new Uint8Array(decompAb);
|
||||
|
||||
return new TextDecoder().decode(bytes);
|
||||
} else {
|
||||
const pako = require("pako");
|
||||
const inflated = pako.inflate(compressedData, { to: "string" });
|
||||
|
||||
return inflated;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue