directory_models_archive_reader.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma once
  2. #include "models_archive_reader.h"
  3. #include <util/folder/path.h>
  4. #include <util/generic/fwd.h>
  5. #include <util/generic/hash.h>
  6. #include <util/generic/ptr.h>
  7. #include <util/generic/vector.h>
  8. class IInputStream;
  9. class TBlob;
  10. class TDirectoryModelsArchiveReader : public IModelsArchiveReader {
  11. public:
  12. TDirectoryModelsArchiveReader(const TString& path, bool lockMemory = false, bool ownBlobs = false);
  13. virtual ~TDirectoryModelsArchiveReader() override;
  14. virtual size_t Count() const noexcept override;
  15. virtual TString KeyByIndex(size_t n) const override;
  16. virtual bool Has(const TStringBuf key) const override;
  17. virtual TAutoPtr<IInputStream> ObjectByKey(const TStringBuf key) const override;
  18. virtual TBlob ObjectBlobByKey(const TStringBuf key) const override;
  19. virtual TBlob BlobByKey(const TStringBuf key) const override;
  20. virtual bool Compressed() const override;
  21. private:
  22. TString NormalizePath(TString path) const; // in archive path works unix-like path delimiter and leading slash is neccesery
  23. void LoadFilesAndSubdirs(const TString& subPath, bool lockMemory, bool ownBlobs);
  24. private:
  25. TString Path_;
  26. THashMap<TString, TString> PathByKey_;
  27. THashMap<TString, TBlob> BlobByKey_;
  28. TVector<TString> Recs_;
  29. };