mirror of
https://github.com/catdevnull/transicion-desordenada-diablo
synced 2024-11-15 10:31:38 +00:00
permitir ver dumps sin comprimir
This commit is contained in:
parent
f5c40943eb
commit
e155ab4aa7
1 changed files with 9 additions and 5 deletions
|
@ -6,21 +6,25 @@ export async function downloadFile(
|
||||||
datasetId: string,
|
datasetId: string,
|
||||||
dist: Distribution,
|
dist: Distribution,
|
||||||
) {
|
) {
|
||||||
|
if (!dist.downloadURL) throw new Error("no downloadURL");
|
||||||
const outputS = streamSaver.createWriteStream(
|
const outputS = streamSaver.createWriteStream(
|
||||||
dist.downloadURL.slice(dist.downloadURL.lastIndexOf("/") + 1),
|
dist.downloadURL.slice(dist.downloadURL.lastIndexOf("/") + 1),
|
||||||
);
|
);
|
||||||
const res = await fetch(
|
const res = await fetchGzipped(
|
||||||
`${dataPath}/${datasetId}/${dist.identifier}/${
|
`${dataPath}/${datasetId}/${dist.identifier}/${
|
||||||
dist.fileName || dist.identifier
|
dist.fileName || dist.identifier
|
||||||
}.gz`,
|
}.gz`,
|
||||||
);
|
);
|
||||||
const ds = new DecompressionStream("gzip");
|
await res.body!.pipeTo(outputS);
|
||||||
const decompressedStream = res.body!.pipeThrough(ds);
|
|
||||||
await decompressedStream.pipeTo(outputS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchGzipped(url: string): Promise<Response> {
|
async function fetchGzipped(url: string): Promise<Response> {
|
||||||
const res = await fetch(url);
|
let res = await fetch(url);
|
||||||
|
if (res.status === 404 && url.endsWith(".gz")) {
|
||||||
|
// probar cargando el archivo no comprimido
|
||||||
|
res = await fetch(url.slice(0, url.length - ".gz".length));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
const ds = new DecompressionStream("gzip");
|
const ds = new DecompressionStream("gzip");
|
||||||
const decompressedStream = res.body!.pipeThrough(ds);
|
const decompressedStream = res.body!.pipeThrough(ds);
|
||||||
const resD = new Response(decompressedStream);
|
const resD = new Response(decompressedStream);
|
||||||
|
|
Loading…
Reference in a new issue