summaryrefslogtreecommitdiff
path: root/AK/CountingStream.cpp
blob: c6074b25aa30e29718ec03de66cf41ba620705d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * Copyright (c) 2023, Tim Schumacher <timschumi@gmx.de>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <AK/CountingStream.h>

namespace AK {

CountingStream::CountingStream(MaybeOwned<Stream> stream)
    : m_stream(move(stream))
{
}

u64 CountingStream::read_bytes() const
{
    return m_read_bytes;
}

ErrorOr<Bytes> CountingStream::read_some(Bytes bytes)
{
    auto result = TRY(m_stream->read_some(bytes));

    m_read_bytes += result.size();

    return result;
}

ErrorOr<void> CountingStream::discard(size_t discarded_bytes)
{
    TRY(m_stream->discard(discarded_bytes));

    m_read_bytes += discarded_bytes;

    return {};
}

ErrorOr<size_t> CountingStream::write_some(ReadonlyBytes bytes)
{
    return m_stream->write_some(bytes);
}

bool CountingStream::is_eof() const
{
    return m_stream->is_eof();
}

bool CountingStream::is_open() const
{
    return m_stream->is_open();
}

void CountingStream::close()
{
}

}