mirror of
https://github.com/LLM-Red-Team/step-free-api.git
synced 2026-01-13 07:00:39 +08:00
优化流传输时分包导致的解析异常
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user