Skip to content

Commit 8061b23

Browse files
committed
Updated new bit-stream internal function and value documentation.
1 parent 0c44a39 commit 8061b23

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

arch/INFLATE.LUA

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function inflate(r, w, z)
99
local Z = z and 65536 or 32768
1010

1111
---New bit stream
12+
---@param rf function The reader function that returns a string of raw bytes
13+
---@return table A table full of functions to advance the bitstream (LSB first)
1214
function nbs(rf)
1315

1416
-- b = buffer
@@ -17,7 +19,8 @@ function inflate(r, w, z)
1719
-- bc = bit count
1820
local b, p, bb, bc = "", 1, 0, 0
1921

20-
---Need bits
22+
---Ensure at least the requested amount of bits are available in the stream, refilling from the byte stream if needed
23+
---@param n number The number of bits to have available in the bitstream
2124
function nb(n)
2225
while bc < n do
2326
if p > #b then
@@ -40,17 +43,21 @@ function inflate(r, w, z)
4043
end
4144
end
4245

43-
---Read bits
46+
---Read a certain number of bits from the bitstream
47+
---@param n number The amount of bits to read
48+
---@return number The bits that where read
4449
function rb(n)
4550
nb(n)
4651
local v = bb & ((1 << n) - 1)
4752
bb, bc = (bb >> n), bc - n
4853
return v
4954
end
5055

51-
---Align byte
56+
---Discard pending bits and align to the next byte boundary
5257
function ab() bb, bc = 0, 0 end
5358

59+
-- return.r = read bits
60+
-- return.a = align to byte
5461
return { r = rb, a = ab }
5562
end
5663

0 commit comments

Comments
 (0)