fix(core): streaming of small files using asset://, closes #2854 (#3039)

This commit is contained in:
Lucas Fernandes Nogueira
2021-12-09 01:24:11 -03:00
committed by GitHub
parent fb2b9a52f5
commit 151e629ebf
4 changed files with 9 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
---
"tauri": patch
---
Fix streaming of small files using the `asset` protocol.

View File

@@ -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

View File

@@ -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

View File

@@ -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
*/