···6060 * It uses an existing array or binary string and advances a position index. */
6161class Stream {
62626363+ /**
6464+ * @param {Stream|array|string} enc data (will not be copied)
6565+ * @param {?number} pos starting position (mandatory when `end` is not a Stream)
6666+ */
6367 constructor(enc, pos) {
6468 if (enc instanceof Stream) {
6569 this.enc = enc.enc;
6670 this.pos = enc.pos;
6771 } else {
6868- // enc should be an array or a binary string
6972 this.enc = enc;
7073 this.pos = pos;
7174 }
7575+ if (typeof this.pos != 'number')
7676+ throw new Error('"pos" must be a numeric value');
7777+ if (typeof this.enc == 'string')
7878+ this.getRaw = pos => this.enc.charCodeAt(pos);
7979+ else if (typeof this.enc[0] == 'number')
8080+ this.getRaw = pos => this.enc[pos];
8181+ else
8282+ throw new Error('"enc" must be a numeric array or a string');
7283 }
7384 /** Get the byte at current position (and increment it) or at a specified position (and avoid moving current position).
7485 * @param {?number} pos read position if specified, else current position (and increment it) */
···7788 pos = this.pos++;
7889 if (pos >= this.enc.length)
7990 throw new Error('Requesting byte offset ' + pos + ' on a stream of length ' + this.enc.length);
8080- return (typeof this.enc == 'string') ? this.enc.charCodeAt(pos) : this.enc[pos];
9191+ return this.getRaw(pos);
8192 }
8293 /** Convert a single byte to an hexadcimal string (of length 2).
8394 * @param {number} b */