@@ -336,7 +336,7 @@ pub fn read_file<R: Runtime>(
336336 command_scope : CommandScope < Entry > ,
337337 path : SafePathBuf ,
338338 options : Option < BaseOptions > ,
339- ) -> CommandResult < Vec < u8 > > {
339+ ) -> CommandResult < tauri :: ipc :: Response > {
340340 let resolved_path = resolve_path (
341341 & webview,
342342 & global_scope,
@@ -345,6 +345,7 @@ pub fn read_file<R: Runtime>(
345345 options. as_ref ( ) . and_then ( |o| o. base_dir ) ,
346346 ) ?;
347347 std:: fs:: read ( & resolved_path)
348+ . map ( tauri:: ipc:: Response :: new)
348349 . map_err ( |e| {
349350 format ! (
350351 "failed to read file at path: {} with error: {e}" ,
@@ -756,11 +757,27 @@ pub fn write_file<R: Runtime>(
756757 webview : Webview < R > ,
757758 global_scope : GlobalScope < Entry > ,
758759 command_scope : CommandScope < Entry > ,
759- path : SafePathBuf ,
760- data : Vec < u8 > ,
761- options : Option < WriteFileOptions > ,
760+ request : tauri:: ipc:: Request < ' _ > ,
762761) -> CommandResult < ( ) > {
763- write_file_inner ( webview, & global_scope, & command_scope, path, & data, options)
762+ if let tauri:: ipc:: InvokeBody :: Raw ( data) = request. body ( ) {
763+ let path = request
764+ . headers ( )
765+ . get ( "path" )
766+ . ok_or_else ( || anyhow:: anyhow!( "missing file path" ) . into ( ) )
767+ . and_then ( |p| {
768+ p. to_str ( )
769+ . map_err ( |e| anyhow:: anyhow!( "invalid path: {e}" ) . into ( ) )
770+ } )
771+ . and_then ( |p| SafePathBuf :: new ( p. into ( ) ) . map_err ( CommandError :: from) ) ?;
772+ let options = request
773+ . headers ( )
774+ . get ( "options" )
775+ . and_then ( |p| p. to_str ( ) . ok ( ) )
776+ . and_then ( |opts| serde_json:: from_str ( opts) . ok ( ) ) ;
777+ write_file_inner ( webview, & global_scope, & command_scope, path, data, options)
778+ } else {
779+ Err ( anyhow:: anyhow!( "unexpected invoke body" ) . into ( ) )
780+ }
764781}
765782
766783#[ tauri:: command]
0 commit comments