Add readSkip and writeSkip methods#48
Add readSkip and writeSkip methods#48lukehorvat wants to merge 1 commit intoJoshGlazebrook:masterfrom
readSkip and writeSkip methods#48Conversation
| @@ -614,26 +614,44 @@ describe('Reading/Writing To/From SmartBuffer', () => { | |||
| }); | |||
|
|
|||
| describe('Skipping around data', () => { | |||
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Originally I had this so that it would be more similar to writeSkip:
| 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.
This PR adds convenience methods for skipping when reading/writing.
Resolves #46.