Skip to content

Commit

Permalink
audio.tsでgenerateTextFileDataを使うようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
sigprogramming committed Dec 26, 2024
1 parent 81656da commit ababe83
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Encoding from "encoding-japanese";
import { createUILockAction, withProgress } from "./ui";
import {
AudioItem,
Expand Down Expand Up @@ -64,6 +63,7 @@ import { cloneWithUnwrapProxy } from "@/helpers/cloneWithUnwrapProxy";
import { UnreachableError } from "@/type/utility";
import { errorToMessage } from "@/helpers/errorHelper";
import path from "@/helpers/path";
import { generateTextFileData } from "@/helpers/fileDataGenerator";

function generateAudioKey() {
return AudioKey(uuid4());
Expand Down Expand Up @@ -147,29 +147,13 @@ export async function writeTextFile(obj: {
text: string;
encoding?: EncodingType;
}) {
obj.encoding ??= "UTF-8";

const textBlob = {
"UTF-8": (text: string) => {
const bom = new Uint8Array([0xef, 0xbb, 0xbf]);
return new Blob([bom, text], {
type: "text/plain;charset=UTF-8",
});
},
Shift_JIS: (text: string) => {
const sjisArray = Encoding.convert(Encoding.stringToCode(text), {
to: "SJIS",
type: "arraybuffer",
});
return new Blob([new Uint8Array(sjisArray)], {
type: "text/plain;charset=Shift_JIS",
});
},
}[obj.encoding](obj.text);

const textFileData = await generateTextFileData({
text: obj.text,
encoding: obj.encoding,
});
return window.backend.writeFile({
filePath: obj.filePath,
buffer: await textBlob.arrayBuffer(),
buffer: textFileData,
});
}

Expand Down

0 comments on commit ababe83

Please sign in to comment.