mirror of
https://github.com/overte-org/overte.git
synced 2025-04-12 10:42:10 +02:00
Fix byte range for file resource requests
This commit is contained in:
parent
194541b2d0
commit
043c587395
3 changed files with 19 additions and 26 deletions
|
@ -68,11 +68,9 @@ void SendAssetTask::run() {
|
|||
QFile file { filePath };
|
||||
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
if (!byteRange.isSet()) {
|
||||
// if the byte range is not set, force it to be from 0 to the end of the file
|
||||
byteRange.fromInclusive = 0;
|
||||
byteRange.toExclusive = file.size();
|
||||
}
|
||||
|
||||
// first fixup the range based on the now known file size
|
||||
byteRange.fixupRange(file.size());
|
||||
|
||||
// check if we're being asked to read data that we just don't have
|
||||
// because of the file size
|
||||
|
@ -82,10 +80,6 @@ void SendAssetTask::run() {
|
|||
<< byteRange.fromInclusive << ":" << byteRange.toExclusive;
|
||||
} else {
|
||||
// we have a valid byte range, handle it and send the asset
|
||||
|
||||
// first fixup the range based on the now known file size
|
||||
byteRange.fixupRange(file.size());
|
||||
|
||||
auto size = byteRange.size();
|
||||
|
||||
if (byteRange.fromInclusive >= 0) {
|
||||
|
|
|
@ -30,6 +30,12 @@ struct ByteRange {
|
|||
}
|
||||
|
||||
void fixupRange(int64_t fileSize) {
|
||||
if (!isSet()) {
|
||||
// if the byte range is not set, force it to be from 0 to the end of the file
|
||||
fromInclusive = 0;
|
||||
toExclusive = fileSize;
|
||||
}
|
||||
|
||||
if (fromInclusive > 0 && toExclusive == 0) {
|
||||
// we have a left side of the range that is non-zero
|
||||
// if the RHS of the range is zero, set it to the end of the file now
|
||||
|
|
|
@ -34,24 +34,17 @@ void FileResourceRequest::doSend() {
|
|||
if (file.size() < _byteRange.fromInclusive || file.size() < _byteRange.toExclusive) {
|
||||
_result = ResourceRequest::InvalidByteRange;
|
||||
} else {
|
||||
if (!_byteRange.isSet()) {
|
||||
// no byte range, read the whole file
|
||||
_data = file.readAll();
|
||||
// fix it up based on the known size of the file
|
||||
_byteRange.fixupRange(file.size());
|
||||
|
||||
if (_byteRange.fromInclusive >= 0) {
|
||||
// this is a positive byte range, simply skip to that part of the file and read from there
|
||||
file.seek(_byteRange.fromInclusive);
|
||||
_data = file.read(_byteRange.size());
|
||||
} else {
|
||||
// we have a byte range to handle
|
||||
|
||||
// fix it up based on the known size of the file
|
||||
_byteRange.fixupRange(file.size());
|
||||
|
||||
if (_byteRange.fromInclusive > 0) {
|
||||
// this is a positive byte range, simply skip to that part of the file and read from there
|
||||
file.seek(_byteRange.fromInclusive);
|
||||
_data = file.read(_byteRange.size());
|
||||
} else {
|
||||
// this is a negative byte range, we'll need to grab data from the end of the file first
|
||||
file.seek(file.size() + _byteRange.fromInclusive);
|
||||
_data = file.read(_byteRange.size());
|
||||
}
|
||||
// this is a negative byte range, we'll need to grab data from the end of the file first
|
||||
file.seek(file.size() + _byteRange.fromInclusive);
|
||||
_data = file.read(_byteRange.size());
|
||||
}
|
||||
|
||||
_result = ResourceRequest::Success;
|
||||
|
|
Loading…
Reference in a new issue