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
let total_chunks = total_bytes.div_ceil(DOWNLOAD_CHUNK_SIZE_BYTES);
94
91
95
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
96
93
letmut bytes = vec![];
97
94
98
-
letmut current_byte_index = 0;
99
-
loop{
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);
// Get the size of actual data. The response will be as long as the requested range is, but content-length contains the amount we actually want to read
112
-
let content_length = request
113
-
.header_section("content-length")
114
-
.context("no content-length header")?
115
-
.trim()
116
-
.parse::<usize>()?;
117
-
118
-
// Check if we somehow have no more data (file size would be a perfect multiple of DOWNLOAD_CHUNK_SIZE_BYTES)
119
-
if content_length == 0{
120
-
break;
121
-
}
122
-
123
-
let data = request.data().ok_or(anyhow!("no data"))?;
114
+
.context(".get() returned None")?
115
+
.wait_for_data()
116
+
.await?;
124
117
125
-
// Make sure we don't panic if server sent less data than claimed (should never happen, but avoid a panic)
126
-
if data.len() < content_length {
127
-
returnErr(anyhow!(
128
-
"Received less data ({}) than content-length ({})",
// 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)
0 commit comments