diff --git a/source/coral/files.cpp b/source/coral/files.cpp index 2231794..d9ba825 100644 --- a/source/coral/files.cpp +++ b/source/coral/files.cpp @@ -106,18 +106,31 @@ export namespace coral { char buffer[max + 1]; }; + struct file_reader : public reader { + virtual expected seek(u64 offset) = 0; + + virtual expected tell() = 0; + }; + + struct file_writer : public writer {}; + /** * Platform-generalized file system interface. */ struct fs { + struct io_rules { + bool can_read; + + bool can_write; + }; + /** * Attempts to read the file in the file system located at `file_path` relative, calling * `then` if it was successfully opened for reading. * * Once `then` returns, access to the file is closed automatically. */ - virtual void read_file(path const & file_path, - callable const & then) = 0; + virtual void read_file(path const & file_path, callable const & then) = 0; /** * Attempts to write the file in the file system located at `file_path` relative, calling @@ -125,7 +138,6 @@ export namespace coral { * * Once `then` returns, access to the file is closed automatically. */ - virtual void write_file(path const & file_path, - callable const & then) = 0; + virtual void write_file(path const & file_path, callable const & then) = 0; }; } diff --git a/source/coral/sequence.cpp b/source/coral/sequence.cpp index 24258cc..b568637 100644 --- a/source/coral/sequence.cpp +++ b/source/coral/sequence.cpp @@ -200,14 +200,20 @@ export namespace coral { /** * Writable type for appending data to a [sequence] containing [u8] values. */ - struct sequence_writer : public writable { - sequence_writer(sequence * output_sequence) : writable{ - [output_sequence](slice const & buffer) -> expected { - switch (output_sequence->append(buffer)) { - case append_result::ok: return buffer.length; - case append_result::out_of_memory: return io_error::unavailable; - default: unreachable(); - } - }} {} + struct sequence_writer : public writer { + sequence_writer(sequence * output_sequence) { + this->output_sequence = output_sequence; + } + + expected write(slice const & buffer) { + switch (output_sequence->append(buffer)) { + case append_result::ok: return buffer.length; + case append_result::out_of_memory: return io_error::unavailable; + default: unreachable(); + } + } + + private: + sequence * output_sequence; }; }