aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/archive/directory_models_archive_reader.h
blob: d16d6d728d9ac08e107c796c867b40c60f4ed2b9 (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
#pragma once

#include "models_archive_reader.h"

#include <util/folder/path.h>
#include <util/generic/fwd.h>
#include <util/generic/hash.h>
#include <util/generic/ptr.h>
#include <util/generic/vector.h>


class IInputStream;

class TBlob;

class TDirectoryModelsArchiveReader : public IModelsArchiveReader {
public:
    TDirectoryModelsArchiveReader(const TString& path, bool lockMemory = false, bool ownBlobs = false);
    virtual ~TDirectoryModelsArchiveReader() override;

    virtual size_t Count() const noexcept override;
    virtual TString KeyByIndex(size_t n) const override;
    virtual bool Has(const TStringBuf key) const override;
    virtual TAutoPtr<IInputStream> ObjectByKey(const TStringBuf key) const override;
    virtual TBlob ObjectBlobByKey(const TStringBuf key) const override;
    virtual TBlob BlobByKey(const TStringBuf key) const override;
    virtual bool Compressed() const override;

private:
    TString NormalizePath(TString path) const; // in archive path works unix-like path delimiter and leading slash is neccesery
    void LoadFilesAndSubdirs(const TString& subPath, bool lockMemory, bool ownBlobs);

private:
    TString Path_;
    THashMap<TString, TString> PathByKey_;
    THashMap<TString, TBlob> BlobByKey_;
    TVector<TString> Recs_;
};