2023-11-16 16:00:03 -05:00
|
|
|
import { IFileIO } from '../common/runtime.ts';
|
2023-11-13 15:33:56 -05:00
|
|
|
|
2023-11-16 16:00:03 -05:00
|
|
|
const DenoFileIO: IFileIO = {
|
2023-11-13 15:33:56 -05:00
|
|
|
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);
|
|
|
|
},
|
2023-11-16 11:10:33 -05:00
|
|
|
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();
|
|
|
|
},
|
2023-11-16 13:00:02 -05:00
|
|
|
appendFileSync: function (path: string, contents: string) {
|
|
|
|
const encoder = new TextEncoder();
|
|
|
|
Deno.writeFileSync(path, encoder.encode(contents));
|
|
|
|
},
|
2023-11-13 15:33:56 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
export default DenoFileIO;
|