mirror of https://github.com/kiwix/libkiwix.git
Default constructed ByteRange is a full range
This commit is contained in:
parent
f3e79c6b4c
commit
693905eb68
|
@ -25,7 +25,7 @@ namespace kiwix {
|
|||
ByteRange::ByteRange()
|
||||
: kind_(NONE)
|
||||
, first_(0)
|
||||
, last_(-1)
|
||||
, last_(INT64_MAX)
|
||||
{}
|
||||
|
||||
ByteRange::ByteRange(Kind kind, int64_t first, int64_t last)
|
||||
|
|
|
@ -65,30 +65,22 @@ fullURL2LocalURL(const std::string& full_url, const std::string& rootLocation)
|
|||
|
||||
ByteRange parse_byte_range(std::string range)
|
||||
{
|
||||
const int64_t int64_max = std::numeric_limits<int64_t>::max();
|
||||
|
||||
ByteRange byteRange;
|
||||
const std::string byteUnitSpec("bytes=");
|
||||
if ( kiwix::startsWith(range, byteUnitSpec) ) {
|
||||
range.erase(0, byteUnitSpec.size());
|
||||
int start = 0;
|
||||
int end = -1;
|
||||
std::istringstream iss(range);
|
||||
char c;
|
||||
|
||||
iss >> start;
|
||||
int64_t start, end = INT64_MAX;
|
||||
if (iss >> start) {
|
||||
if ( start < 0 ) {
|
||||
if ( iss.eof() )
|
||||
byteRange = ByteRange(ByteRange::PARSED, start, int64_max);
|
||||
byteRange = ByteRange(ByteRange::PARSED, start, end);
|
||||
} else {
|
||||
iss >> c;
|
||||
if (iss.good() && c=='-') {
|
||||
iss >> end;
|
||||
if (iss.fail()) {
|
||||
// Something went wrong while extracting
|
||||
end = -1;
|
||||
}
|
||||
if (iss.eof()) {
|
||||
char c;
|
||||
if (iss >> c && c=='-') {
|
||||
iss >> end; // if this fails, end is not modified, which is OK
|
||||
if (iss.eof())
|
||||
byteRange = ByteRange(ByteRange::PARSED, start, end);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,9 +50,7 @@ ByteRange resolve_byte_range(const kiwix::Entry& entry, ByteRange range)
|
|||
? std::max(int64_t(0), entrySize + range.first())
|
||||
: range.first();
|
||||
|
||||
const int64_t resolved_last = range.last() < 0
|
||||
? entrySize - 1
|
||||
: std::min(entrySize-1, range.last());
|
||||
const int64_t resolved_last = std::min(entrySize-1, range.last());
|
||||
|
||||
return ByteRange(ByteRange::RESOLVED_PARTIAL_CONTENT, resolved_first, resolved_last);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue