aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/core/file_storage/file_storage.h
blob: 1015269deb4bb6e9462607cfc8ac04a8ffe57f77 (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
44
45
46
47
48
49
50
#pragma once

#include "storage.h"

#include <yql/essentials/core/file_storage/defs/downloader.h>

#include <library/cpp/threading/future/future.h>
#include <library/cpp/uri/http_url.h>

#include <util/folder/path.h>
#include <util/generic/ptr.h>
#include <util/generic/string.h>

#include <vector>

namespace NYql {

class TFileStorageConfig;

struct IFileStorage: public TThrRefBase {
    virtual ~IFileStorage() = default;
    virtual TFileLinkPtr PutFile(const TString& file, const TString& outFileName = {}) = 0;
    virtual TFileLinkPtr PutFileStripped(const TString& file, const TString& originalMd5 = {}) = 0;
    virtual TFileLinkPtr PutInline(const TString& data) = 0;
    virtual TFileLinkPtr PutUrl(const TString& url, const TString& token) = 0;
    // async versions
    virtual NThreading::TFuture<TFileLinkPtr> PutFileAsync(const TString& file, const TString& outFileName = {}) = 0;
    virtual NThreading::TFuture<TFileLinkPtr> PutInlineAsync(const TString& data) = 0;
    virtual NThreading::TFuture<TFileLinkPtr> PutUrlAsync(const TString& url, const TString& token) = 0;

    virtual TFsPath GetRoot() const = 0;
    virtual TFsPath GetTemp() const = 0;
    virtual const TFileStorageConfig& GetConfig() const = 0;
};

using TFileStoragePtr = TIntrusivePtr<IFileStorage>;

// Will use auto-cleaned temporary directory if storagePath is empty
TFileStoragePtr CreateFileStorage(const TFileStorageConfig& params, const std::vector<NFS::IDownloaderPtr>& downloaders = {});

TFileStoragePtr WithAsync(TFileStoragePtr fs);

inline TFileStoragePtr CreateAsyncFileStorage(const TFileStorageConfig& params, const std::vector<NFS::IDownloaderPtr>& downloaders = {}) {
    return WithAsync(CreateFileStorage(params, downloaders));
}

void LoadFsConfigFromFile(TStringBuf path, TFileStorageConfig& params);
void LoadFsConfigFromResource(TStringBuf path, TFileStorageConfig& params);

} // NYql