length.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "length.h"
  2. size_t TLengthLimitedInput::DoRead(void* buf, size_t len) {
  3. const size_t toRead = (size_t)Min<ui64>(Length_, len);
  4. const size_t ret = Slave_->Read(buf, toRead);
  5. Length_ -= ret;
  6. return ret;
  7. }
  8. size_t TLengthLimitedInput::DoSkip(size_t len) {
  9. len = (size_t)Min<ui64>((ui64)len, Length_);
  10. len = Slave_->Skip(len);
  11. Length_ -= len;
  12. return len;
  13. }
  14. size_t TCountingInput::DoRead(void* buf, size_t len) {
  15. const size_t ret = Slave_->Read(buf, len);
  16. Count_ += ret;
  17. return ret;
  18. }
  19. size_t TCountingInput::DoSkip(size_t len) {
  20. const size_t ret = Slave_->Skip(len);
  21. Count_ += ret;
  22. return ret;
  23. }
  24. size_t TCountingInput::DoReadTo(TString& st, char ch) {
  25. const size_t ret = Slave_->ReadTo(st, ch);
  26. Count_ += ret;
  27. return ret;
  28. }
  29. ui64 TCountingInput::DoReadAll(IOutputStream& out) {
  30. const ui64 ret = Slave_->ReadAll(out);
  31. Count_ += ret;
  32. return ret;
  33. }
  34. void TCountingOutput::DoWrite(const void* buf, size_t len) {
  35. Slave_->Write(buf, len);
  36. Count_ += len;
  37. }