Skip to content

Commit

Permalink
refactor(ports): move from zipjs to jszip
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohe-Am committed Dec 11, 2023
1 parent fd88974 commit 09906cd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 30 deletions.
16 changes: 16 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion deps/ports.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! This contains dependencies used by plugins

export * from "./common.ts";
export * as zipjs from "https://deno.land/x/[email protected]/index.js";
export { Foras } from "https://deno.land/x/[email protected]/src/deno/mod.ts";
export * as std_tar from "https://deno.land/[email protected]/archive/tar.ts";
export * as std_streams from "https://deno.land/[email protected]/streams/mod.ts";
export * as std_io from "https://deno.land/[email protected]/io/mod.ts";
export * as jszip from "https://deno.land/x/[email protected]/mod.ts";
4 changes: 2 additions & 2 deletions ghjk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import whiz from "./ports/whiz.ts";
// cargo_insta({});
// jco({});
// mold({});
act({});
// act({});
// asdf({
// pluginRepo: "https://github.com/asdf-community/asdf-cmake",
// installType: "version",
// });
// protoc({ });
protoc({});
// earthly({});
// ruff({});
// whiz({});
45 changes: 18 additions & 27 deletions utils/unarchive.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
Foras,
jszip,
std_fs,
std_io,
std_path,
std_streams,
std_tar,
zipjs,
} from "../deps/ports.ts";

/// Uses file extension to determine type
Expand Down Expand Up @@ -98,30 +98,21 @@ export async function unzip(
path: string,
dest = "./",
) {
const zipFile = await Deno.open(path, { read: true });
const zipReader = new zipjs.ZipReader(zipFile.readable);
try {
await Promise.allSettled(
(await zipReader.getEntries()).map(async (entry) => {
const filePath = std_path.resolve(dest, entry.filename);
if (entry.directory) {
await std_fs.ensureDir(filePath);
return;
}
await std_fs.ensureDir(std_path.dirname(filePath));
const file = await Deno.open(filePath, {
create: true,
truncate: true,
write: true,
mode: entry.externalFileAttribute >> 16,
});
if (!entry.getData) throw Error("impossible");
await entry.getData(file.writable);
}),
);
} catch (err) {
throw err;
} finally {
zipReader.close();
}
const zipArc = await jszip.readZip(path);
await Promise.allSettled(
Object.entries(zipArc.files()).map(async ([_, entry]) => {
const filePath = std_path.resolve(dest, entry.name);
if (entry.dir) {
await std_fs.ensureDir(filePath);
return;
}
await std_fs.ensureDir(std_path.dirname(filePath));
const buf = await entry.async("uint8array");
await Deno.writeFile(filePath, buf, {
create: true,
// FIXME: windows support
mode: Number(entry.unixPermissions ?? 0o666),
});
}),
);
}

0 comments on commit 09906cd

Please sign in to comment.