Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Oct 21, 2024
1 parent 1268005 commit a74539f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugins/fs/api-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions plugins/fs/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions plugins/fs/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down

0 comments on commit a74539f

Please sign in to comment.