Skip to content

Commit 49a2df9

Browse files
authored
feat: add IOBuffer.back() (#52)
1 parent f212a62 commit 49a2df9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/IOBuffer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ export class IOBuffer {
141141
return this;
142142
}
143143

144+
/**
145+
* Move the pointer n bytes backward.
146+
* @param n - Number of bytes to move back.
147+
*/
148+
public back(n = 1): this {
149+
this.offset -= n;
150+
return this;
151+
}
152+
144153
/**
145154
* Move the pointer to the given offset.
146155
* @param offset

src/__tests__/core.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ describe('core methods', () => {
4545
expect(buffer.offset).toBe(8);
4646
});
4747

48+
it('back', () => {
49+
buffer.offset = 8;
50+
buffer.back(5);
51+
expect(buffer.offset).toBe(3);
52+
buffer.back(1);
53+
buffer.back();
54+
expect(buffer.offset).toBe(1);
55+
buffer.back();
56+
expect(buffer.offset).toBe(0);
57+
});
58+
4859
it('seek', () => {
4960
buffer.seek(0);
5061
expect(buffer.offset).toBe(0);

0 commit comments

Comments
 (0)