private _extractData(chunk: Buffer): Buffer {
// 读取数据包大小到 readHeader
chunk.copy(this.readHeader, 0, 0, chunk.length);
// 数据包大小
let bodySize: number = this.readHeader.readInt32BE(0);
let body: Buffer = Buffer.alloc(bodySize);
// 拷贝真正数据
chunk.copy(body, 0, this.readHeader.length, chunk.length);
return body;
}
这里 this.readHeader.readInt32BE(0)
在遇到内容较长时经常会返回负数值:
RangeError [ERR_INVALID_ARG_VALUE]: The argument 'size' is invalid. Received -443709664
at Function.alloc (node:buffer:372:3)
这个 Buffer
偏移量该如何纠正