UNPKG

@bitblit/asyncglk

Version:
43 lines (39 loc) 998 B
/* Glk FileRefs ============ Copyright (c) 2022 Dannii Willis MIT licenced https://github.com/curiousdannii/asyncglk */ import { CachingDialogWrapper, FileBuffer } from '../dialog/common/cache.js'; import { fileusage_TextMode } from './constants.js'; export class FileRef { binary; Dialog; disprock; filename; next = null; prev = null; dfref; rock; constructor(Dialog, filename, dialog_fref, rock, usage) { this.binary = !(usage & fileusage_TextMode); this.Dialog = Dialog; this.filename = filename; this.dfref = dialog_fref; this.rock = rock; } delete_file() { this.Dialog.file_remove_ref(this.dfref); } exists() { return this.Dialog.file_ref_exists(this.dfref); } read() { return this.Dialog.file_read(this.dfref); } write(buf) { const filebuf = new FileBuffer(buf, this.binary, this.dfref); this.Dialog.write_file(this.dfref, filebuf); } }