[WIP] added reverseBitOrder func (not tested)
This commit is contained in:
@@ -40,6 +40,24 @@ local function uintb2num(uintb, littleEndian)
|
|||||||
return num
|
return num
|
||||||
end
|
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.
|
---Decompresses [GZIP](https://en.wikipedia.org/wiki/Gzip) format.
|
||||||
---@param zip string bytes
|
---@param zip string bytes
|
||||||
---@return string bytes
|
---@return string bytes
|
||||||
@@ -71,12 +89,14 @@ local function decompressGzip(zip)
|
|||||||
cursor = cursor + 2
|
cursor = cursor + 2
|
||||||
end
|
end
|
||||||
|
|
||||||
local compressedData = zip:sub(cursor, #zip-8)
|
print('expirement:')
|
||||||
print('compressedData', compressedData)
|
local str = 'BC'
|
||||||
print(dump(compressedData))
|
print(str, reverseBitOrder(str))
|
||||||
local data = compressedData -- getting compressed data without trailing 8 bytes (CRC32, ISIZE)
|
|
||||||
|
|
||||||
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
|
end
|
||||||
|
|
||||||
---Converts (scaling) 16-bit unsigned integer to 8-bit unsigned integer.
|
---Converts (scaling) 16-bit unsigned integer to 8-bit unsigned integer.
|
||||||
|
|||||||
Reference in New Issue
Block a user