enhance(fs):缩短文件读取流程,减少内存复制。
This commit is contained in:
		
							
								
								
									
										26
									
								
								src-tauri/Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										26
									
								
								src-tauri/Cargo.lock
									
									
									
										generated
									
									
									
								
							| @@ -332,6 +332,7 @@ dependencies = [ | |||||||
|  "chrono", |  "chrono", | ||||||
|  "image", |  "image", | ||||||
|  "md-5", |  "md-5", | ||||||
|  |  "mime_guess", | ||||||
|  "mountpoints", |  "mountpoints", | ||||||
|  "once_cell", |  "once_cell", | ||||||
|  "serde", |  "serde", | ||||||
| @@ -1617,6 +1618,22 @@ dependencies = [ | |||||||
|  "autocfg", |  "autocfg", | ||||||
| ] | ] | ||||||
|  |  | ||||||
|  | [[package]] | ||||||
|  | name = "mime" | ||||||
|  | version = "0.3.17" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" | ||||||
|  |  | ||||||
|  | [[package]] | ||||||
|  | name = "mime_guess" | ||||||
|  | version = "2.0.4" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" | ||||||
|  | dependencies = [ | ||||||
|  |  "mime", | ||||||
|  |  "unicase", | ||||||
|  | ] | ||||||
|  |  | ||||||
| [[package]] | [[package]] | ||||||
| name = "miniz_oxide" | name = "miniz_oxide" | ||||||
| version = "0.6.2" | version = "0.6.2" | ||||||
| @@ -3208,6 +3225,15 @@ version = "1.16.0" | |||||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
| checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" | checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" | ||||||
|  |  | ||||||
|  | [[package]] | ||||||
|  | name = "unicase" | ||||||
|  | version = "2.6.0" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" | ||||||
|  | dependencies = [ | ||||||
|  |  "version_check", | ||||||
|  | ] | ||||||
|  |  | ||||||
| [[package]] | [[package]] | ||||||
| name = "unicode-bidi" | name = "unicode-bidi" | ||||||
| version = "0.3.10" | version = "0.3.10" | ||||||
|   | |||||||
| @@ -28,6 +28,7 @@ uuid = "1.3.0" | |||||||
| mountpoints = "0.2.1" | mountpoints = "0.2.1" | ||||||
| md-5 = "0.10.5" | md-5 = "0.10.5" | ||||||
| urlencoding = "2.1.2" | urlencoding = "2.1.2" | ||||||
|  | mime_guess = "2.0.4" | ||||||
|  |  | ||||||
| [features] | [features] | ||||||
| # this feature is used for production builds or when `devPath` points to the filesystem | # this feature is used for production builds or when `devPath` points to the filesystem | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| use std::{error::Error, io::Cursor, path::Path}; | use std::{error::Error, fs, path::Path}; | ||||||
|  |  | ||||||
| use tauri::{ | use tauri::{ | ||||||
|     http::{Request, Response, ResponseBuilder}, |     http::{Request, Response, ResponseBuilder}, | ||||||
| @@ -32,12 +32,11 @@ pub fn comic_protocol<R: Runtime>( | |||||||
|             .body(Vec::new()); |             .body(Vec::new()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     let content = image::io::Reader::open(path)?.decode()?; |     let mimetype = mime_guess::from_path(path); | ||||||
|     let mut bytes: Vec<u8> = Vec::new(); |     let content = fs::read(path)?; | ||||||
|     content.write_to(&mut Cursor::new(&mut bytes), image::ImageOutputFormat::Png)?; |  | ||||||
|  |  | ||||||
|     response_builder |     response_builder | ||||||
|         .mimetype("image/png") |         .mimetype(mimetype.first_or_text_plain().essence_str()) | ||||||
|         .status(200) |         .status(200) | ||||||
|         .body(bytes) |         .body(content) | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user