diff options
author | Tim Schumacher <timschumi@gmx.de> | 2023-03-16 10:23:24 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-03-21 10:25:13 +0100 |
commit | e62183f0ba3a2aad9eb9dcdd879f5f7f03c76043 (patch) | |
tree | b2ee8df1779ea303a1bda293a57759632aa16ba6 /AK/CountingStream.h | |
parent | d1f6a28ffdcd943f7b78c3c7a21e30556dd232ab (diff) | |
download | serenity-e62183f0ba3a2aad9eb9dcdd879f5f7f03c76043.zip |
AK: Add a Stream wrapper that counts read bytes
Diffstat (limited to 'AK/CountingStream.h')
-rw-r--r-- | AK/CountingStream.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/AK/CountingStream.h b/AK/CountingStream.h new file mode 100644 index 0000000000..3afd1f4b48 --- /dev/null +++ b/AK/CountingStream.h @@ -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 }; +}; + +} |