Skip to content

Commit

Permalink
fix(core): streaming of small files using asset://, closes #2854 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Dec 9, 2021
1 parent fb2b9a5 commit 151e629
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/streaming-small-file-fix.md
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Fix streaming of small files using the `asset` protocol.
2 changes: 1 addition & 1 deletion core/tauri/src/manager.rs
Expand Up @@ -350,7 +350,7 @@ impl<R: Runtime> WindowManager<R> {
if range.length > file_size / 3 {
// max size sent (400ko / request)
// as it's local file system we can afford to read more often
real_length = 1024 * 400;
real_length = std::cmp::min(file_size - range.start, 1024 * 400);
}

// last byte we are reading, the length of the range include the last byte
Expand Down
3 changes: 2 additions & 1 deletion examples/streaming/src-tauri/src/main.rs
Expand Up @@ -9,6 +9,7 @@

fn main() {
use std::{
cmp::min,
io::{Read, Seek, SeekFrom},
path::PathBuf,
process::{Command, Stdio},
Expand Down Expand Up @@ -74,7 +75,7 @@ fn main() {
if range.length > file_size / 3 {
// max size sent (400ko / request)
// as it's local file system we can afford to read more often
real_length = 1024 * 400;
real_length = min(file_size - range.start, 1024 * 400);
}

// last byte we are reading, the length of the range include the last byte
Expand Down
2 changes: 1 addition & 1 deletion tooling/api/src/tauri.ts
Expand Up @@ -96,7 +96,7 @@ async function invoke<T>(cmd: string, args: InvokeArgs = {}): Promise<T> {
* Convert a device file path to an URL that can be loaded by the webview.
* Note that `asset:` must be allowed on the `csp` value configured on `tauri.conf.json`.
*
* @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`.
* @param filePath the file path.
*
* @return the URL that can be used as source on the webview
*/
Expand Down

0 comments on commit 151e629

Please sign in to comment.