@tauri-apps/plugin-fs
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -93,2 +93,15 @@ export { BaseDirectory } from '@tauri-apps/api/path'; | ||
} | ||
// https://gist.github.com/zapthedingbat/38ebfbedd98396624e5b5f2ff462611d | ||
/** Converts a big-endian eight byte array to number */ | ||
function fromBytes(buffer) { | ||
const bytes = new Uint8ClampedArray(buffer); | ||
const size = bytes.byteLength; | ||
let x = 0; | ||
for (let i = 0; i < size; i++) { | ||
const byte = bytes[i]; | ||
x *= 0x100; | ||
x += byte; | ||
} | ||
return x; | ||
} | ||
/** | ||
@@ -135,7 +148,14 @@ * The Tauri abstraction for reading and writing files. | ||
} | ||
const [data, nread] = await invoke('plugin:fs|read', { | ||
const data = await invoke('plugin:fs|read', { | ||
rid: this.rid, | ||
len: buffer.byteLength | ||
}); | ||
buffer.set(data); | ||
// Rust side will never return an empty array for this command and | ||
// ensure there is at least 8 elements there. | ||
// | ||
// This is an optimization to include the number of read bytes (as bigendian bytes) | ||
// at the end of returned array to avoid serialization overhead of separate values. | ||
const nread = fromBytes(data.slice(-8)); | ||
const bytes = data instanceof ArrayBuffer ? new Uint8Array(data) : data; | ||
buffer.set(bytes.slice(0, bytes.length - 8)); | ||
return nread === 0 ? null : nread; | ||
@@ -621,6 +641,8 @@ } | ||
} | ||
await invoke('plugin:fs|write_text_file', { | ||
path: path instanceof URL ? path.toString() : path, | ||
data, | ||
options | ||
const encoder = new TextEncoder(); | ||
await invoke('plugin:fs|write_text_file', encoder.encode(data), { | ||
headers: { | ||
path: path instanceof URL ? path.toString() : path, | ||
options: JSON.stringify(options) | ||
} | ||
}); | ||
@@ -627,0 +649,0 @@ } |
{ | ||
"name": "@tauri-apps/plugin-fs", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Access the file system.", | ||
@@ -5,0 +5,0 @@ "license": "MIT OR Apache-2.0", |
@@ -15,3 +15,3 @@  | ||
_This plugin requires a Rust version of at least **1.78**_ | ||
_This plugin requires a Rust version of at least **1.77.2**_ | ||
@@ -18,0 +18,0 @@ There are three general methods of installation that we can recommend. |
Sorry, the diff of this file is not supported yet
87414
2309