Skip to content

Commit

Permalink
优化流传输时分包导致的解析异常
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinlic committed Apr 1, 2024
1 parent 97fdd89 commit fa6cd6d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/api/controllers/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,21 @@ async function receiveStream(model: string, convId: string, stream: any) {
: "";
}
};
let temp = Buffer.from([]);
// 将流数据传到转换器,每个buffer去除数据头5字节
stream.on("data", (buffer: Buffer) => {
const parts: Buffer[] = [];
let length = 0;
let sizeLength = 0;
let i = 0;
if(buffer[buffer.length - 1] != 125) {
temp = Buffer.concat([temp, buffer]);
return;
}
else if(temp.length > 0) {
buffer = Buffer.concat([temp, buffer]);
temp = Buffer.from([]);
}
for (i = 0; i < buffer.byteLength; i++) {
const byte = buffer.readUInt8(i);
if (byte == 0x00 || byte == 0x02) {
Expand Down

0 comments on commit fa6cd6d

Please sign in to comment.