first commit
Some checks failed
Some checks failed
This commit is contained in:
31
app/lib/testcase-backend/zip.ts
Normal file
31
app/lib/testcase-backend/zip.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import archiver from "archiver";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
export function createZipFile(
|
||||
sourceDir: string,
|
||||
zipPath: string,
|
||||
englishName: string | null
|
||||
): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const output = fs.createWriteStream(zipPath);
|
||||
const archive = archiver("zip", { zlib: { level: 9 } });
|
||||
|
||||
output.on("close", () => resolve());
|
||||
archive.on("error", reject);
|
||||
archive.pipe(output);
|
||||
|
||||
if (englishName) {
|
||||
const files = fs.readdirSync(sourceDir);
|
||||
const targetFiles = files.filter(
|
||||
(f) => f.startsWith(englishName) && (f.endsWith(".in") || f.endsWith(".out"))
|
||||
);
|
||||
for (const file of targetFiles) {
|
||||
archive.file(path.join(sourceDir, file), { name: file });
|
||||
}
|
||||
} else {
|
||||
archive.directory(sourceDir, false);
|
||||
}
|
||||
archive.finalize();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user