smart-buffer
smart-buffer copied to clipboard
Adjusting offsets when inserting data
Currently the writeOffset is always adjusted and readOffset is never adjusted.
I think a more sensible thing is to adjust both, but not if the insertion offset is after them.
import { SmartBuffer as SB } from 'smart-buffer';
console.log(SB.fromBuffer(Buffer.from('abcd')).insertString('XX', 0).writeOffset); // 2 - ok
console.log(SB.fromBuffer(Buffer.from('abcd')).insertString('XX', 1).writeOffset); // 2 - should be 0
console.log(SB.fromBuffer(Buffer.from('abcd')).insertString('XX', 0).readOffset); // 0 - should be 2
console.log(SB.fromBuffer(Buffer.from('abcd')).insertString('XX', 1).readOffset); // 0 - ok