Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusting offsets when inserting data #51

Open
anonghuser opened this issue Oct 16, 2023 · 0 comments
Open

Adjusting offsets when inserting data #51

anonghuser opened this issue Oct 16, 2023 · 0 comments

Comments

@anonghuser
Copy link

anonghuser commented Oct 16, 2023

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant