diff --git a/src/state.ts b/src/state.ts index e60af2e..fd611de 100644 --- a/src/state.ts +++ b/src/state.ts @@ -34,17 +34,15 @@ export class FileStateBackend implements StateBackend { constructor(private path: string) {} async read(): Promise { - const decoder = new TextDecoder(); - const data = await Deno.readFile(this.path); - const json = JSON.parse(decoder.decode(data)); + const data = await Deno.readTextFile(this.path); + const json = JSON.parse(data); return json; } async write(newState: State): Promise { - const encoder = new TextEncoder(); - const data = encoder.encode(JSON.stringify(newState, undefined, 2)); + const data = JSON.stringify(newState, undefined, 2); const swapPath = `${this.path}.swap`; - await Deno.writeFile(swapPath, data); + await Deno.writeTextFile(swapPath, data); await Deno.rename(swapPath, this.path); } }