29using std::string_view;
43 using Extras = map<string, string, std::less<>>;
46 FileSpec(
string filehandler,
const vector<string>& chunksIn)
47 : fileHandlerName{std::move(filehandler)}, chunks{chunksIn} {}
48 FileSpec(
string filehandler,
const vector<string>&& chunksIn)
49 : fileHandlerName{std::move(filehandler)}, chunks{chunksIn} {}
50 explicit FileSpec(
const vector<string>& chunksIn) : chunks{chunksIn} {}
51 explicit FileSpec(vector<string>&& chunksIn) : chunks{std::move(chunksIn)} {}
58 bool isDiskFile()
const;
60 static int parseUri(string_view uri,
string& outScheme,
string& outPath,
Extras& outQueryParams);
68 int fromPathJsonUri(string_view pathJsonUri, string_view defaultFileHandlerName = {});
77 bool fromJson(string_view jsonStr);
82 string toJson()
const;
105 const string&
getExtra(string_view name)
const;
107 bool getExtra(string_view name,
string& outValue)
const;
109 bool hasExtra(string_view name)
const;
112 int getExtraAsInt(string_view name,
int defaultValue = 0)
const;
115 int64_t
getExtraAsInt64(string_view name, int64_t defaultValue = 0)
const;
118 uint64_t
getExtraAsUInt64(string_view name, uint64_t defaultValue = 0)
const;
124 bool getExtraAsBool(string_view name,
bool defaultValue =
false)
const;
126 static int decodeQuery(string_view query,
string& outKey,
string& outValue);
127 static int urldecode(string_view in,
string& out);
129 void setExtra(string_view name, string_view value);
130 void setExtra(string_view name,
const char* value);
131 void setExtra(string_view name,
bool value);
132 void setExtra(string_view name,
const string& value);
133 template <
typename T>
134 void setExtra(string_view name, T value) {
135 extras[string(name)] = std::to_string(value);
141 string fileHandlerName;
144 vector<string> chunks;
145 vector<int64_t> chunkSizes;
Definition Compressor.cpp:113
Generalized file descriptor class, allowing the efficient representation of complex file objects,...
Definition FileSpec.h:40
string toPathJsonUri() const
Reverse operation as fromPathJsonUri, as possible.
Definition FileSpec.cpp:208
bool hasChunkSizes() const
Tell if we have chunks and all of them has a file size.
Definition FileSpec.cpp:279
int64_t getExtraAsInt64(string_view name, int64_t defaultValue=0) const
Definition FileSpec.cpp:431
bool operator==(const FileSpec &rhs) const
Test equality (for testing)
Definition FileSpec.cpp:400
string getSourceLocation() const
Get the location of the object, which is the uri (if any), or the file handler.
Definition FileSpec.cpp:306
void unsetExtra(string_view name)
Unset an extra parameter.
Definition FileSpec.cpp:451
int parseUri()
Parse the uri field already set, overwriting other fields on success.
Definition FileSpec.cpp:271
bool hasExtra(string_view name) const
Tell if an extra parameter is defined.
Definition FileSpec.cpp:422
const string & getExtra(string_view name) const
Get an extra parameter, or the empty string.
Definition FileSpec.cpp:407
map< string, string, std::less<> > Extras
Definition FileSpec.h:43
double getExtraAsDouble(string_view name, double defaultValue=0) const
Definition FileSpec.cpp:441
uint64_t getExtraAsUInt64(string_view name, uint64_t defaultValue=0) const
Definition FileSpec.cpp:436
int64_t getFileSize() const
Get the total size of the object, or -1 if don't know.
Definition FileSpec.cpp:283
string getXXHash() const
Get signature of the path.
Definition FileSpec.cpp:384
int fromPathJsonUri(string_view pathJsonUri, string_view defaultFileHandlerName={})
Definition FileSpec.cpp:168
void clear()
clear all the fields.
Definition FileSpec.cpp:90
bool getExtraAsBool(string_view name, bool defaultValue=false) const
Definition FileSpec.cpp:446
string getFileName() const
Get filename, if possible.
Definition FileSpec.cpp:374
string getEasyPath() const
Logical reverse operation from fromPathJsonUri, but kept minimal for logging.
Definition FileSpec.cpp:325
int getExtraAsInt(string_view name, int defaultValue=0) const
Definition FileSpec.cpp:426