AK: Move memory streams from LibCore

This commit is contained in:
Tim Schumacher 2023-01-25 20:19:05 +01:00 committed by Andrew Kaster
parent 11550f582b
commit 093cf428a3
Notes: sideshowbarker 2024-07-17 00:58:49 +09:00
46 changed files with 213 additions and 203 deletions

View File

@ -16,6 +16,7 @@ set(AK_SOURCES
JsonValue.cpp
kmalloc.cpp
LexicalPath.cpp
MemoryStream.cpp
NumberFormat.cpp
Random.cpp
StackInfo.cpp

View File

@ -5,11 +5,12 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/ByteBuffer.h>
#include <AK/FixedArray.h>
#include <AK/MemMem.h>
#include <LibCore/MemoryStream.h>
#include <AK/MemoryStream.h>
namespace Core::Stream {
namespace AK {
FixedMemoryStream::FixedMemoryStream(Bytes bytes)
: m_bytes(bytes)

View File

@ -6,14 +6,11 @@
#pragma once
#include <AK/Error.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/OwnPtr.h>
#include <AK/Span.h>
#include <AK/TypedTransfer.h>
#include <LibCore/Stream.h>
#include <AK/Stream.h>
#include <AK/Vector.h>
namespace Core::Stream {
namespace AK {
/// A stream class that allows for reading/writing on a preallocated memory area
/// using a single read/write head.
@ -49,7 +46,7 @@ private:
/// A stream class that allows for writing to an automatically allocating memory area
/// and reading back the written data afterwards.
class AllocatingMemoryStream final : public AK::Stream {
class AllocatingMemoryStream final : public Stream {
public:
virtual ErrorOr<Bytes> read(Bytes) override;
virtual ErrorOr<size_t> write(ReadonlyBytes) override;
@ -77,3 +74,8 @@ private:
};
}
#if USING_AK_GLOBALLY
using AK::AllocatingMemoryStream;
using AK::FixedMemoryStream;
#endif

View File

@ -25,7 +25,6 @@
#include <LibCore/EventLoop.h>
#include <LibCore/File.h>
#include <LibCore/IODevice.h>
#include <LibCore/MemoryStream.h>
#include <LibCore/Stream.h>
#include <LibCore/System.h>
#include <LibCore/Timer.h>

View File

@ -4,13 +4,13 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/MemoryStream.h>
#include <LibCompress/Brotli.h>
#include <LibCore/MemoryStream.h>
#include <stdio.h>
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
{
auto bufstream_result = Core::Stream::FixedMemoryStream::construct({ data, size });
auto bufstream_result = FixedMemoryStream::construct({ data, size });
if (bufstream_result.is_error()) {
dbgln("MemoryStream::construct() failed.");
return 0;

View File

@ -4,15 +4,15 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/MemoryStream.h>
#include <AK/NonnullOwnPtr.h>
#include <LibArchive/TarStream.h>
#include <LibCore/MemoryStream.h>
#include <LibCore/Stream.h>
#include <stdio.h>
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
{
auto input_stream_or_error = Core::Stream::FixedMemoryStream::construct({ data, size });
auto input_stream_or_error = FixedMemoryStream::construct({ data, size });
if (input_stream_or_error.is_error())
return 0;

View File

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibCore/MemoryStream.h>
#include <AK/MemoryStream.h>
#include <LibWasm/Types.h>
#include <stddef.h>
#include <stdint.h>
@ -12,7 +12,7 @@
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
{
ReadonlyBytes bytes { data, size };
auto stream_or_error = Core::Stream::FixedMemoryStream::construct(bytes);
auto stream_or_error = FixedMemoryStream::construct(bytes);
if (stream_or_error.is_error())
return 0;
auto stream = stream_or_error.release_value();

View File

@ -586,7 +586,7 @@ public:
static ErrorOr<NonnullOwnPtr<IPC::Message>> decode_message(ReadonlyBytes buffer, [[maybe_unused]] Core::Stream::LocalSocket& socket)
{
auto stream = TRY(Core::Stream::FixedMemoryStream::construct(buffer));
auto stream = TRY(FixedMemoryStream::construct(buffer));
auto message_endpoint_magic = TRY(stream->read_value<u32>());)~~~");
generator.append(R"~~~(
@ -768,10 +768,10 @@ void build(StringBuilder& builder, Vector<Endpoint> const& endpoints)
}
generator.appendln(R"~~~(#include <AK/Error.h>
#include <AK/MemoryStream.h>
#include <AK/OwnPtr.h>
#include <AK/Result.h>
#include <AK/Utf8View.h>
#include <LibCore/MemoryStream.h>
#include <LibIPC/Connection.h>
#include <LibIPC/Decoder.h>
#include <LibIPC/Dictionary.h>

View File

@ -50,6 +50,7 @@ set(AK_TEST_SOURCES
TestLexicalPath.cpp
TestMACAddress.cpp
TestMemory.cpp
TestMemoryStream.cpp
TestNeverDestroyed.cpp
TestNonnullRefPtr.cpp
TestNumberFormat.cpp

View File

@ -5,13 +5,13 @@
*/
#include <AK/BitStream.h>
#include <LibCore/MemoryStream.h>
#include <AK/MemoryStream.h>
#include <LibTest/TestCase.h>
// Note: This does not do any checks on the internal representation, it just ensures that the behavior of the input and output streams match.
TEST_CASE(little_endian_bit_stream_input_output_match)
{
auto memory_stream = make<Core::Stream::AllocatingMemoryStream>();
auto memory_stream = make<AllocatingMemoryStream>();
// Note: The bit stream only ever reads from/writes to the underlying stream in one byte chunks,
// so testing with sizes that will not trigger a write will yield unexpected results.
@ -67,7 +67,7 @@ TEST_CASE(little_endian_bit_stream_input_output_match)
// Note: This does not do any checks on the internal representation, it just ensures that the behavior of the input and output streams match.
TEST_CASE(big_endian_bit_stream_input_output_match)
{
auto memory_stream = make<Core::Stream::AllocatingMemoryStream>();
auto memory_stream = make<AllocatingMemoryStream>();
// Note: The bit stream only ever reads from/writes to the underlying stream in one byte chunks,
// so testing with sizes that will not trigger a write will yield unexpected results.

View File

@ -0,0 +1,94 @@
/*
* Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/MemoryStream.h>
#include <AK/String.h>
#include <LibCore/Stream.h>
#include <LibTest/TestCase.h>
TEST_CASE(allocating_memory_stream_empty)
{
AllocatingMemoryStream stream;
EXPECT_EQ(stream.used_buffer_size(), 0ul);
{
Array<u8, 32> array;
auto read_bytes = MUST(stream.read(array));
EXPECT_EQ(read_bytes.size(), 0ul);
}
{
auto offset = MUST(stream.offset_of("test"sv.bytes()));
EXPECT(!offset.has_value());
}
}
TEST_CASE(allocating_memory_stream_offset_of)
{
AllocatingMemoryStream stream;
MUST(stream.write_entire_buffer("Well Hello Friends! :^)"sv.bytes()));
{
auto offset = MUST(stream.offset_of(" "sv.bytes()));
EXPECT(offset.has_value());
EXPECT_EQ(offset.value(), 4ul);
}
{
auto offset = MUST(stream.offset_of("W"sv.bytes()));
EXPECT(offset.has_value());
EXPECT_EQ(offset.value(), 0ul);
}
{
auto offset = MUST(stream.offset_of(")"sv.bytes()));
EXPECT(offset.has_value());
EXPECT_EQ(offset.value(), 22ul);
}
{
auto offset = MUST(stream.offset_of("-"sv.bytes()));
EXPECT(!offset.has_value());
}
MUST(stream.discard(1));
{
auto offset = MUST(stream.offset_of("W"sv.bytes()));
EXPECT(!offset.has_value());
}
{
auto offset = MUST(stream.offset_of("e"sv.bytes()));
EXPECT(offset.has_value());
EXPECT_EQ(offset.value(), 0ul);
}
}
TEST_CASE(allocating_memory_stream_offset_of_oob)
{
AllocatingMemoryStream stream;
// NOTE: This test is to make sure that offset_of() doesn't read past the end of the "initialized" data.
// So we have to assume some things about the behaviour of this class:
// - The chunk size is 4096 bytes.
// - A chunk is moved to the end when it's fully read from
// - A free chunk is used as-is, no new ones are allocated if one exists.
// First, fill exactly one chunk.
for (size_t i = 0; i < 256; ++i)
MUST(stream.write_entire_buffer("AAAAAAAAAAAAAAAA"sv.bytes()));
// Then discard it all.
MUST(stream.discard(4096));
// Now we can write into this chunk again, knowing that it's initialized to all 'A's.
MUST(stream.write_entire_buffer("Well Hello Friends! :^)"sv.bytes()));
{
auto offset = MUST(stream.offset_of("A"sv.bytes()));
EXPECT(!offset.has_value());
}
}

View File

@ -8,9 +8,9 @@
#include <AK/Array.h>
#include <AK/BitStream.h>
#include <AK/MemoryStream.h>
#include <AK/Random.h>
#include <LibCompress/Deflate.h>
#include <LibCore/MemoryStream.h>
#include <cstring>
TEST_CASE(canonical_code_simple)
@ -28,7 +28,7 @@ TEST_CASE(canonical_code_simple)
};
auto const huffman = Compress::CanonicalCode::from_bytes(code).value();
auto memory_stream = MUST(Core::Stream::FixedMemoryStream::construct(input));
auto memory_stream = MUST(FixedMemoryStream::construct(input));
auto bit_stream = MUST(LittleEndianInputBitStream::construct(move(memory_stream)));
for (size_t idx = 0; idx < 9; ++idx)
@ -48,7 +48,7 @@ TEST_CASE(canonical_code_complex)
};
auto const huffman = Compress::CanonicalCode::from_bytes(code).value();
auto memory_stream = MUST(Core::Stream::FixedMemoryStream::construct(input));
auto memory_stream = MUST(FixedMemoryStream::construct(input));
auto bit_stream = MUST(LittleEndianInputBitStream::construct(move(memory_stream)));
for (size_t idx = 0; idx < 12; ++idx)

View File

@ -9,7 +9,6 @@
#include <AK/String.h>
#include <LibCore/EventLoop.h>
#include <LibCore/LocalServer.h>
#include <LibCore/MemoryStream.h>
#include <LibCore/Stream.h>
#include <LibCore/TCPServer.h>
#include <LibCore/Timer.h>
@ -594,89 +593,3 @@ TEST_CASE(buffered_tcp_socket_read)
auto second_received_line = maybe_second_received_line.value();
EXPECT_EQ(second_received_line, second_line);
}
// Allocating memory stream tests
TEST_CASE(allocating_memory_stream_empty)
{
Core::Stream::AllocatingMemoryStream stream;
EXPECT_EQ(stream.used_buffer_size(), 0ul);
{
Array<u8, 32> array;
auto read_bytes = MUST(stream.read(array));
EXPECT_EQ(read_bytes.size(), 0ul);
}
{
auto offset = MUST(stream.offset_of("test"sv.bytes()));
EXPECT(!offset.has_value());
}
}
TEST_CASE(allocating_memory_stream_offset_of)
{
Core::Stream::AllocatingMemoryStream stream;
MUST(stream.write_entire_buffer("Well Hello Friends! :^)"sv.bytes()));
{
auto offset = MUST(stream.offset_of(" "sv.bytes()));
EXPECT(offset.has_value());
EXPECT_EQ(offset.value(), 4ul);
}
{
auto offset = MUST(stream.offset_of("W"sv.bytes()));
EXPECT(offset.has_value());
EXPECT_EQ(offset.value(), 0ul);
}
{
auto offset = MUST(stream.offset_of(")"sv.bytes()));
EXPECT(offset.has_value());
EXPECT_EQ(offset.value(), 22ul);
}
{
auto offset = MUST(stream.offset_of("-"sv.bytes()));
EXPECT(!offset.has_value());
}
MUST(stream.discard(1));
{
auto offset = MUST(stream.offset_of("W"sv.bytes()));
EXPECT(!offset.has_value());
}
{
auto offset = MUST(stream.offset_of("e"sv.bytes()));
EXPECT(offset.has_value());
EXPECT_EQ(offset.value(), 0ul);
}
}
TEST_CASE(allocating_memory_stream_offset_of_oob)
{
Core::Stream::AllocatingMemoryStream stream;
// NOTE: This test is to make sure that offset_of() doesn't read past the end of the "initialized" data.
// So we have to assume some things about the behaviour of this class:
// - The chunk size is 4096 bytes.
// - A chunk is moved to the end when it's fully read from
// - A free chunk is used as-is, no new ones are allocated if one exists.
// First, fill exactly one chunk.
for (size_t i = 0; i < 256; ++i)
MUST(stream.write_entire_buffer("AAAAAAAAAAAAAAAA"sv.bytes()));
// Then discard it all.
MUST(stream.discard(4096));
// Now we can write into this chunk again, knowing that it's initialized to all 'A's.
MUST(stream.write_entire_buffer("Well Hello Friends! :^)"sv.bytes()));
{
auto offset = MUST(stream.offset_of("A"sv.bytes()));
EXPECT(!offset.has_value());
}
}

View File

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibCore/MemoryStream.h>
#include <AK/MemoryStream.h>
#include <LibCore/Stream.h>
#include <LibTest/JavaScriptTestRunner.h>
#include <LibWasm/AbstractMachine/BytecodeInterpreter.h>
@ -106,7 +106,7 @@ TESTJS_GLOBAL_FUNCTION(parse_webassembly_module, parseWebAssemblyModule)
if (!is<JS::Uint8Array>(object))
return vm.throw_completion<JS::TypeError>("Expected a Uint8Array argument to parse_webassembly_module");
auto& array = static_cast<JS::Uint8Array&>(*object);
auto stream = Core::Stream::FixedMemoryStream::construct(array.data()).release_value_but_fixme_should_propagate_errors();
auto stream = FixedMemoryStream::construct(array.data()).release_value_but_fixme_should_propagate_errors();
auto result = Wasm::Module::parse(*stream);
if (result.is_error())
return vm.throw_completion<JS::SyntaxError>(Wasm::parse_error_to_deprecated_string(result.error()));

View File

@ -10,8 +10,8 @@
#include <AK/DeprecatedString.h>
#include <AK/JsonArray.h>
#include <AK/LexicalPath.h>
#include <AK/MemoryStream.h>
#include <Applications/Spreadsheet/CSVExportGML.h>
#include <LibCore/MemoryStream.h>
#include <LibCore/StandardPaths.h>
#include <LibGUI/Application.h>
#include <LibGUI/CheckBox.h>
@ -167,7 +167,7 @@ auto CSVExportDialogPage::generate(AK::Stream& stream, GenerationType type) -> E
void CSVExportDialogPage::update_preview()
{
auto maybe_error = [this]() -> ErrorOr<void> {
Core::Stream::AllocatingMemoryStream memory_stream;
AllocatingMemoryStream memory_stream;
TRY(generate(memory_stream, GenerationType::Preview));
auto buffer = TRY(memory_stream.read_until_eof());
m_data_preview_text_editor->set_text(StringView(buffer));

View File

@ -7,7 +7,7 @@
#include <LibTest/TestCase.h>
#include "../CSV.h"
#include <LibCore/MemoryStream.h>
#include <AK/MemoryStream.h>
TEST_CASE(can_write)
{
@ -17,7 +17,7 @@ TEST_CASE(can_write)
{ 7, 8, 9 },
};
Core::Stream::AllocatingMemoryStream stream;
AllocatingMemoryStream stream;
MUST(Writer::CSV::generate(stream, data));
auto expected_output = R"~(1,2,3
@ -37,7 +37,7 @@ TEST_CASE(can_write_with_header)
{ 7, 8, 9 },
};
Core::Stream::AllocatingMemoryStream stream;
AllocatingMemoryStream stream;
MUST(Writer::CSV::generate(stream, data, { "A"sv, "B\""sv, "C"sv }));
auto expected_output = R"~(A,"B""",C
@ -57,7 +57,7 @@ TEST_CASE(can_write_with_different_behaviors)
{ "We\"ll", "Hello,", " Friends" },
};
Core::Stream::AllocatingMemoryStream stream;
AllocatingMemoryStream stream;
MUST(Writer::CSV::generate(stream, data, { "A"sv, "B\""sv, "C"sv }, Writer::WriterBehavior::QuoteOnlyInFieldStart | Writer::WriterBehavior::WriteHeaders));
auto expected_output = R"~(A,B",C

View File

@ -11,6 +11,7 @@
#include <AK/Format.h>
#include <AK/IntegralMath.h>
#include <AK/Math.h>
#include <AK/MemoryStream.h>
#include <AK/ScopeGuard.h>
#include <AK/StdLibExtras.h>
#include <AK/Try.h>
@ -20,7 +21,6 @@
#include <LibAudio/FlacTypes.h>
#include <LibAudio/LoaderError.h>
#include <LibAudio/Resampler.h>
#include <LibCore/MemoryStream.h>
#include <LibCore/Stream.h>
namespace Audio {
@ -42,7 +42,7 @@ Result<NonnullOwnPtr<FlacLoaderPlugin>, LoaderError> FlacLoaderPlugin::create(St
Result<NonnullOwnPtr<FlacLoaderPlugin>, LoaderError> FlacLoaderPlugin::create(Bytes buffer)
{
auto stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(buffer));
auto stream = LOADER_TRY(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::FixedMemoryStream::construct(streaminfo.data.bytes()));
auto streaminfo_data_memory = LOADER_TRY(FixedMemoryStream::construct(streaminfo.data.bytes()));
auto streaminfo_data = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<AK::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::FixedMemoryStream::construct(block.data.bytes()));
auto memory_stream = LOADER_TRY(FixedMemoryStream::construct(block.data.bytes()));
auto picture_block_bytes = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<AK::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::FixedMemoryStream::construct(block.data.bytes()));
auto memory_stream = LOADER_TRY(FixedMemoryStream::construct(block.data.bytes()));
auto seektable_bytes = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<AK::Stream>(*memory_stream)));
for (size_t i = 0; i < block.length / 18; ++i) {
// 11.14. SEEKPOINT

View File

@ -12,7 +12,6 @@
#include <AK/Error.h>
#include <AK/Span.h>
#include <AK/Types.h>
#include <LibCore/MemoryStream.h>
#include <LibCore/Stream.h>
namespace Audio {

View File

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

View File

@ -9,8 +9,8 @@
#include "Loader.h"
#include "MP3Types.h"
#include <AK/BitStream.h>
#include <AK/MemoryStream.h>
#include <AK/Tuple.h>
#include <LibCore/MemoryStream.h>
#include <LibCore/Stream.h>
#include <LibDSP/MDCT.h>
@ -73,7 +73,7 @@ private:
AK::Optional<MP3::MP3Frame> m_current_frame;
u32 m_current_frame_read;
OwnPtr<BigEndianInputBitStream> m_bitstream;
Core::Stream::AllocatingMemoryStream m_bit_reservoir;
AllocatingMemoryStream m_bit_reservoir;
};
}

View File

@ -10,9 +10,9 @@
#include <AK/Debug.h>
#include <AK/Endian.h>
#include <AK/FixedArray.h>
#include <AK/MemoryStream.h>
#include <AK/NumericLimits.h>
#include <AK/Try.h>
#include <LibCore/MemoryStream.h>
namespace Audio {
@ -35,7 +35,7 @@ Result<NonnullOwnPtr<WavLoaderPlugin>, LoaderError> WavLoaderPlugin::create(Stri
Result<NonnullOwnPtr<WavLoaderPlugin>, LoaderError> WavLoaderPlugin::create(Bytes buffer)
{
auto stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(buffer));
auto stream = LOADER_TRY(FixedMemoryStream::construct(buffer));
auto loader = make<WavLoaderPlugin>(move(stream));
LOADER_TRY(loader->initialize());
@ -115,7 +115,7 @@ static ErrorOr<double> read_sample(AK::Stream& stream)
LoaderSamples WavLoaderPlugin::samples_from_pcm_data(Bytes const& data, size_t samples_to_read) const
{
FixedArray<Sample> samples = LOADER_TRY(FixedArray<Sample>::create(samples_to_read));
auto stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(move(data)));
auto stream = LOADER_TRY(FixedMemoryStream::construct(move(data)));
switch (m_sample_format) {
case PcmSampleFormat::Uint8:

View File

@ -10,7 +10,7 @@
#include <AK/BinaryHeap.h>
#include <AK/BinarySearch.h>
#include <AK/BitStream.h>
#include <LibCore/MemoryStream.h>
#include <AK/MemoryStream.h>
#include <string.h>
#include <LibCompress/Deflate.h>
@ -317,9 +317,9 @@ void DeflateDecompressor::close()
ErrorOr<ByteBuffer> DeflateDecompressor::decompress_all(ReadonlyBytes bytes)
{
auto memory_stream = TRY(Core::Stream::FixedMemoryStream::construct(bytes));
auto memory_stream = TRY(FixedMemoryStream::construct(bytes));
auto deflate_stream = TRY(DeflateDecompressor::construct(move(memory_stream)));
Core::Stream::AllocatingMemoryStream output_stream;
AllocatingMemoryStream output_stream;
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
while (!deflate_stream->is_eof()) {
@ -1017,7 +1017,7 @@ ErrorOr<void> DeflateCompressor::final_flush()
ErrorOr<ByteBuffer> DeflateCompressor::compress_all(ReadonlyBytes bytes, CompressionLevel compression_level)
{
auto output_stream = TRY(try_make<Core::Stream::AllocatingMemoryStream>());
auto output_stream = TRY(try_make<AllocatingMemoryStream>());
auto deflate_stream = TRY(DeflateCompressor::construct(MaybeOwned<AK::Stream>(*output_stream), compression_level));
TRY(deflate_stream->write_entire_buffer(bytes));

View File

@ -8,8 +8,8 @@
#include <LibCompress/Gzip.h>
#include <AK/DeprecatedString.h>
#include <AK/MemoryStream.h>
#include <LibCore/DateTime.h>
#include <LibCore/MemoryStream.h>
namespace Compress {
@ -164,9 +164,9 @@ Optional<DeprecatedString> GzipDecompressor::describe_header(ReadonlyBytes bytes
ErrorOr<ByteBuffer> GzipDecompressor::decompress_all(ReadonlyBytes bytes)
{
auto memory_stream = TRY(Core::Stream::FixedMemoryStream::construct(bytes));
auto memory_stream = TRY(FixedMemoryStream::construct(bytes));
auto gzip_stream = make<GzipDecompressor>(move(memory_stream));
Core::Stream::AllocatingMemoryStream output_stream;
AllocatingMemoryStream output_stream;
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
while (!gzip_stream->is_eof()) {
@ -235,7 +235,7 @@ void GzipCompressor::close()
ErrorOr<ByteBuffer> GzipCompressor::compress_all(ReadonlyBytes bytes)
{
auto output_stream = TRY(try_make<Core::Stream::AllocatingMemoryStream>());
auto output_stream = TRY(try_make<AllocatingMemoryStream>());
GzipCompressor gzip_stream { MaybeOwned<AK::Stream>(*output_stream) };
TRY(gzip_stream.write_entire_buffer(bytes));

View File

@ -5,12 +5,12 @@
*/
#include <AK/IntegralMath.h>
#include <AK/MemoryStream.h>
#include <AK/Span.h>
#include <AK/TypeCasts.h>
#include <AK/Types.h>
#include <LibCompress/Deflate.h>
#include <LibCompress/Zlib.h>
#include <LibCore/MemoryStream.h>
namespace Compress {
@ -163,7 +163,7 @@ ErrorOr<void> ZlibCompressor::finish()
ErrorOr<ByteBuffer> ZlibCompressor::compress_all(ReadonlyBytes bytes, ZlibCompressionLevel compression_level)
{
auto output_stream = TRY(try_make<Core::Stream::AllocatingMemoryStream>());
auto output_stream = TRY(try_make<AllocatingMemoryStream>());
auto zlib_stream = TRY(ZlibCompressor::construct(MaybeOwned<AK::Stream>(*output_stream), compression_level));
TRY(zlib_stream->write_entire_buffer(bytes));

View File

@ -13,7 +13,6 @@ set(SOURCES
IODevice.cpp
LockFile.cpp
MappedFile.cpp
MemoryStream.cpp
MimeData.cpp
NetworkJob.cpp
Notifier.cpp

View File

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibCore/MemoryStream.h>
#include <AK/MemoryStream.h>
#include <LibCore/SOCKSProxyClient.h>
enum class Method : u8 {
@ -122,7 +122,7 @@ ErrorOr<void> send_version_identifier_and_method_selection_message(Core::Stream:
ErrorOr<Reply> send_connect_request_message(Core::Stream::Socket& socket, Core::SOCKSProxyClient::Version version, Core::SOCKSProxyClient::HostOrIPV4 target, int port, Core::SOCKSProxyClient::Command command)
{
Core::Stream::AllocatingMemoryStream stream;
AllocatingMemoryStream stream;
Socks5ConnectRequestHeader header {
.version_identifier = to_underlying(version),
@ -218,7 +218,7 @@ ErrorOr<Reply> send_connect_request_message(Core::Stream::Socket& socket, Core::
ErrorOr<u8> send_username_password_authentication_message(Core::Stream::Socket& socket, Core::SOCKSProxyClient::UsernamePasswordAuthenticationData const& auth_data)
{
Core::Stream::AllocatingMemoryStream stream;
AllocatingMemoryStream stream;
u8 version = 0x01;
auto size = TRY(stream.write({ &version, sizeof(version) }));

View File

@ -9,8 +9,8 @@
#include "Name.h"
#include "PacketHeader.h"
#include <AK/Debug.h>
#include <AK/MemoryStream.h>
#include <AK/StringBuilder.h>
#include <LibCore/MemoryStream.h>
#include <arpa/inet.h>
namespace DNS {
@ -48,7 +48,7 @@ ErrorOr<ByteBuffer> Packet::to_byte_buffer() const
header.set_question_count(m_questions.size());
header.set_answer_count(m_answers.size());
Core::Stream::AllocatingMemoryStream stream;
AllocatingMemoryStream stream;
TRY(stream.write_value(header));
for (auto& question : m_questions) {

View File

@ -8,7 +8,7 @@
#include "DwarfInfo.h"
#include <AK/LEB128.h>
#include <LibCore/MemoryStream.h>
#include <AK/MemoryStream.h>
namespace Debug::Dwarf {
@ -21,7 +21,7 @@ AbbreviationsMap::AbbreviationsMap(DwarfInfo const& dwarf_info, u32 offset)
ErrorOr<void> AbbreviationsMap::populate_map()
{
auto abbreviation_stream = TRY(Core::Stream::FixedMemoryStream::construct(m_dwarf_info.abbreviation_data()));
auto abbreviation_stream = TRY(FixedMemoryStream::construct(m_dwarf_info.abbreviation_data()));
TRY(abbreviation_stream->discard(m_offset));
Core::Stream::WrapInAKInputStream wrapped_abbreviation_stream { *abbreviation_stream };

View File

@ -9,7 +9,7 @@
#include "DwarfInfo.h"
#include <AK/ByteBuffer.h>
#include <AK/LEB128.h>
#include <LibCore/MemoryStream.h>
#include <AK/MemoryStream.h>
namespace Debug::Dwarf {
@ -23,7 +23,7 @@ ErrorOr<void> DIE::rehydrate_from(u32 offset, Optional<u32> parent_offset)
{
m_offset = offset;
auto stream = TRY(Core::Stream::FixedMemoryStream::construct(m_compilation_unit.dwarf_info().debug_info_data()));
auto stream = TRY(FixedMemoryStream::construct(m_compilation_unit.dwarf_info().debug_info_data()));
// Note: We can't just slice away from the input data here, since get_attribute_value will try to recover the original offset using seek().
TRY(stream->seek(m_offset));
Core::Stream::WrapInAKInputStream wrapped_stream { *stream };
@ -52,7 +52,7 @@ ErrorOr<void> DIE::rehydrate_from(u32 offset, Optional<u32> parent_offset)
ErrorOr<Optional<AttributeValue>> DIE::get_attribute(Attribute const& attribute) const
{
auto stream = TRY(Core::Stream::FixedMemoryStream::construct(m_compilation_unit.dwarf_info().debug_info_data()));
auto stream = TRY(FixedMemoryStream::construct(m_compilation_unit.dwarf_info().debug_info_data()));
// Note: We can't just slice away from the input data here, since get_attribute_value will try to recover the original offset using seek().
TRY(stream->seek(m_data_offset));

View File

@ -11,7 +11,7 @@
#include <AK/ByteReader.h>
#include <AK/LEB128.h>
#include <LibCore/MemoryStream.h>
#include <AK/MemoryStream.h>
#include <LibDebug/DebugInfo.h>
namespace Debug::Dwarf {
@ -47,8 +47,8 @@ ErrorOr<void> DwarfInfo::populate_compilation_units()
if (!m_debug_info_data.data())
return {};
auto debug_info_stream = TRY(Core::Stream::FixedMemoryStream::construct(m_debug_info_data));
auto line_info_stream = TRY(Core::Stream::FixedMemoryStream::construct(m_debug_line_data));
auto debug_info_stream = TRY(FixedMemoryStream::construct(m_debug_info_data));
auto line_info_stream = TRY(FixedMemoryStream::construct(m_debug_line_data));
while (!debug_info_stream->is_eof()) {
auto unit_offset = TRY(debug_info_stream->tell());
@ -321,14 +321,14 @@ ErrorOr<void> DwarfInfo::build_cached_dies() const
Vector<DIERange> entries;
if (die.compilation_unit().dwarf_version() == 5) {
auto range_lists_stream = TRY(Core::Stream::FixedMemoryStream::construct(debug_range_lists_data()));
auto range_lists_stream = TRY(FixedMemoryStream::construct(debug_range_lists_data()));
TRY(range_lists_stream->seek(offset));
AddressRangesV5 address_ranges(move(range_lists_stream), die.compilation_unit());
TRY(address_ranges.for_each_range([&entries](auto range) {
entries.empend(range.start, range.end);
}));
} else {
auto ranges_stream = TRY(Core::Stream::FixedMemoryStream::construct(debug_ranges_data()));
auto ranges_stream = TRY(FixedMemoryStream::construct(debug_ranges_data()));
TRY(ranges_stream->seek(offset));
AddressRangesV4 address_ranges(move(ranges_stream), die.compilation_unit());
TRY(address_ranges.for_each_range([&entries](auto range) {

View File

@ -7,14 +7,14 @@
#include "Expression.h"
#include <AK/Format.h>
#include <LibCore/MemoryStream.h>
#include <AK/MemoryStream.h>
#include <sys/arch/regs.h>
namespace Debug::Dwarf::Expression {
ErrorOr<Value> evaluate(ReadonlyBytes bytes, [[maybe_unused]] PtraceRegisters const& regs)
{
auto stream = TRY(Core::Stream::FixedMemoryStream::construct(bytes));
auto stream = TRY(FixedMemoryStream::construct(bytes));
while (!stream->is_eof()) {
auto opcode = TRY(stream->read_value<u8>());

View File

@ -11,9 +11,9 @@
#include <AK/Error.h>
#include <AK/IntegralMath.h>
#include <AK/Memory.h>
#include <AK/MemoryStream.h>
#include <AK/NonnullOwnPtrVector.h>
#include <AK/Try.h>
#include <LibCore/MemoryStream.h>
#include <LibGfx/GIFLoader.h>
#include <string.h>
@ -381,7 +381,7 @@ static ErrorOr<void> load_gif_frame_descriptors(GIFLoadingContext& context)
if (context.data_size < 32)
return Error::from_string_literal("Size too short for GIF frame descriptors");
auto stream = TRY(Core::Stream::FixedMemoryStream::construct(ReadonlyBytes { context.data, context.data_size }));
auto stream = TRY(FixedMemoryStream::construct(ReadonlyBytes { context.data, context.data_size }));
TRY(decode_gif_header(*stream));
@ -565,7 +565,7 @@ bool GIFImageDecoderPlugin::set_nonvolatile(bool& was_purged)
bool GIFImageDecoderPlugin::initialize()
{
auto stream_or_error = Core::Stream::FixedMemoryStream::construct(ReadonlyBytes { m_context->data, m_context->data_size });
auto stream_or_error = FixedMemoryStream::construct(ReadonlyBytes { m_context->data, m_context->data_size });
if (stream_or_error.is_error())
return false;
return !decode_gif_header(*stream_or_error.value()).is_error();
@ -573,7 +573,7 @@ bool GIFImageDecoderPlugin::initialize()
ErrorOr<bool> GIFImageDecoderPlugin::sniff(ReadonlyBytes data)
{
auto stream = TRY(Core::Stream::FixedMemoryStream::construct(data));
auto stream = TRY(FixedMemoryStream::construct(data));
return !decode_gif_header(*stream).is_error();
}

View File

@ -5,14 +5,15 @@
*/
#include <AK/Debug.h>
#include <AK/Endian.h>
#include <AK/Error.h>
#include <AK/FixedArray.h>
#include <AK/HashMap.h>
#include <AK/Math.h>
#include <AK/MemoryStream.h>
#include <AK/String.h>
#include <AK/Try.h>
#include <AK/Vector.h>
#include <LibCore/MemoryStream.h>
#include <LibGfx/JPGLoader.h>
#define JPG_INVALID 0X0000
@ -198,7 +199,7 @@ struct JPGLoadingContext {
HuffmanStreamState huffman_stream;
i32 previous_dc_values[3] = { 0 };
MacroblockMeta mblock_meta;
OwnPtr<Core::Stream::FixedMemoryStream> stream;
OwnPtr<FixedMemoryStream> stream;
Optional<ICCMultiChunkState> icc_multi_chunk_state;
Optional<ByteBuffer> icc_data;
@ -1201,7 +1202,7 @@ static ErrorOr<void> scan_huffman_stream(AK::SeekableStream& stream, JPGLoadingC
static ErrorOr<void> decode_header(JPGLoadingContext& context)
{
if (context.state < JPGLoadingContext::State::HeaderDecoded) {
context.stream = TRY(Core::Stream::FixedMemoryStream::construct({ context.data, context.data_size }));
context.stream = TRY(FixedMemoryStream::construct({ context.data, context.data_size }));
if (auto result = parse_header(*context.stream, context); result.is_error()) {
context.state = JPGLoadingContext::State::Error;

View File

@ -5,7 +5,7 @@
*/
#include <AK/Endian.h>
#include <LibCore/MemoryStream.h>
#include <AK/MemoryStream.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/QOILoader.h>
@ -202,13 +202,13 @@ bool QOIImageDecoderPlugin::initialize()
ErrorOr<bool> QOIImageDecoderPlugin::sniff(ReadonlyBytes data)
{
auto stream = TRY(Core::Stream::FixedMemoryStream::construct({ data.data(), data.size() }));
auto stream = TRY(FixedMemoryStream::construct({ data.data(), data.size() }));
return !decode_qoi_header(*stream).is_error();
}
ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> QOIImageDecoderPlugin::create(ReadonlyBytes data)
{
auto stream = TRY(Core::Stream::FixedMemoryStream::construct(data));
auto stream = TRY(FixedMemoryStream::construct(data));
return adopt_nonnull_own_or_enomem(new (nothrow) QOIImageDecoderPlugin(move(stream)));
}

View File

@ -8,12 +8,12 @@
#include <AK/CharacterTypes.h>
#include <AK/Debug.h>
#include <AK/JsonObject.h>
#include <AK/MemoryStream.h>
#include <AK/Try.h>
#include <LibCompress/Brotli.h>
#include <LibCompress/Gzip.h>
#include <LibCompress/Zlib.h>
#include <LibCore/Event.h>
#include <LibCore/MemoryStream.h>
#include <LibHTTP/HttpResponse.h>
#include <LibHTTP/Job.h>
#include <stdio.h>
@ -70,7 +70,7 @@ static ErrorOr<ByteBuffer> handle_content_encoding(ByteBuffer const& buf, Deprec
} else if (content_encoding == "br") {
dbgln_if(JOB_DEBUG, "Job::handle_content_encoding: buf is brotli compressed!");
auto bufstream = TRY(Core::Stream::FixedMemoryStream::construct({ buf.data(), buf.size() }));
auto bufstream = TRY(FixedMemoryStream::construct({ buf.data(), buf.size() }));
auto brotli_stream = Compress::BrotliDecompressionStream { *bufstream };
auto uncompressed = TRY(brotli_stream.read_until_eof());

View File

@ -10,6 +10,7 @@
#include <AK/Debug.h>
#include <AK/GenericLexer.h>
#include <AK/JsonObject.h>
#include <AK/MemoryStream.h>
#include <AK/RedBlackTree.h>
#include <AK/ScopeGuard.h>
#include <AK/ScopedValueRollback.h>
@ -20,7 +21,6 @@
#include <LibCore/Event.h>
#include <LibCore/EventLoop.h>
#include <LibCore/File.h>
#include <LibCore/MemoryStream.h>
#include <LibCore/Notifier.h>
#include <errno.h>
#include <fcntl.h>
@ -1329,7 +1329,7 @@ ErrorOr<void> Editor::cleanup()
ErrorOr<void> Editor::refresh_display()
{
Core::Stream::AllocatingMemoryStream output_stream;
AllocatingMemoryStream output_stream;
ScopeGuard flush_stream {
[&] {
m_shown_lines = current_prompt_metrics().lines_with_addition(m_cached_buffer_metrics, m_num_columns);

View File

@ -6,8 +6,9 @@
*/
#include <AK/BitStream.h>
#include <AK/Endian.h>
#include <AK/MemoryStream.h>
#include <AK/Tuple.h>
#include <LibCore/MemoryStream.h>
#include <LibPDF/CommonNames.h>
#include <LibPDF/Document.h>
#include <LibPDF/DocumentParser.h>
@ -595,7 +596,7 @@ PDFErrorOr<DocumentParser::PageOffsetHintTable> DocumentParser::parse_page_offse
PDFErrorOr<Vector<DocumentParser::PageOffsetHintTableEntry>> DocumentParser::parse_all_page_offset_hint_table_entries(PageOffsetHintTable const& hint_table, ReadonlyBytes hint_stream_bytes)
{
auto input_stream = TRY(Core::Stream::FixedMemoryStream::construct(hint_stream_bytes));
auto input_stream = TRY(FixedMemoryStream::construct(hint_stream_bytes));
TRY(input_stream->seek(sizeof(PageOffsetHintTable)));
auto bit_stream = TRY(LittleEndianInputBitStream::construct(move(input_stream)));

View File

@ -10,9 +10,9 @@
#include <AK/ByteBuffer.h>
#include <AK/DeprecatedString.h>
#include <AK/Function.h>
#include <AK/MemoryStream.h>
#include <AK/RefCounted.h>
#include <AK/WeakPtr.h>
#include <LibCore/MemoryStream.h>
#include <LibCore/Notifier.h>
#include <LibCore/Stream.h>
#include <LibIPC/Forward.h>
@ -68,7 +68,7 @@ private:
bool m_should_buffer_all_input { false };
struct InternalBufferedData {
Core::Stream::AllocatingMemoryStream payload_stream;
AllocatingMemoryStream payload_stream;
HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> response_headers;
Optional<u32> response_code;
};

View File

@ -6,7 +6,7 @@
*/
#include <AK/Debug.h>
#include <LibCore/MemoryStream.h>
#include <AK/MemoryStream.h>
#include <LibWasm/AbstractMachine/AbstractMachine.h>
#include <LibWasm/AbstractMachine/BytecodeInterpreter.h>
#include <LibWasm/AbstractMachine/Configuration.h>
@ -203,7 +203,7 @@ struct ConvertToRaw<float> {
{
LittleEndian<u32> res;
ReadonlyBytes bytes { &value, sizeof(float) };
auto stream = Core::Stream::FixedMemoryStream::construct(bytes).release_value_but_fixme_should_propagate_errors();
auto stream = FixedMemoryStream::construct(bytes).release_value_but_fixme_should_propagate_errors();
stream->read_entire_buffer(res.bytes()).release_value_but_fixme_should_propagate_errors();
return static_cast<u32>(res);
}
@ -215,7 +215,7 @@ struct ConvertToRaw<double> {
{
LittleEndian<u64> res;
ReadonlyBytes bytes { &value, sizeof(double) };
auto stream = Core::Stream::FixedMemoryStream::construct(bytes).release_value_but_fixme_should_propagate_errors();
auto stream = FixedMemoryStream::construct(bytes).release_value_but_fixme_should_propagate_errors();
stream->read_entire_buffer(res.bytes()).release_value_but_fixme_should_propagate_errors();
return static_cast<u64>(res);
}
@ -253,7 +253,7 @@ template<typename T>
T BytecodeInterpreter::read_value(ReadonlyBytes data)
{
LittleEndian<T> value;
auto stream = Core::Stream::FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors();
auto stream = FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors();
auto maybe_error = stream->read_entire_buffer(value.bytes());
if (maybe_error.is_error()) {
dbgln("Read from {} failed", data.data());
@ -266,7 +266,7 @@ template<>
float BytecodeInterpreter::read_value<float>(ReadonlyBytes data)
{
LittleEndian<u32> raw_value;
auto stream = Core::Stream::FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors();
auto stream = FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors();
auto maybe_error = stream->read_entire_buffer(raw_value.bytes());
if (maybe_error.is_error())
m_trap = Trap { "Read from memory failed" };
@ -277,7 +277,7 @@ template<>
double BytecodeInterpreter::read_value<double>(ReadonlyBytes data)
{
LittleEndian<u64> raw_value;
auto stream = Core::Stream::FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors();
auto stream = FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors();
auto maybe_error = stream->read_entire_buffer(raw_value.bytes());
if (maybe_error.is_error())
m_trap = Trap { "Read from memory failed" };

View File

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibCore/MemoryStream.h>
#include <AK/MemoryStream.h>
#include <LibWasm/AbstractMachine/Configuration.h>
#include <LibWasm/AbstractMachine/Interpreter.h>
#include <LibWasm/Printer/Printer.h>
@ -86,7 +86,7 @@ Result Configuration::execute(Interpreter& interpreter)
void Configuration::dump_stack()
{
auto print_value = []<typename... Ts>(CheckedFormatString<Ts...> format, Ts... vs) {
Core::Stream::AllocatingMemoryStream memory_stream;
AllocatingMemoryStream memory_stream;
Printer { memory_stream }.print(vs...);
auto buffer = ByteBuffer::create_uninitialized(memory_stream.used_buffer_size()).release_value_but_fixme_should_propagate_errors();
memory_stream.read_entire_buffer(buffer).release_value_but_fixme_should_propagate_errors();

View File

@ -6,9 +6,9 @@
#include <AK/Debug.h>
#include <AK/LEB128.h>
#include <AK/MemoryStream.h>
#include <AK/ScopeGuard.h>
#include <AK/ScopeLogger.h>
#include <LibCore/MemoryStream.h>
#include <LibWasm/Types.h>
namespace Wasm {
@ -261,7 +261,7 @@ ParseResult<BlockType> BlockType::parse(AK::Stream& stream)
return BlockType {};
{
auto value_stream = Core::Stream::FixedMemoryStream::construct(ReadonlyBytes { &kind, 1 }).release_value_but_fixme_should_propagate_errors();
auto value_stream = FixedMemoryStream::construct(ReadonlyBytes { &kind, 1 }).release_value_but_fixme_should_propagate_errors();
if (auto value_type = ValueType::parse(*value_stream); !value_type.is_error())
return BlockType { value_type.release_value() };
}

View File

@ -11,8 +11,8 @@
#include "WebAssemblyModulePrototype.h"
#include "WebAssemblyTableObject.h"
#include "WebAssemblyTablePrototype.h"
#include <AK/MemoryStream.h>
#include <AK/ScopeGuard.h>
#include <LibCore/MemoryStream.h>
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/ArrayBuffer.h>
#include <LibJS/Runtime/BigInt.h>
@ -121,7 +121,7 @@ JS::ThrowCompletionOr<size_t> parse_module(JS::VM& vm, JS::Object* buffer_object
} else {
return vm.throw_completion<JS::TypeError>("Not a BufferSource");
}
auto stream = Core::Stream::FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors();
auto stream = FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors();
auto module_result = Wasm::Module::parse(*stream);
if (module_result.is_error()) {
// FIXME: Throw CompileError instead.

View File

@ -9,6 +9,7 @@
#include <AK/Base64.h>
#include <AK/Debug.h>
#include <AK/LexicalPath.h>
#include <AK/MemoryStream.h>
#include <AK/QuickSort.h>
#include <AK/StringBuilder.h>
#include <AK/URL.h>
@ -16,7 +17,6 @@
#include <LibCore/DirIterator.h>
#include <LibCore/File.h>
#include <LibCore/MappedFile.h>
#include <LibCore/MemoryStream.h>
#include <LibCore/MimeData.h>
#include <LibHTTP/HttpRequest.h>
#include <LibHTTP/HttpResponse.h>
@ -336,7 +336,7 @@ ErrorOr<void> Client::handle_directory_listing(String const& requested_path, Str
builder.append("</html>\n"sv);
auto response = builder.to_deprecated_string();
auto stream = TRY(Core::Stream::FixedMemoryStream::construct(response.bytes()));
auto stream = TRY(FixedMemoryStream::construct(response.bytes()));
return send_response(*stream, request, { .type = TRY(String::from_utf8("text/html"sv)), .length = response.length() });
}

View File

@ -7,13 +7,13 @@
#include "AST.h"
#include "Shell.h"
#include <AK/DeprecatedString.h>
#include <AK/MemoryStream.h>
#include <AK/ScopeGuard.h>
#include <AK/ScopedValueRollback.h>
#include <AK/StringBuilder.h>
#include <AK/URL.h>
#include <LibCore/EventLoop.h>
#include <LibCore/File.h>
#include <LibCore/MemoryStream.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
@ -1641,7 +1641,7 @@ void Execute::for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(Non
Core::EventLoop loop;
auto notifier = Core::Notifier::construct(pipefd[0], Core::Notifier::Read);
Core::Stream::AllocatingMemoryStream stream;
AllocatingMemoryStream stream;
enum {
Continue,

View File

@ -16,7 +16,6 @@
#include <LibCore/ConfigFile.h>
#include <LibCore/EventLoop.h>
#include <LibCore/File.h>
#include <LibCore/MemoryStream.h>
#include <LibCore/Stream.h>
#include <LibCore/System.h>
#include <LibCore/SystemServerTakeover.h>
@ -343,7 +342,7 @@ public:
private:
HTTPHeadlessRequest(HTTP::HttpRequest&& request, NonnullOwnPtr<Core::Stream::BufferedSocketBase> socket, ByteBuffer&& stream_backing_buffer)
: m_stream_backing_buffer(move(stream_backing_buffer))
, m_output_stream(Core::Stream::FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors())
, m_output_stream(FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors())
, m_socket(move(socket))
, m_job(HTTP::Job::construct(move(request), *m_output_stream))
{
@ -369,7 +368,7 @@ public:
Optional<u32> m_response_code;
ByteBuffer m_stream_backing_buffer;
NonnullOwnPtr<Core::Stream::FixedMemoryStream> m_output_stream;
NonnullOwnPtr<FixedMemoryStream> m_output_stream;
NonnullOwnPtr<Core::Stream::BufferedSocketBase> m_socket;
NonnullRefPtr<HTTP::Job> m_job;
HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> m_response_headers;
@ -422,7 +421,7 @@ public:
private:
HTTPSHeadlessRequest(HTTP::HttpRequest&& request, NonnullOwnPtr<Core::Stream::BufferedSocketBase> socket, ByteBuffer&& stream_backing_buffer)
: m_stream_backing_buffer(move(stream_backing_buffer))
, m_output_stream(Core::Stream::FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors())
, m_output_stream(FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors())
, m_socket(move(socket))
, m_job(HTTP::HttpsJob::construct(move(request), *m_output_stream))
{
@ -448,7 +447,7 @@ public:
Optional<u32> m_response_code;
ByteBuffer m_stream_backing_buffer;
NonnullOwnPtr<Core::Stream::FixedMemoryStream> m_output_stream;
NonnullOwnPtr<FixedMemoryStream> m_output_stream;
NonnullOwnPtr<Core::Stream::BufferedSocketBase> m_socket;
NonnullRefPtr<HTTP::HttpsJob> m_job;
HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> m_response_headers;
@ -491,7 +490,7 @@ public:
private:
GeminiHeadlessRequest(Gemini::GeminiRequest&& request, NonnullOwnPtr<Core::Stream::BufferedSocketBase> socket, ByteBuffer&& stream_backing_buffer)
: m_stream_backing_buffer(move(stream_backing_buffer))
, m_output_stream(Core::Stream::FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors())
, m_output_stream(FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors())
, m_socket(move(socket))
, m_job(Gemini::Job::construct(move(request), *m_output_stream))
{
@ -517,7 +516,7 @@ public:
Optional<u32> m_response_code;
ByteBuffer m_stream_backing_buffer;
NonnullOwnPtr<Core::Stream::FixedMemoryStream> m_output_stream;
NonnullOwnPtr<FixedMemoryStream> m_output_stream;
NonnullOwnPtr<Core::Stream::BufferedSocketBase> m_socket;
NonnullRefPtr<Gemini::Job> m_job;
HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> m_response_headers;

View File

@ -5,10 +5,10 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/MemoryStream.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
#include <LibCore/MappedFile.h>
#include <LibCore/MemoryStream.h>
#include <LibLine/Editor.h>
#include <LibMain/Main.h>
#include <LibWasm/AbstractMachine/AbstractMachine.h>
@ -252,7 +252,7 @@ static Optional<Wasm::Module> parse(StringView filename)
return {};
}
auto stream = Core::Stream::FixedMemoryStream::construct(ReadonlyBytes { result.value()->data(), result.value()->size() }).release_value_but_fixme_should_propagate_errors();
auto stream = FixedMemoryStream::construct(ReadonlyBytes { result.value()->data(), result.value()->size() }).release_value_but_fixme_should_propagate_errors();
auto parse_result = Wasm::Module::parse(*stream);
if (parse_result.is_error()) {
warnln("Something went wrong, either the file is invalid, or there's a bug with LibWasm!");
@ -398,7 +398,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
StringBuilder argument_builder;
bool first = true;
for (auto& argument : arguments) {
Core::Stream::AllocatingMemoryStream stream;
AllocatingMemoryStream stream;
Wasm::Printer { stream }.print(argument);
if (first)
first = false;