smart-buffer icon indicating copy to clipboard operation
smart-buffer copied to clipboard

Adjusting offsets when inserting data

Open anonghuser opened this issue 2 years ago • 0 comments

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

anonghuser avatar Oct 16 '23 12:10 anonghuser