aboutsummaryrefslogtreecommitdiffstats
path: root/util/stream/direct_io.h
blob: 2e1f2e07dd7dfbe9a448a3efea6b9d1a643d21b6 (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
#pragma once

#include "input.h"
#include "output.h"
#include <util/system/direct_io.h>

class TRandomAccessFileInput: public IInputStream {
public:
    TRandomAccessFileInput(TDirectIOBufferedFile& file, ui64 position);

protected:
    size_t DoRead(void* buf, size_t len) override;
    size_t DoSkip(size_t len) override;

private:
    TDirectIOBufferedFile& File;
    ui64 Position;
};

class TRandomAccessFileOutput: public IOutputStream {
public:
    TRandomAccessFileOutput(TDirectIOBufferedFile& file);

    TRandomAccessFileOutput(TRandomAccessFileOutput&&) noexcept = default;
    TRandomAccessFileOutput& operator=(TRandomAccessFileOutput&&) noexcept = default;

protected:
    TDirectIOBufferedFile* File;

private:
    void DoWrite(const void* buf, size_t len) override;
    void DoFlush() override;
};

class TBufferedFileOutputEx: public TRandomAccessFileOutput {
public:
    TBufferedFileOutputEx(const TString& path, EOpenMode oMode, size_t buflen = 1 << 17);

private:
    void DoFlush() override;
    void DoFinish() override;
    THolder<TDirectIOBufferedFile> FileHolder;
};