diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2018-02-20 15:06:26 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2018-02-21 14:50:13 +0100 |
commit | 021e1ae596440cfdee5ffe75907b76069ae44307 (patch) | |
tree | ebf15ff8a72e5f14291ba37b6f297ca9a738eea4 /platform/default/default_file_source.cpp | |
parent | 06213d9145d3b20b63e235cc25678fd76dc296d0 (diff) | |
download | qtlocation-mapboxgl-upstream/blob.tar.gz |
[core] introduce Blob for compressed and uncompressed dataupstream/blob
- Blob is a wrapper type for a shared_ptr<const string> that has accessor functions for getting compressed and uncompressed data
- Moved util::writeFile, util::readFile, util::compress, util::uncompress, decodeImage, and encodePNG to the Blob interface
- Added Blob support to Request and file sources
- Added Blob support to VectorTile objects
- Added support for gzip decoding to util::uncompress
- We're no longer compressing WebP, PNG, and JPEG data when storing in the OfflineDatabase
- Android's HTTPRequest returns compressed Blobs by default
One caveat is that our previous decompress function didn't support gzip, so once users upgrade to this version, their offline cache may contain both zlib-compressed data and gzip-compressed data, but older versions won't be able to decompress gzip data. On the other hand, we don't support downgrading SDKs anyway, so this shouldn't be a problem. To be on the safe side, we could bump the user_version of the SQLite DB.
Diffstat (limited to 'platform/default/default_file_source.cpp')
-rw-r--r-- | platform/default/default_file_source.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/platform/default/default_file_source.cpp b/platform/default/default_file_source.cpp index cb602995a4..5dcd28facd 100644 --- a/platform/default/default_file_source.cpp +++ b/platform/default/default_file_source.cpp @@ -151,8 +151,23 @@ public: // Get from the online file source if (resource.hasLoadingMethod(Resource::LoadingMethod::Network)) { + // Always solicit a compressed response so that we can insert it into the database + // while still compressed to save on CPU time. + const auto compression = resource.compression; + resource.compression = Resource::Compression::PreferCompressed; tasks[req] = onlineFileSource.request(resource, [=] (Response onlineResponse) mutable { this->offlineDatabase->put(resource, onlineResponse); + // If the original request expects an uncompressed response, uncompress before + // handing it back. + if (onlineResponse.data && onlineResponse.data.isCompressed() && + compression == Resource::Compression::Uncompressed) { + try { + onlineResponse.data.uncompress(); + } catch (std::exception& ex) { + onlineResponse.error = std::make_unique<Response::Error>( + Response::Error::Reason::Other, ex.what()); + } + } callback(onlineResponse); }); } |