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

AK: Add a Stream wrapper that counts read bytes

This commit is contained in:
Tim Schumacher 2023-03-16 10:23:24 +01:00 committed by Andreas Kling
parent d1f6a28ffd
commit e62183f0ba
4 changed files with 93 additions and 0 deletions

32
AK/CountingStream.h Normal file
View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2023, Tim Schumacher <timschumi@gmx.de>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/MaybeOwned.h>
#include <AK/Stream.h>
namespace AK {
class CountingStream : public Stream {
public:
CountingStream(MaybeOwned<Stream>);
u64 read_bytes() const;
virtual ErrorOr<Bytes> read_some(Bytes) override;
virtual ErrorOr<void> discard(size_t discarded_bytes) override;
virtual ErrorOr<size_t> write_some(ReadonlyBytes) override;
virtual bool is_eof() const override;
virtual bool is_open() const override;
virtual void close() override;
private:
MaybeOwned<Stream> m_stream;
u64 m_read_bytes { 0 };
};
}