Fix stdin buffer splitting bug in bridge
This commit is contained in:
parent
c8020154e7
commit
dcd97a451f
1 changed files with 5 additions and 2 deletions
|
|
@ -128,11 +128,14 @@ function setContent(newContent: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// read json lines from stdin
|
// read json lines from stdin
|
||||||
|
let buffer = "";
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
for await (const chunk of Bun.stdin.stream()) {
|
for await (const chunk of Bun.stdin.stream()) {
|
||||||
const lines = decoder.decode(chunk).trim().split("\n");
|
buffer += decoder.decode(chunk);
|
||||||
|
const lines = buffer.split("\n");
|
||||||
|
buffer = lines.pop() ?? ""; // keep incomplete last line
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (!line) continue;
|
if (!line.trim()) continue;
|
||||||
try {
|
try {
|
||||||
const msg = JSON.parse(line);
|
const msg = JSON.parse(line);
|
||||||
switch (msg.type) {
|
switch (msg.type) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue