scroll/src/deno/file_io.ts

29 lines
776 B
JavaScript

import { IFIO } from '../common/runtime.ts';
const DenoFileIO: IFIO = {
openFile: async function (path: string): Promise<string> {
const decoder = new TextDecoder('utf-8');
const data = await Deno.readFile(path);
return decoder.decode(data);
},
openFileSync: function (path: string): string {
const decoder = new TextDecoder('utf-8');
const data = Deno.readFileSync(path);
return decoder.decode(data);
},
appendFile: async function (path: string, contents: string): Promise<void> {
const file = await Deno.open(path, {
write: true,
append: true,
create: true,
});
const encoder = new TextEncoder();
const writer = file.writable.getWriter();
await writer.write(encoder.encode(contents));
file.close();
},
};
export default DenoFileIO;