A flex buffer which behaves as a dynamic queue with a complete but limited Buffer API.
npm install queue-bufferQueue-Buffer
===================
A flex buffer which behaves as a dynamic queue with a complete but limited Buffer API.
- Queue-Buffer extends Flex-Buffer.
- Tested on Node 0.8-0.12, latest iojs on Mac, Linux and Windows.
- Entities in the queue are kept in order and the only operations on the collection are the addition of entities to the rear terminal position, known as enqueue(write), and removal of entities from the front terminal position, known as dequeue(read).



npm install queue-buffer -S
`
then
`javascript
QueueBuffer = require("queue-buffer");buf = new QueueBuffer(10);
buf.write([1, 2, 3, 4, 5]);
buf.writeInt32LE(14);
buf.read(5);
`API
QueueBuffer extends Flexbuffer, please see Flex-Buffer for more API info.- #### QueueBuffer.AUTO\_RELEASE_THRESHOLD
Auto release threshold(ms)
- type: { _number_ }
- #### constructor (arg, opts = {})
see FlexBuffer
- param:
arg { _number | Buffer | Array | string_ } The same arg as Buffer.
- param:
opts { _Object={}_ } options
- option:
autoRelease { _boolean_ } auto release useless space
- option:
autoReleaseThreshold { _number_ } auto release threshold(ms)
- #### free ()
Release useless space which has been read.
- #### move (size)
Move current read offset.
- param:
size { _number_ } number of bytes to move, can be negative.
- #### skip (size)
Move current read offset forward.
- param:
size { _number_ } number of bytes to skip
- #### rewind (size)
Move current read offset backward.
- param:
size { _number_ } number of bytes to rewind
- #### read (size) (alias: unshift, dequeue)
Read bytes from the head of the buffer.
- param:
size { _number_ } number of bytes to read
- return: { _Buffer_ }
data
- #### write (value, encoding = "utf8") (alias: push, enqueue)
see FlexBuffer
- param:
value { _number | string | Array | Buffer_ } The value to write
- param:
encoding { _string="utf8"_ } string encoding
- #### length
length of the data
- type: { _number_ }
__All the native Buffer API is wrapped. However, read* methods can only read data from head, with no
offset argument.__Test
`
npm test
`Benchmark
`
npm run benchmark
``io.js v2.4.0
- Read
- Buffer x 721,399 ops/sec ±0.52% (93 runs sampled)
- FlexBuffer x 656,232 ops/sec ±0.87% (90 runs sampled)
- wrapped native API
- Buffer x 17,708,521 ops/sec ±0.72% (93 runs sampled)
- FlexBuffer x 12,937,044 ops/sec ±0.70% (91 runs sampled)
io.js v3.0.0
> see https://github.com/dracupid/flex-buffer#benchmark for more info
- Read
- Buffer x 323,664 ops/sec ±0.68% (91 runs sampled)
- FlexBuffer x 320,600 ops/sec ±0.75% (93 runs sampled)
- wrapped native API
- Buffer x 9,614,392 ops/sec ±0.70% (92 runs sampled)
- FlexBuffer x 7,115,334 ops/sec ±0.68% (93 runs sampled)