Sign in to follow this  
Followers 0
Ward

zLib (Deflate/Inflate/GZIP) UDF

18 posts in this topic

#1 ·  Posted (edited)

To use zLib in AutoIt, the easiest way is download the DLL, and then just use it by DllCall, or warp it by my

But now I convert zLib to machine code version UDF, because "just for fun", or because I can.

There is another good reason: to minimize the UDF size (because there are some functions I don't need in the DLL file).

The best thing of this library is that it can compress/decompress the gzip format.

So this is also a "GZIP UDF" in pure script.

Example:

; -----------------------------------------------------------------------------
; Zlib Compression Library (Deflate/Inflate) Machine Code UDF Example
; Purpose: Provide The Machine Code Version of Zlib Library In AutoIt
; Author: Ward
; Zlib Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
; -----------------------------------------------------------------------------

#Include "ZLIB.au3"

; Test _ZLIB_Compress And _ZLIB_Uncompress
Dim $Original = BinaryFileRead(@AutoItExe)
Dim $Compressed = _ZLIB_Compress($Original, 9)
Dim $Decompressed = _ZLIB_Uncompress($Compressed)
Dim $Result = 'Original Size: ' & BinaryLen($Original) & @CRLF
$Result &= 'Compressed Size: ' & BinaryLen($Compressed) & @CRLF
$Result &= 'Decompress Succeed: ' & ($Decompressed = $Original)
MsgBox(0,'Deflate/Inflate Test', $Result)


; Test _ZLIB_GZCompress And _ZLIB_GZUncompress
Dim $Original = BinaryFileRead(@AutoItExe)
Dim $Compressed = _ZLIB_GZCompress($Original, 9)
Dim $Decompressed = _ZLIB_GZUncompress($Compressed)
Dim $Result = 'Original Size: ' & BinaryLen($Original) & @CRLF
$Result &= 'Compressed Size: ' & BinaryLen($Compressed) & @CRLF
$Result &= 'Decompress Succeed: ' & ($Decompressed = $Original)
MsgBox(0,'Gzip Test', $Result)


; Test _ZLIB_FileCompress And _ZLIB_FileUncompress
Dim $OriginalPath = @AutoItExe
Dim $CompressedPath = @TempDir & "\test.z"
Dim $DecompressedPath = @TempDir & "\test.unz"
_ZLIB_FileCompress($OriginalPath, $CompressedPath, 9)
_ZLIB_FileUncompress($CompressedPath, $DecompressedPath)
Dim $Result = 'Original Size: ' & FileGetSize($OriginalPath) & @CRLF
$Result &= 'Compressed Size: ' & FileGetSize($CompressedPath) & @CRLF
$Result &= 'Decompress Succeed: ' & (BinaryFileRead($DecompressedPath) = BinaryFileRead($OriginalPath))
FileDelete($CompressedPath)
FileDelete($DecompressedPath)
MsgBox(0,'Deflate/Inflate File Test', $Result)


; Test _ZLIB_GZFileCompress And _ZLIB_GZFileUncompress
Dim $OriginalPath = @AutoItExe
Dim $CompressedPath = @TempDir & "\test.gz"
Dim $DecompressedPath = @TempDir & "\test.ungz"
_ZLIB_GZFileCompress($OriginalPath, $CompressedPath, 9)
_ZLIB_GZFileUncompress($CompressedPath, $DecompressedPath)
Dim $Result = 'Original Size: ' & FileGetSize($OriginalPath) & @CRLF
$Result &= 'Compressed Size: ' & FileGetSize($CompressedPath) & @CRLF
$Result &= 'Decompress Succeed: ' & (BinaryFileRead($DecompressedPath) = BinaryFileRead($OriginalPath))
FileDelete($CompressedPath)
FileDelete($DecompressedPath)
MsgBox(0,'Gzip File Test', $Result)

Exit

Func BinaryFileRead($Path)
    Local $File = FileOpen($Path, 16)
    Local $Data = FileRead($File)
    FileClose($File)
    Return $Data
EndFunc

For other compression method, see my "

ZLIB.zip

Edited by Ward
1 person likes this

新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了

 

Share this post


Link to post
Share on other sites



Awesome work WardPosted Image, 5 stars from me.


73 108 111 118 101 65 117 116 111 105 116

Share this post


Link to post
Share on other sites

Thanks Ward. This is great...


[center]MsgBox_Tipped: Eye candy msgboxes/inputboxes/loginboxes. | CreateBlankBox: Semi-transparent layers with borders and rounded corners.[/center]

Share this post


Link to post
Share on other sites

Great work Ward!

I found it really interesting to be able to deflate and/or inflate in raw mode, ie without header and footer. Just put $Level = -15 (windowBits) and you're able to compress/uncompress in raw mode. Thanks once again.

Joakim

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

[deleted]

Edited by ynbIpb

Share this post


Link to post
Share on other sites

I tried to do this, but didn't work:

#Include "ZLIB.au3"

$Path = (@scriptdir & "test.exe")

; Test _ZLIB_Compress And _ZLIB_Uncompress
Dim $Original = BinaryFileRead(@ScriptDir & "test.exe")
Dim $Compressed = _ZLIB_Compress($Original, 9)

Func BinaryFileRead($Path)
Local $File = FileOpen($Path, 16)
Local $Data = FileRead($File)
FileClose($File)
Return $Data
EndFunc

Share this post


Link to post
Share on other sites

Legend,

I know nothing about this UDF. But if you want to get help from anyone you need to be more specific. "Doesn't work" isn't.

Do you get any error messages? Is @error set? Does the script crash? ...


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I don't get any errors, the script runs, but doesen't compress test.exe

Share this post


Link to post
Share on other sites

no one :D?

Share this post


Link to post
Share on other sites

If you're referring specifically to your test script... well, what are you doing with $Compressed? As far as I can see you're doing nothing with it. Your script and the functions don't compress any data in place, so what do you expect the end result to be?

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I tried to do this, but didn't work:

 

#Include "ZLIB.au3"

$Path = (@scriptdir & "test.exe")

; Test _ZLIB_Compress And _ZLIB_Uncompress
Dim $Original = BinaryFileRead(@ScriptDir & "test.exe")
Dim $Compressed = _ZLIB_Compress($Original, 9)

Func BinaryFileRead($Path)
Local $File = FileOpen($Path, 16)
Local $Data = FileRead($File)
FileClose($File)
Return $Data
EndFunc

 

I know this topic is VERY old but I couldn't resist.  Also, this may help.....

;$Path = (@scriptdir & "test.exe")
$Path = (@scriptdir & "\test.exe"); * Don't forget the backslash..

;Dim $Original = BinaryFileRead(@ScriptDir & "test.exe")
Dim $Original = BinaryFileRead($Path)
Edited by NewPlaza

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

will this work to decode a gzip encoded http body? and if so how would i do that exactly?

Edited by lionfaggot

Share this post


Link to post
Share on other sites

well the good news is i learned a lot today, i changed one of my headers to: "Accept-Encoding: deflate" and it automatically deflates for me. i also know a lot more about certain subjects in general. VERY PRODUCTIVE DAY! Jos i owe you one man. a friend is paying me for my current project lol - you saved me some troubles

Share this post


Link to post
Share on other sites

well the good news is i learned a lot today, i changed one of my headers to: "Accept-Encoding: deflate" and it automatically deflates for me. i also know a lot more about certain subjects in general. VERY PRODUCTIVE DAY! Jos i owe you one man. a friend is paying me for my current project lol - you saved me some troubles

Good for you ;)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I can't download it. Can you help me ?

Share this post


Link to post
Share on other sites
12 hours ago, argumentum said:

attached below.

ZLIB.zip

I work, I have downloaded, thank you very much

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0