direct_io.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "direct_io.h"
  2. #include <util/generic/utility.h>
  3. size_t TRandomAccessFileInput::DoRead(void* buf, size_t len) {
  4. const size_t result = File.Pread(buf, len, Position);
  5. Position += result;
  6. return result;
  7. }
  8. TRandomAccessFileInput::TRandomAccessFileInput(TDirectIOBufferedFile& file, ui64 position)
  9. : File(file)
  10. , Position(position)
  11. {
  12. }
  13. size_t TRandomAccessFileInput::DoSkip(size_t len) {
  14. size_t skiped = Min(len, (size_t)Min((ui64)Max<size_t>(), File.GetLength() - Position));
  15. Position += skiped;
  16. return skiped;
  17. }
  18. TRandomAccessFileOutput::TRandomAccessFileOutput(TDirectIOBufferedFile& file)
  19. : File(&file)
  20. {
  21. }
  22. void TRandomAccessFileOutput::DoWrite(const void* buf, size_t len) {
  23. File->Write(buf, len);
  24. }
  25. void TRandomAccessFileOutput::DoFlush() {
  26. File->FlushData();
  27. }
  28. TBufferedFileOutputEx::TBufferedFileOutputEx(const TString& path, EOpenMode oMode, size_t buflen)
  29. : TRandomAccessFileOutput(*(new TDirectIOBufferedFile(path, oMode, buflen)))
  30. , FileHolder(File)
  31. {
  32. }
  33. void TBufferedFileOutputEx::DoFinish() {
  34. FileHolder->Finish();
  35. }
  36. void TBufferedFileOutputEx::DoFlush() {
  37. }