You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Figure out total size of download (this request is acting like a HEAD since we don't have those in this environment. Nothing actually gets downloaded since we are constraining the range)
70
+
let request = NetworkRequestBuilder::new(&self.url)
75
71
.context("can't create new NetworkRequestBuilder")?
72
+
.with_header(&format!("Range: bytes=0-0"))
73
+
.context(".with_header() returned None")?
76
74
.get()
77
-
.context(".get() returned None")?
78
-
.wait_for_data()
79
-
.await?;
75
+
.context(".get() returned None")?;
76
+
77
+
request.wait_for_data().await?;
78
+
79
+
// Try parsing the content-range header
80
+
let total_bytes = request
81
+
.header_section("content-range")
82
+
.context("no content-range header")?
83
+
.trim()
84
+
.split("/")
85
+
.last()
86
+
.ok_or(anyhow!("invalid content-range"))?
87
+
.parse::<usize>()?;
88
+
89
+
// Total amount of chunks to download
90
+
let total_chunks = total_bytes.div_ceil(DOWNLOAD_CHUNK_SIZE_BYTES);
91
+
92
+
// We need to download the data in chunks of DOWNLOAD_CHUNK_SIZE_BYTES to avoid a timeout, so we need to keep track of a "working" accumulation of all responses
93
+
letmut bytes = vec![];
94
+
95
+
for i in0..total_chunks {
96
+
// Calculate the range for the current chunk
97
+
let range_start = i *DOWNLOAD_CHUNK_SIZE_BYTES;
98
+
let range_end = ((i + 1)*DOWNLOAD_CHUNK_SIZE_BYTES - 1).min(total_bytes - 1);
// Only close connection if DATABASE_STATE has already been initialized - otherwise we end up unnecessarily copying the bundled data and instantly replacing it (due to initialization logic in database state)
82
122
ifLazy::get(&DATABASE_STATE).is_some(){
@@ -87,23 +127,8 @@ impl Function for DownloadNavigationData {
0 commit comments