[WIP] added reverseBitOrder func (not tested)
This commit is contained in:
@@ -40,6 +40,24 @@ local function uintb2num(uintb, littleEndian)
|
||||
return num
|
||||
end
|
||||
|
||||
---Reverses bit order in given string (converting bitwise little-endian order to normal).
|
||||
---@param bytes string bytes
|
||||
---@return string
|
||||
local function reverseBitOrder(bytes)
|
||||
local result = ''
|
||||
for i = 1,#bytes do
|
||||
local byte = string.byte(bytes:sub(i,i))
|
||||
local revByte = 0
|
||||
for j = 1,8 do
|
||||
local bit = byte % 2
|
||||
revByte = revByte * 2 + bit
|
||||
byte = math.floor(byte / 2)
|
||||
end
|
||||
result = result .. string.char(revByte)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
---Decompresses [GZIP](https://en.wikipedia.org/wiki/Gzip) format.
|
||||
---@param zip string bytes
|
||||
---@return string bytes
|
||||
@@ -71,12 +89,14 @@ local function decompressGzip(zip)
|
||||
cursor = cursor + 2
|
||||
end
|
||||
|
||||
local compressedData = zip:sub(cursor, #zip-8)
|
||||
print('compressedData', compressedData)
|
||||
print(dump(compressedData))
|
||||
local data = compressedData -- getting compressed data without trailing 8 bytes (CRC32, ISIZE)
|
||||
print('expirement:')
|
||||
local str = 'BC'
|
||||
print(str, reverseBitOrder(str))
|
||||
|
||||
return core.decompress(data, 'deflate', 1)
|
||||
local compressedData = zip:sub(cursor, #zip-8) -- getting compressed data without trailing 8 bytes (CRC32, ISIZE)
|
||||
local reversedCompressedData = reverseBitOrder(compressedData)
|
||||
--print(dump(reversedCompressedData))
|
||||
return core.decompress(reversedCompressedData, 'deflate', 1)
|
||||
end
|
||||
|
||||
---Converts (scaling) 16-bit unsigned integer to 8-bit unsigned integer.
|
||||
|
||||
Reference in New Issue
Block a user