diff --git a/.changes/streaming-small-file-fix.md b/.changes/streaming-small-file-fix.md new file mode 100644 index 000000000..e4b316e40 --- /dev/null +++ b/.changes/streaming-small-file-fix.md @@ -0,0 +1,5 @@ +--- +"tauri": patch +--- + +Fix streaming of small files using the `asset` protocol. diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index e0fdcf88f..621069b77 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -350,7 +350,7 @@ impl WindowManager { 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 diff --git a/examples/streaming/src-tauri/src/main.rs b/examples/streaming/src-tauri/src/main.rs index 7f79143bd..57d860169 100644 --- a/examples/streaming/src-tauri/src/main.rs +++ b/examples/streaming/src-tauri/src/main.rs @@ -9,6 +9,7 @@ fn main() { use std::{ + cmp::min, io::{Read, Seek, SeekFrom}, path::PathBuf, process::{Command, Stdio}, @@ -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 diff --git a/tooling/api/src/tauri.ts b/tooling/api/src/tauri.ts index 3d00fa161..444bfa820 100644 --- a/tooling/api/src/tauri.ts +++ b/tooling/api/src/tauri.ts @@ -96,7 +96,7 @@ async function invoke(cmd: string, args: InvokeArgs = {}): Promise { * 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 */