Jump to content



Photo

zLib (Deflate/Inflate/GZIP) UDF


  • Please log in to reply
10 replies to this topic

#1 Ward

Ward

    Adventurer

  • Active Members
  • PipPip
  • 141 posts

Posted 24 May 2011 - 08:54 PM

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

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:
AutoIt         
; ----------------------------------------------------------------------------- ; Zlib Compression Library (Deflate/Inflate) Machine Code UDF Example ; Purpose: Provide The Machine Code Version of Zlib Library In AutoIt ; Author: Ward ; Zlib Copyright © 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 "AutoIt Machine Code Algorithm Collection"

Attached File  ZLIB.zip   58.58K   910 downloads

Edited by Ward, 24 May 2011 - 09:52 PM.








#2 Digisoul

Digisoul

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 312 posts

Posted 24 May 2011 - 11:04 PM

Awesome work WardPosted Image, 5 stars from me.
73 108 111 118 101 65 117 116 111 105 116 Posted Image

#3 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 24 May 2011 - 11:13 PM

Very nice! :huh2:

#4 tip

tip

    Adventurer

  • Active Members
  • PipPip
  • 103 posts

Posted 28 May 2011 - 02:50 PM

Thanks Ward. This is great...

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


#5 joakim

joakim

    Wayfarer

  • Active Members
  • Pip
  • 97 posts

Posted 12 June 2011 - 10:33 PM

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

#6 ynbIpb

ynbIpb

    Seeker

  • Active Members
  • 45 posts

Posted 05 November 2012 - 04:50 PM

[deleted]

Edited by ynbIpb, 05 November 2012 - 05:59 PM.


#7 legend

legend

    Prodigy

  • Active Members
  • PipPipPip
  • 157 posts

Posted 08 December 2012 - 01:29 PM

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


#8 water

water

    ?

  • MVPs
  • 10,695 posts

Posted 08 December 2012 - 02:01 PM

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? ...

UDFs:

Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki

OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki

ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts

WordEX (2012-12-29 - Version 1.3 released) - Download

ExcelEX (2013-05-11 - Alpha 4 released) - Download


#9 legend

legend

    Prodigy

  • Active Members
  • PipPipPip
  • 157 posts

Posted 09 December 2012 - 10:59 AM

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

#10 legend

legend

    Prodigy

  • Active Members
  • PipPipPip
  • 157 posts

Posted 13 December 2012 - 12:43 AM

no one :D?

#11 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 13 December 2012 - 02:52 PM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users