1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:57:47 +00:00

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.
This commit is contained in:
Tim Schumacher 2022-12-07 15:47:44 +01:00 committed by Linus Groh
parent c4f68bde57
commit c6d71ca727
11 changed files with 29 additions and 27 deletions

View file

@ -42,7 +42,7 @@ Result<NonnullOwnPtr<FlacLoaderPlugin>, LoaderError> FlacLoaderPlugin::try_creat
Result<NonnullOwnPtr<FlacLoaderPlugin>, LoaderError> FlacLoaderPlugin::try_create(Bytes buffer)
{
auto stream = LOADER_TRY(Core::Stream::MemoryStream::construct(buffer));
auto stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(buffer));
auto loader = make<FlacLoaderPlugin>(move(stream));
LOADER_TRY(loader->initialize());
@ -78,7 +78,7 @@ MaybeLoaderError FlacLoaderPlugin::parse_header()
// Receive the streaminfo block
auto streaminfo = TRY(next_meta_block(*bit_input));
FLAC_VERIFY(streaminfo.type == FlacMetadataBlockType::STREAMINFO, LoaderError::Category::Format, "First block must be STREAMINFO");
auto streaminfo_data_memory = LOADER_TRY(Core::Stream::MemoryStream::construct(streaminfo.data.bytes()));
auto streaminfo_data_memory = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(streaminfo.data.bytes()));
auto streaminfo_data = LOADER_TRY(BigEndianInputBitStream::construct(Core::Stream::Handle<Core::Stream::Stream>(*streaminfo_data_memory)));
// 11.10 METADATA_BLOCK_STREAMINFO
@ -149,7 +149,7 @@ MaybeLoaderError FlacLoaderPlugin::parse_header()
// 11.19. METADATA_BLOCK_PICTURE
MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block)
{
auto memory_stream = LOADER_TRY(Core::Stream::MemoryStream::construct(block.data.bytes()));
auto memory_stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(block.data.bytes()));
auto picture_block_bytes = LOADER_TRY(BigEndianInputBitStream::construct(Core::Stream::Handle<Core::Stream::Stream>(*memory_stream)));
PictureData picture {};
@ -186,7 +186,7 @@ MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block)
// 11.13. METADATA_BLOCK_SEEKTABLE
MaybeLoaderError FlacLoaderPlugin::load_seektable(FlacRawMetadataBlock& block)
{
auto memory_stream = LOADER_TRY(Core::Stream::MemoryStream::construct(block.data.bytes()));
auto memory_stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(block.data.bytes()));
auto seektable_bytes = LOADER_TRY(BigEndianInputBitStream::construct(Core::Stream::Handle<Core::Stream::Stream>(*memory_stream)));
for (size_t i = 0; i < block.length / 18; ++i) {
// 11.14. SEEKPOINT

View file

@ -31,7 +31,7 @@ Result<NonnullOwnPtr<MP3LoaderPlugin>, LoaderError> MP3LoaderPlugin::try_create(
Result<NonnullOwnPtr<MP3LoaderPlugin>, LoaderError> MP3LoaderPlugin::try_create(Bytes buffer)
{
auto stream = LOADER_TRY(Core::Stream::MemoryStream::construct(buffer));
auto stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(buffer));
auto loader = make<MP3LoaderPlugin>(move(stream));
LOADER_TRY(loader->initialize());

View file

@ -35,7 +35,7 @@ Result<NonnullOwnPtr<WavLoaderPlugin>, LoaderError> WavLoaderPlugin::try_create(
Result<NonnullOwnPtr<WavLoaderPlugin>, LoaderError> WavLoaderPlugin::try_create(Bytes buffer)
{
auto stream = LOADER_TRY(Core::Stream::MemoryStream::construct(buffer));
auto stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(buffer));
auto loader = make<WavLoaderPlugin>(move(stream));
LOADER_TRY(loader->initialize());
@ -115,7 +115,7 @@ static ErrorOr<double> read_sample(Core::Stream::Stream& stream)
LoaderSamples WavLoaderPlugin::samples_from_pcm_data(Bytes const& data, size_t samples_to_read) const
{
FixedArray<Sample> samples = LOADER_TRY(FixedArray<Sample>::try_create(samples_to_read));
auto stream = LOADER_TRY(Core::Stream::MemoryStream::construct(move(data)));
auto stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(move(data)));
switch (m_sample_format) {
case PcmSampleFormat::Uint8:

View file

@ -309,7 +309,7 @@ void DeflateDecompressor::close()
ErrorOr<ByteBuffer> DeflateDecompressor::decompress_all(ReadonlyBytes bytes)
{
auto memory_stream = TRY(Core::Stream::MemoryStream::construct(bytes));
auto memory_stream = TRY(Core::Stream::FixedMemoryStream::construct(bytes));
DeflateDecompressor deflate_stream { move(memory_stream) };
DuplexMemoryStream output_stream;

View file

@ -153,7 +153,7 @@ Optional<DeprecatedString> GzipDecompressor::describe_header(ReadonlyBytes bytes
ErrorOr<ByteBuffer> GzipDecompressor::decompress_all(ReadonlyBytes bytes)
{
auto memory_stream = TRY(Core::Stream::MemoryStream::construct(bytes));
auto memory_stream = TRY(Core::Stream::FixedMemoryStream::construct(bytes));
auto gzip_stream = make<GzipDecompressor>(move(memory_stream));
DuplexMemoryStream output_stream;

View file

@ -15,16 +15,18 @@
namespace Core::Stream {
class MemoryStream final : public SeekableStream {
/// A stream class that allows for reading/writing on a preallocated memory area
/// using a single read/write head.
class FixedMemoryStream final : public SeekableStream {
public:
static ErrorOr<NonnullOwnPtr<MemoryStream>> construct(Bytes bytes)
static ErrorOr<NonnullOwnPtr<FixedMemoryStream>> construct(Bytes bytes)
{
return adopt_nonnull_own_or_enomem<MemoryStream>(new (nothrow) MemoryStream(bytes));
return adopt_nonnull_own_or_enomem<FixedMemoryStream>(new (nothrow) FixedMemoryStream(bytes));
}
static ErrorOr<NonnullOwnPtr<MemoryStream>> construct(ReadonlyBytes bytes)
static ErrorOr<NonnullOwnPtr<FixedMemoryStream>> construct(ReadonlyBytes bytes)
{
return adopt_nonnull_own_or_enomem<MemoryStream>(new (nothrow) MemoryStream(bytes));
return adopt_nonnull_own_or_enomem<FixedMemoryStream>(new (nothrow) FixedMemoryStream(bytes));
}
virtual bool is_eof() const override { return m_offset >= m_bytes.size(); }
@ -98,12 +100,12 @@ public:
size_t remaining() const { return m_bytes.size() - m_offset; }
protected:
explicit MemoryStream(Bytes bytes)
explicit FixedMemoryStream(Bytes bytes)
: m_bytes(bytes)
{
}
explicit MemoryStream(ReadonlyBytes bytes)
explicit FixedMemoryStream(ReadonlyBytes bytes)
: m_bytes({ const_cast<u8*>(bytes.data()), bytes.size() })
, m_writing_enabled(false)
{

View file

@ -80,7 +80,7 @@ static Optional<ByteBuffer> handle_content_encoding(ByteBuffer const& buf, Depre
} else if (content_encoding == "br") {
dbgln_if(JOB_DEBUG, "Job::handle_content_encoding: buf is brotli compressed!");
auto bufstream_result = Core::Stream::MemoryStream::construct({ buf.data(), buf.size() });
auto bufstream_result = Core::Stream::FixedMemoryStream::construct({ buf.data(), buf.size() });
if (bufstream_result.is_error()) {
dbgln("Job::handle_content_encoding: MemoryStream::construct() failed.");
return {};