1- export const BitStream : {
2- new ( ab : ArrayBuffer , mtl : boolean , opt_offset : number , opt_length : number ) : {
3- /**
4- * The bytes in the stream.
5- * @type {Uint8Array }
6- * @private
7- */
8- bytes : Uint8Array ;
9- /**
10- * The byte in the stream that we are currently on.
11- * @type {Number }
12- * @private
13- */
14- bytePtr : number ;
15- /**
16- * The bit in the current byte that we will read next (can have values 0 through 7).
17- * @type {Number }
18- * @private
19- */
20- bitPtr : number ;
21- /**
22- * An ever-increasing number.
23- * @type {Number }
24- * @private
25- */
26- bitsRead_ : number ;
27- peekBits : ( n : number , opt_movePointers : any ) => number ;
28- /**
29- * Returns how many bites have been read in the stream since the beginning of time.
30- * @returns {number }
31- */
32- getNumBitsRead ( ) : number ;
33- /**
34- * Returns how many bits are currently in the stream left to be read.
35- * @returns {number }
36- */
37- getNumBitsLeft ( ) : number ;
38- /**
39- * byte0 byte1 byte2 byte3
40- * 7......0 | 7......0 | 7......0 | 7......0
41- *
42- * The bit pointer starts at least-significant bit (0) of byte0 and moves left until it reaches
43- * bit7 of byte0, then jumps to bit0 of byte1, etc.
44- * @param {number } n The number of bits to peek, must be a positive integer.
45- * @param {boolean= } movePointers Whether to move the pointer, defaults false.
46- * @returns {number } The peeked bits, as an unsigned number.
47- */
48- peekBits_ltm ( n : number , opt_movePointers : any ) : number ;
49- /**
50- * byte0 byte1 byte2 byte3
51- * 7......0 | 7......0 | 7......0 | 7......0
52- *
53- * The bit pointer starts at bit7 of byte0 and moves right until it reaches
54- * bit0 of byte0, then goes to bit7 of byte1, etc.
55- * @param {number } n The number of bits to peek. Must be a positive integer.
56- * @param {boolean= } movePointers Whether to move the pointer, defaults false.
57- * @returns {number } The peeked bits, as an unsigned number.
58- */
59- peekBits_mtl ( n : number , opt_movePointers : any ) : number ;
60- /**
61- * Peek at 16 bits from current position in the buffer.
62- * Bit at (bytePtr,bitPtr) has the highest position in returning data.
63- * Taken from getbits.hpp in unrar.
64- * TODO: Move this out of BitStream and into unrar.
65- * @returns {number }
66- */
67- getBits ( ) : number ;
68- /**
69- * Reads n bits out of the stream, consuming them (moving the bit pointer).
70- * @param {number } n The number of bits to read. Must be a positive integer.
71- * @returns {number } The read bits, as an unsigned number.
72- */
73- readBits ( n : number ) : number ;
74- /**
75- * This returns n bytes as a sub-array, advancing the pointer if movePointers
76- * is true. Only use this for uncompressed blocks as this throws away remaining
77- * bits in the current byte.
78- * @param {number } n The number of bytes to peek. Must be a positive integer.
79- * @param {boolean= } movePointers Whether to move the pointer, defaults false.
80- * @returns {Uint8Array } The subarray.
81- */
82- peekBytes ( n : number , opt_movePointers : any ) : Uint8Array ;
83- /**
84- * @param {number } n The number of bytes to read.
85- * @returns {Uint8Array } The subarray.
86- */
87- readBytes ( n : number ) : Uint8Array ;
88- } ;
89- } ;
1+ /**
2+ * This object allows you to peek and consume bits and bytes out of a stream.
3+ * Note that this stream is optimized, and thus, will *NOT* throw an error if
4+ * the end of the stream is reached. Only use this in scenarios where you
5+ * already have all the bits you need.
6+ *
7+ * Bit reading always proceeds from the first byte in the buffer, to the
8+ * second byte, and so on. The MTL flag controls which bit is considered
9+ * first *inside* the byte.
10+ *
11+ * An Example for how Most-To-Least vs Least-to-Most mode works:
12+ *
13+ * If you have an ArrayBuffer with the following two Uint8s:
14+ * 185 (0b10111001) and 66 (0b01000010)
15+ * and you perform a series of readBits: 2 bits, then 3, then 5, then 6.
16+ *
17+ * A BitStream in "mtl" mode will yield the following:
18+ * - readBits(2) => 2 ('10')
19+ * - readBits(3) => 7 ('111')
20+ * - readBits(5) => 5 ('00101')
21+ * - readBits(6) => 2 ('000010')
22+ *
23+ * A BitStream in "ltm" mode will yield the following:
24+ * - readBits(2) => 1 ('01')
25+ * - readBits(3) => 6 ('110')
26+ * - readBits(5) => 21 ('10101')
27+ * - readBits(6) => 16 ('010000')
28+ */
29+ export class BitStream {
30+ /**
31+ * @param {ArrayBuffer } ab An ArrayBuffer object or a Uint8Array.
32+ * @param {boolean } mtl Whether the stream reads bits from the byte starting with the
33+ * most-significant-bit (bit 7) to least-significant (bit 0). False means the direction is
34+ * from least-significant-bit (bit 0) to most-significant (bit 7).
35+ * @param {Number } opt_offset The offset into the ArrayBuffer
36+ * @param {Number } opt_length The length of this BitStream
37+ */
38+ constructor ( ab : ArrayBuffer , mtl : boolean , opt_offset : number , opt_length : number ) ;
39+ /**
40+ * The bytes in the stream.
41+ * @type {Uint8Array }
42+ * @private
43+ */
44+ private bytes ;
45+ /**
46+ * The byte in the stream that we are currently on.
47+ * @type {Number }
48+ * @private
49+ */
50+ private bytePtr ;
51+ /**
52+ * The bit in the current byte that we will read next (can have values 0 through 7).
53+ * @type {Number }
54+ * @private
55+ */
56+ private bitPtr ;
57+ /**
58+ * An ever-increasing number.
59+ * @type {Number }
60+ * @private
61+ */
62+ private bitsRead_ ;
63+ peekBits : ( n : number , opt_movePointers : any ) => number ;
64+ /**
65+ * Returns how many bites have been read in the stream since the beginning of time.
66+ * @returns {number }
67+ */
68+ getNumBitsRead ( ) : number ;
69+ /**
70+ * Returns how many bits are currently in the stream left to be read.
71+ * @returns {number }
72+ */
73+ getNumBitsLeft ( ) : number ;
74+ /**
75+ * byte0 byte1 byte2 byte3
76+ * 7......0 | 7......0 | 7......0 | 7......0
77+ *
78+ * The bit pointer starts at least-significant bit (0) of byte0 and moves left until it reaches
79+ * bit7 of byte0, then jumps to bit0 of byte1, etc.
80+ * @param {number } n The number of bits to peek, must be a positive integer.
81+ * @param {boolean= } movePointers Whether to move the pointer, defaults false.
82+ * @returns {number } The peeked bits, as an unsigned number.
83+ */
84+ peekBits_ltm ( n : number , opt_movePointers : any ) : number ;
85+ /**
86+ * byte0 byte1 byte2 byte3
87+ * 7......0 | 7......0 | 7......0 | 7......0
88+ *
89+ * The bit pointer starts at bit7 of byte0 and moves right until it reaches
90+ * bit0 of byte0, then goes to bit7 of byte1, etc.
91+ * @param {number } n The number of bits to peek. Must be a positive integer.
92+ * @param {boolean= } movePointers Whether to move the pointer, defaults false.
93+ * @returns {number } The peeked bits, as an unsigned number.
94+ */
95+ peekBits_mtl ( n : number , opt_movePointers : any ) : number ;
96+ /**
97+ * Peek at 16 bits from current position in the buffer.
98+ * Bit at (bytePtr,bitPtr) has the highest position in returning data.
99+ * Taken from getbits.hpp in unrar.
100+ * TODO: Move this out of BitStream and into unrar.
101+ * @returns {number }
102+ */
103+ getBits ( ) : number ;
104+ /**
105+ * Reads n bits out of the stream, consuming them (moving the bit pointer).
106+ * @param {number } n The number of bits to read. Must be a positive integer.
107+ * @returns {number } The read bits, as an unsigned number.
108+ */
109+ readBits ( n : number ) : number ;
110+ /**
111+ * This returns n bytes as a sub-array, advancing the pointer if movePointers
112+ * is true. Only use this for uncompressed blocks as this throws away remaining
113+ * bits in the current byte.
114+ * @param {number } n The number of bytes to peek. Must be a positive integer.
115+ * @param {boolean= } movePointers Whether to move the pointer, defaults false.
116+ * @returns {Uint8Array } The subarray.
117+ */
118+ peekBytes ( n : number , opt_movePointers : any ) : Uint8Array ;
119+ /**
120+ * @param {number } n The number of bytes to read.
121+ * @returns {Uint8Array } The subarray.
122+ */
123+ readBytes ( n : number ) : Uint8Array ;
124+ }
90125//# sourceMappingURL=bitstream.d.ts.map
0 commit comments