Repository: tauri
Issue: [bug] Memory leaks when reading files
Labels: type: bug,scope: core,priority: 1 high,status: needs triage

### Describe the bug


When reading larger files (140MB+) the code never gets past reading them. Tauri tries to eat all of my memory and then freezes/crashes.
I am on windows and my system has 16GB of RAM and when trying to read 140MB file Tauri tries to eat all of it,  going up to 11,5 GB of RAM usage (I use task manager for measuring). Then it propably goes out of memory and crashes.

Even for smaller files like 50-80MB it uses like 2-5 GB of RAM on my machine.

Tested on v1 (readBinaryFile) and also on beta v2 (readFile). 

### Reproduction

I use readBinaryFile() to read the contents of a file. To reproduce create new tauri app with `sh <(curl https://create.tauri.app/sh)` and use this minimal code to try to read a file.
```js
import { readBinaryFile } from '@tauri-apps/api/fs';
import { open } from '@tauri-apps/api/dialog';

async function attemptToRead(){
    const selected = await open({multiple: false});
    if (typeof selected != "string"){
      console.log(typeof selected + " is not a string");
      return;
    }

    console.log("Start reading");
    const content = await readBinaryFile(selected);
    console.log("Read succesfull"); // never logged 
}
  ```
  
  I also tried it in the v2 beta version with essentially the same code and got the same result - exceptionally high memory usage followed by crash.  `sh <(curl https://create.tauri.app/sh) --beta`
```js
import { readFile } from '@tauri-apps/plugin-fs';
import { open } from '@tauri-apps/plugin-dialog';

async function attemptToRead() {
  const selected = await open({
    multiple: false,
    directory: false,
  });
  if (!selected?.path){
    console.log("bad select");
    return
  }
  console.log("Started reading");
  const result = await readFile(selected.path);
  console.log("Finished reading");
}
```

### Expected behavior

Not using 11+ gigs of RAM to read 140MB file.

### Full `tauri info` output

```text
V1:
[✔] Environment
    - OS: Windows 10.0.22631 X64
    ✔ WebView2: 122.0.2365.80
    ✔ MSVC: Visual Studio Build Tools 2022
    ✔ rustc: 1.76.0 (07dca489a 2024-02-04)
    ✔ cargo: 1.76.0 (c84b36747 2024-01-18)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 20.11.0
    - yarn: 1.22.22
    - npm: 10.2.4

[-] Packages
    - tauri [RUST]: 1.6.1
    - tauri-build [RUST]: 1.5.1
    - wry [RUST]: 0.24.7
    - tao [RUST]: 0.16.7
    - @tauri-apps/api [NPM]: 1.5.3
    - @tauri-apps/cli [NPM]: 1.5.11

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../dist
    - devPath: http://localhost:1420/
    - framework: Svelte
    - bundler: Vite

V2:
[✔] Environment
    - OS: Windows 10.0.22631 X64
    ✔ WebView2: 122.0.2365.80
    ✔ MSVC: Visual Studio Build Tools 2022
    ✔ rustc: 1.76.0 (07dca489a 2024-02-04)
    ✔ cargo: 1.76.0 (c84b36747 2024-01-18)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 20.11.0
    - yarn: 1.22.22
    - npm: 10.2.4

[-] Packages
    - tauri [RUST]: 2.0.0-beta.11
    - tauri-build [RUST]: 2.0.0-beta.9
    - wry [RUST]: 0.37.0
    - tao [RUST]: 0.26.1
    - @tauri-apps/api [NPM]: 2.0.0-beta.5
    - @tauri-apps/cli [NPM]: 2.0.0-beta.9

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - bundler: Vite
```


### Stack trace

_No response_

### Additional context

I tested this with only PDF files but I dont think this issue is specific to them. Here are the pdfs I used for testing:
The pdfs are just pdf specification merged with it self bunch of times.

141 MB: [https://mega.nz/file/WmwCTZqL#Jt30rUsjd1F5QG5prnKN5wsRm1J4MesurpmQ7XnAi5g](https://mega.nz/file/WmwCTZqL#Jt30rUsjd1F5QG5prnKN5wsRm1J4MesurpmQ7XnAi5g)
215 MB: [https://mega.nz/file/ivQlWDrR#EdscaHf0YiBkPaR5oqZJPNuLb84D4VppEmUAsL9W76g](https://mega.nz/file/ivQlWDrR#EdscaHf0YiBkPaR5oqZJPNuLb84D4VppEmUAsL9W76g)
350 MB: [https://mega.nz/file/3nwmUJqD#hPqPRuqTlvnahbINfWZsV2BibiWCuMkulGLU4_Pn8eY](https://mega.nz/file/3nwmUJqD#hPqPRuqTlvnahbINfWZsV2BibiWCuMkulGLU4_Pn8eY)

Am a doing something wrong when reading the files? Is there a workaround?