Skip to content

Commit 151e629

Browse files
authored
fix(core): streaming of small files using asset://, closes #2854 (#3039)
1 parent fb2b9a5 commit 151e629

4 files changed

Lines changed: 9 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Fix streaming of small files using the `asset` protocol.

core/tauri/src/manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ impl<R: Runtime> WindowManager<R> {
350350
if range.length > file_size / 3 {
351351
// max size sent (400ko / request)
352352
// as it's local file system we can afford to read more often
353-
real_length = 1024 * 400;
353+
real_length = std::cmp::min(file_size - range.start, 1024 * 400);
354354
}
355355

356356
// last byte we are reading, the length of the range include the last byte

examples/streaming/src-tauri/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
fn main() {
1111
use std::{
12+
cmp::min,
1213
io::{Read, Seek, SeekFrom},
1314
path::PathBuf,
1415
process::{Command, Stdio},
@@ -74,7 +75,7 @@ fn main() {
7475
if range.length > file_size / 3 {
7576
// max size sent (400ko / request)
7677
// as it's local file system we can afford to read more often
77-
real_length = 1024 * 400;
78+
real_length = min(file_size - range.start, 1024 * 400);
7879
}
7980

8081
// last byte we are reading, the length of the range include the last byte

tooling/api/src/tauri.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async function invoke<T>(cmd: string, args: InvokeArgs = {}): Promise<T> {
9696
* Convert a device file path to an URL that can be loaded by the webview.
9797
* Note that `asset:` must be allowed on the `csp` value configured on `tauri.conf.json`.
9898
*
99-
* @param filePath the file path. On Windows, the drive name must be omitted, i.e. using `/Users/user/file.png` instead of `C:/Users/user/file.png`.
99+
* @param filePath the file path.
100100
*
101101
* @return the URL that can be used as source on the webview
102102
*/

0 commit comments

Comments
 (0)