mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:37:37 +00:00
LibCompress: Switch DeflateDecompressor
to a fallible constructor
We don't have anything fallible in there yet, but we will soon switch the seekback buffer to the new `CircularBuffer`, which has a fallible constructor. We have to do the same for the internal `GzipDecompressor::Member` class, as it needs to construct a `DeflateCompressor` from its received stream.
This commit is contained in:
parent
d717a08003
commit
d23f0a7405
4 changed files with 34 additions and 16 deletions
|
@ -189,6 +189,11 @@ ErrorOr<bool> DeflateDecompressor::UncompressedBlock::try_read_more()
|
|||
return true;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<DeflateDecompressor>> DeflateDecompressor::construct(Core::Stream::Handle<Core::Stream::Stream> stream)
|
||||
{
|
||||
return TRY(adopt_nonnull_own_or_enomem(new (nothrow) DeflateDecompressor(move(stream))));
|
||||
}
|
||||
|
||||
DeflateDecompressor::DeflateDecompressor(Core::Stream::Handle<Core::Stream::Stream> stream)
|
||||
: m_input_stream(make<Core::Stream::LittleEndianInputBitStream>(move(stream)))
|
||||
{
|
||||
|
@ -311,12 +316,12 @@ void DeflateDecompressor::close()
|
|||
ErrorOr<ByteBuffer> DeflateDecompressor::decompress_all(ReadonlyBytes bytes)
|
||||
{
|
||||
auto memory_stream = TRY(Core::Stream::FixedMemoryStream::construct(bytes));
|
||||
DeflateDecompressor deflate_stream { move(memory_stream) };
|
||||
auto deflate_stream = TRY(DeflateDecompressor::construct(move(memory_stream)));
|
||||
DuplexMemoryStream output_stream;
|
||||
|
||||
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
|
||||
while (!deflate_stream.is_eof()) {
|
||||
auto const slice = TRY(deflate_stream.read(buffer));
|
||||
while (!deflate_stream->is_eof()) {
|
||||
auto const slice = TRY(deflate_stream->read(buffer));
|
||||
output_stream.write_or_error(slice);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue