@@ -173,14 +173,18 @@ export class DynamicBuffer {
173173 * @param encoding The character encoding to use, default from buffer encoding.
174174 * @returns Number of bytes written.
175175 */
176- write ( data : string , offset ?: number , length ?: number , encoding ?: BufferEncoding ) {
177- const start = offset || 0 ;
178- if ( start < 0 ) {
176+ write (
177+ data : string ,
178+ offset : number = 0 ,
179+ length : number = data . length ,
180+ encoding : BufferEncoding | undefined = this . encoding ,
181+ ) {
182+ if ( offset < 0 ) {
179183 throw new RangeError ( 'The value of "offset" is out of range.' ) ;
180184 }
181185
182- const count = this . writeData ( data , start , length , encoding ) ;
183- this . used = start + count ;
186+ const count = this . writeData ( data , offset , length , encoding ) ;
187+ this . used = offset + count ;
184188
185189 return count ;
186190 }
@@ -223,7 +227,7 @@ export class DynamicBuffer {
223227 * @param end The byte offset to stop coping at (not inclusive), default used bytes offset.
224228 * @returns The new buffer contains the written data in this buffer.
225229 */
226- toBuffer ( start ? : number , end ? : number ) {
230+ toBuffer ( start : number = 0 , end : number = this . used ) {
227231 if ( ! this . buffer || this . used === 0 ) {
228232 return Buffer . alloc ( 0 ) ;
229233 }
@@ -253,7 +257,11 @@ export class DynamicBuffer {
253257 * @param end The byte offset to stop decoding at (not inclusive), default used bytes offset.
254258 * @returns The string decodes from buffer with the specified range.
255259 */
256- toString ( encoding ?: BufferEncoding , start ?: number , end ?: number ) {
260+ toString (
261+ encoding : BufferEncoding | undefined = this . encoding ,
262+ start : number = 0 ,
263+ end : number = this . used ,
264+ ) {
257265 if ( ! this . buffer || this . used === 0 ) {
258266 return '' ;
259267 }
@@ -263,7 +271,7 @@ export class DynamicBuffer {
263271 return '' ;
264272 }
265273
266- return this . buffer . toString ( encoding || this . encoding , startOffset , endOffset ) ;
274+ return this . buffer . toString ( encoding , startOffset , endOffset ) ;
267275 }
268276
269277 /**
0 commit comments