Public
Back
Version 60
6/9/2023
const arxivSourceZip = async (id) => {
const { t } = await import("npm:tar");
const { default: Zip } = await import("npm:adm-zip");
const { iterateReader } = await import(
"https://deno.land/std@0.122.0/streams/mod.ts"
);
const url = id.replace("/abs/", "/e-print/");
const response = await fetch(url);
if (!response.ok) {
throw new Error(await response.text());
}
if (response.headers.get("content-type") !== "application/x-eprint-tar") {
throw new Error(JSON.stringify(Object.fromEntries(response.headers)));
}
return new Promise(async (resolve, reject) => {
const zip = new Zip();
const extractStream = t({
filter: (path, entry) => entry.type === "File",
}).on("entry", async (entry) => {
const buffers = [];
for await (const data of entry) {
buffers.push(data);
}
zip.add(entry.path, Buffer.concat(buffers));
extractStream.resume();
}).on("error", (error) => {
reject(error);
}).on("end", () => {
resolve(
new Response(zip.toBuffer(), {
headers: {
"content-type": "application/zip",
},
}),
);
});
Updated: October 23, 2023