Commit graph

15 commits

Author SHA1 Message Date
Tim Schumacher 8464da1439 AK: Move Stream and SeekableStream from LibCore
`Stream` will be qualified as `AK::Stream` until we remove the
`Core::Stream` namespace. `IODevice` now reuses the `SeekMode` that is
defined by `SeekableStream`, since defining its own would require us to
qualify it with `AK::SeekMode` everywhere.
2023-01-29 19:16:44 -07:00
Tim Schumacher daf181caa8 LibCore: Let offset-related Stream functions return an unsigned value
A negative return value doesn't make sense for any of those functions.
The return types were inherited from POSIX, where they also need to have
an indicator for an error (negative values).
2023-01-19 11:41:56 +01:00
Tim Schumacher 156b6e83cd LibCore: Add AllocatingMemoryStream::offset_of 2023-01-14 00:33:35 +03:30
Tim Schumacher f205f62a44 LibCore: Add an automatically allocating MemoryStream
Similar to AK::DuplexStream, this writes to the end and reads from the
beginning of a dynamically allocated buffer.
2022-12-15 13:28:29 +00:00
Tim Schumacher 8dbc7aa63f LibCore: Move the MemoryStream implementation into a separate file 2022-12-15 13:28:29 +00:00
Tim Schumacher c6d71ca727 LibCore: Rename MemoryStream to FixedMemoryStream
This is to differentiate between the upcoming `AllocatingMemoryStream`,
which automatically allocates memory as needed instead of operating on a
static memory area.
2022-12-15 13:28:29 +00:00
Tim Schumacher 9a3e95785e LibCore: Propagate errors from Stream::*_entire_buffer 2022-12-12 14:16:42 +01:00
Tim Schumacher 6c7c5a6786 LibCore: Rename Stream::*_or_error to *_entire_buffer
All of our functions are `_or_error` (or are about to be), and maybe
making it less reminiscient of AK::Stream will make people use it more.
2022-12-12 14:16:42 +01:00
Tim Schumacher d402f6cdb3 LibCore: Add support for ReadonlyBytes to MemoryStream 2022-11-30 12:09:53 +00:00
Lucas CHOLLET db40a514f5 LibCore: Allow MemoryStream::seek to go to EOF
The method still prevents you to go out of bound.
2022-11-13 18:51:18 -07:00
sin-ack e5f09ea170 Everywhere: Split Error::from_string_literal and Error::from_string_view
Error::from_string_literal now takes direct char const*s, while
Error::from_string_view does what Error::from_string_literal used to do:
taking StringViews. This change will remove the need to insert `sv`
after error strings when returning string literal errors once
StringView(char const*) is removed.

No functional changes.
2022-07-12 23:11:35 +02:00
Sam Atkins 3b1e063d30 LibCore+Everywhere: Make Core::Stream::read() return Bytes
A mistake I've repeatedly made is along these lines:
```c++
auto nread = TRY(source_file->read(buffer));
TRY(destination_file->write(buffer));
```

It's a little clunky to have to create a Bytes or StringView from the
buffer's data pointer and the nread, and easy to forget and just use
the buffer. So, this patch changes the read() function to return a
Bytes of the data that were just read.

The other read_foo() methods will be modified in the same way in
subsequent commits.

Fixes #13687
2022-04-16 13:27:51 -04:00
Idan Horowitz 086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Sam Atkins 4d5080388a LibCore+Tests: Add SeekableStream::truncate() 2022-02-16 19:49:41 -05:00
kleines Filmröllchen d786142eca LibCore: Introduce MemoryStream
MemoryStream is the Core::Stream API's streamlike access to a chunk of
memory, mimicking AK::DuplexMemoryStream. The implementation is very
similar, except that no APIs except the SeekableStream operations
currently exist. This will be fine for the first users and can be
expanded upon later.
2022-01-22 01:13:42 +03:30