···5656 }
5757}
58585959+/** Class to manage a stream of bytes, with a zero-copy approach.
6060+ * It uses an existing array or binary string and advances a position index. */
5961class Stream {
60626163 constructor(enc, pos) {
···6870 this.pos = pos;
6971 }
7072 }
7373+ /** Get the byte at current position (and increment it) or at a specified position (and avoid moving current position).
7474+ * @param {?number} pos read position if specified, else current position (and increment it) */
7175 get(pos) {
7276 if (pos === undefined)
7377 pos = this.pos++;
···7579 throw new Error('Requesting byte offset ' + pos + ' on a stream of length ' + this.enc.length);
7680 return (typeof this.enc == 'string') ? this.enc.charCodeAt(pos) : this.enc[pos];
7781 }
7878- hexByte(b) {
8282+ /** Convert a single byte to an hexadcimal string (of length 2).
8383+ * @param {number} b */
8484+ static hexByte(b) {
7985 return hexDigits.charAt((b >> 4) & 0xF) + hexDigits.charAt(b & 0xF);
8086 }
8181- /** Hexadecimal dump.
8282- * @param type 'raw', 'byte' or 'dump' */
8787+ /** Hexadecimal dump of a specified region of the stream.
8888+ * @param {number} start starting position (included)
8989+ * @param {number} end ending position (excluded)
9090+ * @param {string} type 'raw', 'byte' or 'dump' */
8391 hexDump(start, end, type = 'dump') {
8492 let s = '';
8593 for (let i = start; i < end; ++i) {
···95103 }
96104 return s;
97105 }
106106+ /** Base-64 dump of a specified region of the stream.
107107+ * @param {number} start starting position (included)
108108+ * @param {number} end ending position (excluded) */
98109 b64Dump(start, end) {
99110 let extra = (end - start) % 3,
100111 s = '',