@@ -2,6 +2,9 @@ import { constants } from 'buffer';
22
33import { DynamicBufferIterator } from './iterator' ;
44
5+ /**
6+ * The character encoding that is supported by Node.js, copy from Node.js Buffer module.
7+ */
58type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2'
69 | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex' ;
710
@@ -89,6 +92,12 @@ export class DynamicBuffer {
8992
9093 /**
9194 * Returns the number of the used bytes in this buffer.
95+ *
96+ * ```js
97+ * buf.append('Hello');
98+ * console.log(buf.length);
99+ * // 5
100+ * ```
92101 */
93102 get length ( ) {
94103 return this . used ;
@@ -179,6 +188,12 @@ export class DynamicBuffer {
179188 /**
180189 * Copies the buffer data onto a new `Buffer` instance without unused parts.
181190 *
191+ * ```js
192+ * buf.append('Hello');
193+ * console.log(buf.toBuffer());
194+ * // <Buffer 48 65 6c 6c 6f>
195+ * ```
196+ *
182197 * @param start The byte offset to start coping at, default 0.
183198 * @param end The byte offset to stop coping at (not inclusive), default used bytes offset.
184199 * @returns The new buffer contains the written data in this buffer.
@@ -202,6 +217,12 @@ export class DynamicBuffer {
202217 /**
203218 * Decodes buffer to a string with the specified character encoding and range.
204219 *
220+ * ```js
221+ * buf.append('Hello');
222+ * console.log(buf.toString());
223+ * // Hello
224+ * ```
225+ *
205226 * @param encoding The character encoding to use, default from buffer encoding.
206227 * @param start The byte offset to start decoding at, default 0.
207228 * @param end The byte offset to stop decoding at (not inclusive), default used bytes offset.
0 commit comments