pull/1962/head
amrbashir 9 months ago
parent 12680059f6
commit a74539f994
No known key found for this signature in database
GPG Key ID: BBD7A47A2003FF33

File diff suppressed because one or more lines are too long

@ -813,6 +813,11 @@ async function readTextFileLines(
const bytes =
arr instanceof ArrayBuffer ? new Uint8Array(arr) : Uint8Array.from(arr)
// Rust side will never return an empty array for this command and
// ensure there is at least one elements there.
//
// This is an optimization to include wether we finished iteration or not (1 or 0)
// at the end of returned array to avoid serialization overhead of separate values.
const done = bytes[bytes.byteLength - 1] === 1
if (done) {
@ -821,8 +826,7 @@ async function readTextFileLines(
return { value: null, done }
}
const data = bytes.slice(0, bytes.byteLength)
const line = data.byteLength !== 0 ? new TextDecoder().decode(data) : ''
const line = new TextDecoder().decode(bytes.slice(0, bytes.byteLength))
return {
value: line,

@ -421,6 +421,10 @@ pub async fn read_text_file_lines_next<R: Runtime>(
let ret = StdLinesResource::with_lock(&lines, |lines| -> CommandResult<Vec<u8>> {
let mut buf = Vec::new();
// This is an optimization over `BufReader::lines` so we can use `tauri::ipc::Response`
// and also include wether we finished iteration or not (1 or 0)
// at the end of returned vector so we can use `tauri::ipc::Response`
// and avoid serialization overhead of separate values.
match lines.read_until(b'\n', &mut buf) {
Ok(0) => {
resource_table.close(rid)?;

Loading…
Cancel
Save