xlsepiphone
2023-07-26 16:01:12 +08:00
更新了下代码,已结解决了:
```typescript
readBytes(length: number = 1): Buffer {
// 按照指定长度创建缓冲区
let buffer: Buffer = Buffer.alloc(length)
// 已经读取的字节长度
let readedLength = 0
for (;;) {
// 如果已经读取的字节长度等于指定的长度,则退出循环
if (readedLength === length) {
break
}
// 计算出可以读取的字节长度
const readableLength = Math.min(length - readedLength, this.reader.readableLength)
// 读取指定长度的字节
const readedBuffer = this.reader.read(readableLength)
// 填充到缓冲区中
buffer.fill(readedBuffer, readedLength)
// 更新已经读取的字节长度
readedLength += readableLength
}
return buffer
}
```