mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2025-02-25 10:11:00 -05:00
18 lines
687 B
TypeScript
18 lines
687 B
TypeScript
import { basename, resolve as resolvePath } from "node:path";
|
|
import Zip from "adm-zip";
|
|
|
|
export function zipFile(path: string | string[], zipPath?: string): Buffer {
|
|
const fs = jest.requireActual<typeof import("node:fs")>("node:fs");
|
|
const realPath = typeof path === "string" ? path : resolvePath(...path);
|
|
zipPath ||= basename(realPath);
|
|
|
|
const zip = new Zip();
|
|
zip.addFile(zipPath, fs.readFileSync(realPath));
|
|
return zip.toBuffer();
|
|
}
|
|
|
|
export function zipContent(content: string | Buffer, zipPath: string): Buffer {
|
|
const zip = new Zip();
|
|
zip.addFile(zipPath, typeof content === "string" ? Buffer.from(content) : content);
|
|
return zip.toBuffer();
|
|
}
|