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

Add readSkip and writeSkip methods #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lukehorvat
Copy link

This PR adds convenience methods for skipping when reading/writing.

Resolves #46.

@@ -614,26 +614,44 @@ describe('Reading/Writing To/From SmartBuffer', () => {
});

describe('Skipping around data', () => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to explain the diff noise in this file:

There was already this Skipping around data test block that had tests manipulating the readOffset to skip. I replaced this block's tests with ones for readSkip/writeSkip, and moved the old tests* to the Setting write and read offsets block, since that felt like the more appropriate place for them.

* Actually, in the case of the Should throw an error when attempting to skip more bytes than actually exist test, I removed it completely because you already had other tests that covered it.

*/
readSkip(length: number): SmartBuffer {
checkLengthValue(length);
this.readOffset += length;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally I had this so that it would be more similar to writeSkip:

Suggested change
this.readOffset += length;
this.readBuffer(length); // Ignore the returned buffer value

But it did not throw an error if length went beyond the bounds of the buffer, so I changed it.

Let me know if you would prefer it to not throw an error though.

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

Successfully merging this pull request may close these issues.

Convenience method to skip bytes?
1 participant