mirror of
https://github.com/TeamPiped/Piped.git
synced 2024-11-24 14:37:20 +00:00
Add gzip decompression helper.
This commit is contained in:
parent
1265044854
commit
2d7801eb67
@ -16,3 +16,23 @@ export const compressGzip = async data => {
|
|||||||
return pako.gzip(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 New Issue
Block a user