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 "direct_io.h"
#include <util/generic/utility.h>
size_t TRandomAccessFileInput::DoRead(void* buf, size_t len) {
const size_t result = File.Pread(buf, len, Position);
Position += result;
return result;
}
TRandomAccessFileInput::TRandomAccessFileInput(TDirectIOBufferedFile& file, ui64 position)
: File(file)
, Position(position)
{
}
size_t TRandomAccessFileInput::DoSkip(size_t len) {
size_t skiped = Min(len, (size_t)Min((ui64)Max<size_t>(), File.GetLength() - Position));
Position += skiped;
return skiped;
}
TRandomAccessFileOutput::TRandomAccessFileOutput(TDirectIOBufferedFile& file)
: File(&file)
{
}
void TRandomAccessFileOutput::DoWrite(const void* buf, size_t len) {
File->Write(buf, len);
}
void TRandomAccessFileOutput::DoFlush() {
File->FlushData();
}
TBufferedFileOutputEx::TBufferedFileOutputEx(const TString& path, EOpenMode oMode, size_t buflen)
: TRandomAccessFileOutput(*(new TDirectIOBufferedFile(path, oMode, buflen)))
, FileHolder(File)
{
}
void TBufferedFileOutputEx::DoFinish() {
FileHolder->Finish();
}
void TBufferedFileOutputEx::DoFlush() {
}
|