File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,12 @@ export class Buffer extends Uint8Array {
2323 return result ;
2424 }
2525
26+ writeUInt8 ( value : u8 , offset : i32 = 0 ) : i32 {
27+ if ( < u32 > offset > this . dataLength ) throw new RangeError ( E_INDEXOUTOFRANGE ) ;
28+ store < u8 > ( this . dataStart + offset , value ) ;
29+ return offset + 1 ;
30+ }
31+
2632 writeInt8 ( value : i8 , offset : i32 = 0 ) : i32 {
2733 if ( < u32 > offset > this . dataLength ) throw new RangeError ( E_INDEXOUTOFRANGE ) ;
2834 store < i8 > ( this . dataStart + offset , value ) ;
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ declare class Buffer extends Uint8Array {
33 static alloc ( size : i32 ) : Buffer ;
44 /** This method allocates a new Buffer of indicated size. This is unsafe because the data is not zeroed. */
55 static allocUnsafe ( size : i32 ) : Buffer ;
6+ /** Writes an inputted u8 value to the buffer, at the desired offset. */
7+ writeUInt8 ( value :u8 , offset ?:i32 ) : i32 ;
68 /** Writes an inputted value to the buffer, at the desired offset. */
79 writeInt8 ( value :i8 , offset ?:i32 ) : i32 ;
810 /** Reads a signed integer at the designated offset. */
Original file line number Diff line number Diff line change @@ -43,6 +43,14 @@ describe("buffer", () => {
4343 // TODO: expectFn(() => { Buffer.allocUnsafe(BLOCK_MAXSIZE + 1); }).toThrow();
4444 } ) ;
4545
46+ test ( "#writeUInt8" , ( ) => {
47+ let buff = new Buffer ( 5 ) ;
48+ expect < i32 > ( buff . writeUInt8 ( 4 ) ) . toBe ( 1 ) ;
49+ expect < i32 > ( buff . writeUInt8 ( 252 , 4 ) ) . toBe ( 5 ) ;
50+ expect < u8 > ( buff [ 0 ] ) . toBe ( 4 ) ;
51+ expect < u8 > ( buff [ 4 ] ) . toBe ( 252 ) ;
52+ } ) ;
53+
4654 test ( "#writeInt8" , ( ) => {
4755 let buff = new Buffer ( 5 ) ;
4856 expect < i32 > ( buff . writeInt8 ( 9 ) ) . toBe ( 1 ) ;
@@ -65,5 +73,4 @@ describe("buffer", () => {
6573 // newBuff.readInt8(5);
6674 // }).toThrow();
6775 } )
68-
6976} ) ;
You can’t perform that action at this time.
0 commit comments