我需要一种方法来存储写入stream中的最后0xFFF字节在某种缓冲区中

我正在使用stream在Node.JS中进行解压缩例程,但是我需要将写入stream的最后0xFFF字节保存在临时缓冲区中。

我有一些代码可以工作,但它似乎效率低下,是否有与Node.js 缓冲区对象的任何等效的?

var arr = Array(0xFFF) // allocate an array to use as a buffer function writeByte(byte, stream){ arr.shift() // remove the first byte in the buffer arr.push(byte) // push the new byte onto the end stream.write([byte]) // send the byte to the stream }