Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace of compressing module #36

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cli.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { compress, ensureDir, join, parseArgs, walk } from "./deps.ts";
import { ensureDir, join, parseArgs, walk } from "./deps.ts";
import { isValidFileExtention, isValidJson } from "./core/validation.ts";
import {
convertJsonToTextData,
parsedCsvToJson,
readFile,
} from "./core/convert.ts";
import { generateDictionaryFile } from "./core/build.ts";
import { compressFile, generateDictionaryFile } from "./core/build.ts";
import { CliError } from "./core/error.ts";
import type { ImeType } from "./model.ts";

Expand Down Expand Up @@ -75,5 +75,5 @@ for await (const dirEntry of walk(join(Deno.cwd(), args.dir))) {
}

if (args.compress) {
await compress("bid_output", "bid_output_archive");
await compressFile("bid_output", "bid_output_archive");
}
22 changes: 20 additions & 2 deletions core/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Buffer, compress } from "../deps.ts";
import {
Buffer,
getFileList,
readFile,
TextReader,
Uint8ArrayWriter,
ZipWriter,
} from "../deps.ts";
import { imeConfig } from "./config.ts";
import type { ImeType } from "../model.ts";

Expand Down Expand Up @@ -28,7 +35,18 @@ export const compressFile = async (
filePath: string,
archivePath: string,
): Promise<void> => {
await compress(filePath, archivePath);
const fileList = await getFileList(filePath);
console.log({ fileList });

const uintWriter = new Uint8ArrayWriter();
const zipWriter = new ZipWriter(uintWriter);
for await (const file of fileList) {
const data = await readFile(file.path);
await zipWriter.add(file.name, new TextReader(data));
}
const zipData = await zipWriter.close();
// FIXME: 出力されたMicrosoft IMEのデータが文字化けしている
await Deno.writeFile(`${archivePath}.zip`, zipData);
};

/** ファイル出力ログを生成 */
Expand Down
30 changes: 30 additions & 0 deletions deno.lock

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

8 changes: 8 additions & 0 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ export { Buffer } from "node:buffer";
export { parse } from "https://deno.land/[email protected]/csv/parse.ts";
export { z } from "https://deno.land/x/[email protected]/mod.ts";
export { compress } from "https://deno.land/x/[email protected]/mod.ts";
export { getFileList, readFile } from "jsr:@whyk/utils/file";
export {
BlobWriter,
TextReader,
Uint8ArrayReader,
Uint8ArrayWriter,
ZipWriter,
} from "jsr:@zip-js/[email protected]";

/* --- cli --- */
export { ensureDir } from "https://deno.land/[email protected]/fs/mod.ts";
Expand Down
Loading