File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -27,4 +27,9 @@ export class Buffer extends Uint8Array {
2727 if ( < u32 > offset >= this . dataLength ) throw new RangeError ( E_INDEXOUTOFRANGE ) ;
2828 return load < i8 > ( this . dataStart + usize ( offset ) ) ;
2929 }
30+
31+ readUInt8 ( offset : i32 = 0 ) : u8 {
32+ if ( < u32 > offset > this . dataLength ) throw new RangeError ( E_INDEXOUTOFRANGE ) ;
33+ return load < u8 > ( this . dataStart + usize ( offset ) ) ;
34+ }
3035}
Original file line number Diff line number Diff line change @@ -5,4 +5,5 @@ declare class Buffer extends Uint8Array {
55 static allocUnsafe ( size : i32 ) : Buffer ;
66 /** Reads a signed integer at the designated offset. */
77 readInt8 ( offset ?: i32 ) : i8 ;
8+ readUInt8 ( offset ?: i32 ) : u8 ;
89}
Original file line number Diff line number Diff line change @@ -56,5 +56,21 @@ describe("buffer", () => {
5656 // let newBuff = new Buffer(1);
5757 // newBuff.readInt8(5);
5858 // }).toThrow();
59- } )
59+ } ) ;
60+
61+ test ( "#readUInt8" , ( ) => {
62+ let buff = new Buffer ( 10 ) ;
63+ buff [ 0 ] = - 2 ;
64+ buff [ 9 ] = 47 ;
65+ // Testing casting between u8 and i8.
66+ expect < u8 > ( buff . readUInt8 ( 0 ) ) . toBe ( 254 ) ;
67+ expect < u8 > ( buff . readUInt8 ( ) ) . toBe ( 254 ) ;
68+ // Testing offset
69+ expect < u8 > ( buff . readUInt8 ( 9 ) ) . toBe ( 47 ) ;
70+ // TODO:
71+ // expectFn(() => {
72+ // let newBuff = new Buffer(1);
73+ // newBuff.readUInt8(5);
74+ // }).toThrow();
75+ } ) ;
6076} ) ;
You can’t perform that action at this time.
0 commit comments