direct_io.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #pragma once
  2. #include "input.h"
  3. #include "output.h"
  4. #include <util/system/direct_io.h>
  5. class TRandomAccessFileInput: public IInputStream {
  6. public:
  7. TRandomAccessFileInput(TDirectIOBufferedFile& file, ui64 position);
  8. protected:
  9. size_t DoRead(void* buf, size_t len) override;
  10. size_t DoSkip(size_t len) override;
  11. private:
  12. TDirectIOBufferedFile& File;
  13. ui64 Position;
  14. };
  15. class TRandomAccessFileOutput: public IOutputStream {
  16. public:
  17. TRandomAccessFileOutput(TDirectIOBufferedFile& file);
  18. TRandomAccessFileOutput(TRandomAccessFileOutput&&) noexcept = default;
  19. TRandomAccessFileOutput& operator=(TRandomAccessFileOutput&&) noexcept = default;
  20. protected:
  21. TDirectIOBufferedFile* File;
  22. private:
  23. void DoWrite(const void* buf, size_t len) override;
  24. void DoFlush() override;
  25. };
  26. class TBufferedFileOutputEx: public TRandomAccessFileOutput {
  27. public:
  28. TBufferedFileOutputEx(const TString& path, EOpenMode oMode, size_t buflen = 1 << 17);
  29. private:
  30. void DoFlush() override;
  31. void DoFinish() override;
  32. THolder<TDirectIOBufferedFile> FileHolder;
  33. };