Hello everyone, before I apologize for my english level...
I have a problem on decompressing data zip.
I made a python script to perform this decompression using zlib and it works correctly.
Now I have to integrate this decompression code in an vb app ... I have no other choice, it is required.
So I just ask for some help, if possible, and know before posting, I searches on a lot of web sites, forums, docs, examples, in all languages ^ ^ but I don't know enough about vb to success.
Basically, I have a data stream as byte array (not a compressed file), which I collected in a section of an XML file that contains settings but they are compressed.
I write the steps in vb to retrieve only the data compressed, after doing a ascii encode and decode base 64, and I get the same result as python script in which these data are decompressed.
But in VB, when I try to uncompress data, I can not do it, I get the error -3 with zlib and the following message with ReadByte (ReadByte method is to read the bytes decompressed by the interface of System.IO.Compression.DeflateStream. Net)
Here 3 pieces of code that all generate mistakes ... (CompressBuf byte array are compressed data, it is the variable "compressed" in python code below)
Thank you in advance for the help you could give me!
Nckb
And for information Python code I use :
I have a problem on decompressing data zip.
I made a python script to perform this decompression using zlib and it works correctly.
Now I have to integrate this decompression code in an vb app ... I have no other choice, it is required.
So I just ask for some help, if possible, and know before posting, I searches on a lot of web sites, forums, docs, examples, in all languages ^ ^ but I don't know enough about vb to success.
Basically, I have a data stream as byte array (not a compressed file), which I collected in a section of an XML file that contains settings but they are compressed.
I write the steps in vb to retrieve only the data compressed, after doing a ascii encode and decode base 64, and I get the same result as python script in which these data are decompressed.
But in VB, when I try to uncompress data, I can not do it, I get the error -3 with zlib and the following message with ReadByte (ReadByte method is to read the bytes decompressed by the interface of System.IO.Compression.DeflateStream. Net)
Code:
An unhandled exception of type 'System.IO.InvalidDataException' occurred in System.dll
Additional information: Block length icts Does not match with complement.
Code:
Using ms1 As New MemoryStream(CompressBuf)
Using dStream1 As System.IO.Compression.DeflateStream = New System.IO.Compression.DeflateStream(ms1, Compression.CompressionMode.Decompress)
While dStream1.ReadByte <> -1 ' -1 indicates nothing left to read
decompressedBufferLength += 1
End While
End Using
End Using
Using ms2 As New MemoryStream(CompressBuf)
Using dStream2 As System.IO.Compression.DeflateStream = New System.IO.Compression.DeflateStream(ms2, Compression.CompressionMode.Decompress)
ReDim CompressBuf(decompressedBufferLength - 1) '11711
dStream2.Read(CompressBuf, 0, decompressedBufferLength) '11712
End Using
End Using
Code:
res = uncompress(DecompressBuf, DecompressLen, CompressBuf, CompressLen)
Code:
DelSole.DotZLibCompressor.DotZLib.DeCompressBytes(CompressBuf, CompressBuf.Length) ', DecompressBuf)
Nckb
And for information Python code I use :
Code:
binary = base64.decodestring(data.encode('ascii'))
print("---------binary----------")
print(binary)
print("---------FIN binary----------")
header, compressed = binary[:32], binary[32:]
print("---------header----------")
print(header)
print("---------FIN header----------")
print("---------compressed----------")
print(compressed)
print("---------FIN compressed----------")
prtl_xml = zlib.decompress(compressed)
print(prtl_xml)
prtl_xml = prtl_xml.decode('utf-16')