aboutsummaryrefslogtreecommitdiffstats
path: root/util/stream/length.cpp
blob: 09968fc2abb5009741869779a6b7855d9108cd51 (plain) (blame)
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
#include "length.h" 
 
size_t TLengthLimitedInput::DoRead(void* buf, size_t len) { 
    const size_t toRead = (size_t)Min<ui64>(Length_, len); 
    const size_t ret = Slave_->Read(buf, toRead); 
 
    Length_ -= ret; 
 
    return ret; 
} 
 
size_t TLengthLimitedInput::DoSkip(size_t len) { 
    len = (size_t)Min<ui64>((ui64)len, Length_); 
    len = Slave_->Skip(len); 
    Length_ -= len; 
    return len; 
} 
 
size_t TCountingInput::DoRead(void* buf, size_t len) { 
    const size_t ret = Slave_->Read(buf, len); 
    Count_ += ret; 
    return ret; 
} 
 
size_t TCountingInput::DoSkip(size_t len) { 
    const size_t ret = Slave_->Skip(len); 
    Count_ += ret; 
    return ret; 
} 

size_t TCountingInput::DoReadTo(TString& st, char ch) {
    const size_t ret = Slave_->ReadTo(st, ch);
    Count_ += ret;
    return ret;
}

ui64 TCountingInput::DoReadAll(IOutputStream& out) {
    const ui64 ret = Slave_->ReadAll(out);
    Count_ += ret;
    return ret;
}

void TCountingOutput::DoWrite(const void* buf, size_t len) {
    Slave_->Write(buf, len);

    Count_ += len;
}