-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decode non-ANSII strings only on backend
Signed-off-by: xychen <xychen@listenai.com>
- Loading branch information
xychen
committed
Jun 11, 2024
1 parent
922597a
commit d24e227
Showing
2 changed files
with
15 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { invoke } from '@tauri-apps/api/core'; | ||
|
||
export async function decode(data: ArrayLike<number>): Promise<string> { | ||
// IPC is expensive, so we should avoid it if possible. | ||
const isPureAscii = Array.from(data).every((c) => c < 0x80); | ||
if (isPureAscii) { | ||
return new TextDecoder().decode(new Uint8Array(data)); | ||
} | ||
|
||
return await invoke('decode', { data }); | ||
} |