Sign in to follow this  
Followers 0
gosu

AutoZip

45 posts in this topic

#1 ·  Posted (edited)

Hi guys.

Don´t know if there already has been a compression made with AutoIt, so don´t beat me if someone already had the same idea.

AutoZip is a _very_ basic compression written quick and dirty. Because I´m not that good in english, I´ll just show you an example.

aaaaaaaaaaaaaa
55555555
kkkkkkkkkk
ooooooooooooo
333

will be compressed to

14{a}
8{5}
10{k}
13{o}
3{3}

What AutoZip can´t do so far:

Compress more than one char into one statement. Example:

ababab

won´t get into:

3{ab}

Maybe I´ll develop it further, don´t know yet.

After compressing, it will show you some info:

Posted Image

Maybe someone can learn from it or make it better.

Have fun :lmao:

; ----------------------------------------------------------------------------
; Includes
; ----------------------------------------------------------------------------
#include <file.au3>
#Include <string.au3>

; ----------------------------------------------------------------------------
; Script
; ----------------------------------------------------------------------------
AutoZip("example.txt", "example.zipped.txt")

; ----------------------------------------------------------------------------
; Functions
; ----------------------------------------------------------------------------
Func AutoZip($arg1, $arg2)
   $oldtime = TimerInit()
   
   $readfile = FileOpen($arg1, 0)
   $writefile = FileOpen($arg2, 2)
   $linesyet = 0
   $letters = 0
   $numbers = 0
   
   If $readfile = -1 Or $writefile = -1 Then
      MsgBox(0, "Error", "Unable to open file(s).")
      Exit
   EndIf
   
   $CountedLines = _FileCountLines ($arg1)
   ToolTip("Compressing..." & @CR & "0 %", 0, 0)
   
   While 1
      $line = FileReadLine($readfile)
      If @error = -1 Then ExitLoop
      $len = StringLen($line)
      For $letters = 97 to 122
         If StringInStr($line, Chr($letters)) Then
            $letters = 1
            ExitLoop
         EndIf
      Next
      For $numbers = 48 to 57
         If StringInStr($line, Chr($numbers)) Then
            $numbers = 1
            ExitLoop
         EndIf
      Next
      If $numbers = 1 Then
         For $char2check = 48 To 57
            If StringInStr($line, Chr($char2check), 1) Then
                  If _StringRepeat(Chr($char2check), $len) == $line Then
                     $line = $len & "{" & Chr($char2check) & "}"
                  EndIf
            EndIf
         Next
      EndIf
      If $letters = 1 Then
         For $char2check = 65 To 90
            If StringInStr($line, Chr($char2check), 1) Then
                  If _StringRepeat(Chr($char2check), $len) == $line Then
                     $line = $len & "{" & Chr($char2check) & "}"
                  EndIf
            EndIf
         Next
         For $char2check = 97 To 122
            If StringInStr($line, Chr($char2check), 1) Then
                  If _StringRepeat(Chr($char2check), $len) == $line Then
                     $line = $len & "{" & Chr($char2check) & "}"
                  EndIf
            EndIf
         Next
      EndIf
      FileWriteLine($writefile, $line)
      $linesyet = $linesyet + 1
      $percent = $linesyet / $CountedLines
      $percent = $percent * 100
      ToolTip("Compressing..." & @CR & Round($percent, 2) & " %", 0, 0)
   Wend
   
   FileClose($readfile)
   FileClose($writefile)
   
   $readfilesize = FileGetSize($arg1)
   $writefilesize = FileGetSize($arg2)
   
   $timeneeded = TimerDiff($oldtime)
   MsgBox(0, "AutoZip: done!", "Needed " & Round($timeneeded / 1000, 0) & " seconds to compress " & $readfilesize & " Bytes to " & $writefilesize & " Bytes!" & @CR &_
             "Compressed file is " & 100 - Round(($writefilesize / $readfilesize) * 100, 2) & "% smaller than original file!" & @CR &_
             "Compressed " & Round($CountedLines / ($timeneeded / 1000), 2) & " lines per second!")
EndFunc ;==>AutoZip

Cheers

Edited by gosu

[quote name='d2hacker88' date='Jan 6 2005, 05:10 PM']Can someone please help me out with autoit like gimme a link on how to use it cause i have no experience with computer languages and i'd like to make a program with autoit in order to empress my computer teacher.[right][snapback]52215[/snapback][/right][/quote]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Yeah, some implementation of RLE compression :lmao: Don't know if it will be usefull in real environment, because this kind of compression give very small size winning on real files, but anyway it's good for demonstration purposes.

Edited by Lazycat

Share this post


Link to post
Share on other sites

Yeah, some implementation of RLE compression :lmao: Don't know if it will be usefull in real environment, because this kind of compression give very small size winning on real files, but anyway it's good for demonstration purposes.

<{POST_SNAPBACK}>

Yeah, this is pretty useless for 'real' files.

Maybe i´ll do a directionary compression. o:)


[quote name='d2hacker88' date='Jan 6 2005, 05:10 PM']Can someone please help me out with autoit like gimme a link on how to use it cause i have no experience with computer languages and i'd like to make a program with autoit in order to empress my computer teacher.[right][snapback]52215[/snapback][/right][/quote]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

i'm going to create a GUI for this if you don't care, i hope you can find a way to make it compress 'real' files :lmao:

EDIT: i made the gui and the compressed files have the extention .caz, the program is attached

EDIT2: i removed the tool tip and made it update the text in the GUI while compressing, btw when you get to 10% 20% etc it only shows the first number and not the zero

EDIT3: i changed the attached file, see my lower post...

Edited by Xenogis

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

i'm going to create a GUI for this if you don't care, i hope you can find a way to make it compress 'real' files :lmao:

EDIT: i made the gui and the compressed files have the extention .caz, the program is attached

<{POST_SNAPBACK}>

Nice. You could maybe add a status label which contains %.

And I found out the compression isn´t useless. I just compressed a jpg to 50 % of it´s size o:)

dit: Compressing executables also works, but really slow:

Posted Image

Edited by gosu

[quote name='d2hacker88' date='Jan 6 2005, 05:10 PM']Can someone please help me out with autoit like gimme a link on how to use it cause i have no experience with computer languages and i'd like to make a program with autoit in order to empress my computer teacher.[right][snapback]52215[/snapback][/right][/quote]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

you need to fix some of the problems with numbers, besides that it works quite well. maybe you could create a FileInstall () line and have another script that compresses that way you could split the file up and make it go really fast, if you need any help with the program i will help you :lmao:

EDIT: i got some screenshots, one is messed up compression percent and the other is messed up numbers after compression is done

Posted Image

Posted Image

Edited by Xenogis

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

you need to fix some of the problems with numbers, besides that it works quite well. maybe you could create a FileInstall () line and have another script that compresses that way you could split the file up and make it go really fast, if you need any help with the program i will help you :lmao:

<{POST_SNAPBACK}>

Hm? I don´t know what you mean. I see no line where I could cut something out - and I see no problems with numbers. If I run the script, I get 100 % CPU, so 2 Scripts would be senseless without a P4 HT.

EDIT: i got some screenshots, one is messed up compression percent and the other is messed up numbers after compression is done

Posted Image

Posted Image

<{POST_SNAPBACK}>

What the...?

How did that happen? What file did you choose to compress? How many lines has got the file?

Edited by gosu

[quote name='d2hacker88' date='Jan 6 2005, 05:10 PM']Can someone please help me out with autoit like gimme a link on how to use it cause i have no experience with computer languages and i'd like to make a program with autoit in order to empress my computer teacher.[right][snapback]52215[/snapback][/right][/quote]

Share this post


Link to post
Share on other sites

i never watched the CPU, but i edited my post with screenshots. there are negative numbers


[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

...If I run the script, I get 100 % CPU, so 2 Scripts would be senseless without a P4 HT.

<{POST_SNAPBACK}>

Try adding a tiny Sleep in the loops..

For example Sleep(1) should do it..

If you don't have the Sleep in the loops, it will try to loop as fast as the CPU allows,

which results in the 100% usage of the CPU..

Edited by Helge

Share this post


Link to post
Share on other sites

Try adding a tiny Sleep in the loops..

For example Sleep(1) should do it..

If you don't have the Sleep in the loops, it will try to loop as fast as the CPU allows,

which results in the 100% usage of the CPU..

<{POST_SNAPBACK}>

I know, but this is exactly what I want. It should use the whole CPU to compress.

[quote name='d2hacker88' date='Jan 6 2005, 05:10 PM']Can someone please help me out with autoit like gimme a link on how to use it cause i have no experience with computer languages and i'd like to make a program with autoit in order to empress my computer teacher.[right][snapback]52215[/snapback][/right][/quote]

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

updated script, i only changed 3 things but i figured i'd post it anyway

i added 2 Sleep (1)s to it

i made it so it doesn't change the file to 1 when you click cancel in the browse dialog

EDIT: i started typing before i saw your post, the sleeps are only 1 millesecond and it doesnt matter if it is using the whole cpu, the result is the same. if i compressed a file that took 35 seconds it would not even take a second more with the sleep in there. and you don't want it to take tons of cpu or it will slow people down and they wont use it

EDIT2: changed the file see my post on page 2

Edited by Xenogis

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Share this post


Link to post
Share on other sites

updated script, i only changed 3 things but i figured i'd post it anyway

i added 2 Sleep (1)s to it

i made it so it doesn't change the file to 1 when you click cancel in the browse dialog

<{POST_SNAPBACK}>

The Sleep(1) in the compress function is silly. It´ll just slow down it. And a 50 ms sleep for the GUI is also ok.

[quote name='d2hacker88' date='Jan 6 2005, 05:10 PM']Can someone please help me out with autoit like gimme a link on how to use it cause i have no experience with computer languages and i'd like to make a program with autoit in order to empress my computer teacher.[right][snapback]52215[/snapback][/right][/quote]

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

with the sleeps in there it takes 75% less cpu, i don't see how that is silly

edit: its your project, you can do what you want but i really think you should keep the sleeps in there

Edited by Xenogis

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

with the sleeps in there it takes 75% less cpu, i don't see how that is silly

edit: its your project, you can do what you want but i really think you should keep the sleeps in there

<{POST_SNAPBACK}>

The compression already is too slow. A compression is meant to compress files fast, not to save CPU power :">

Compare this to this:

(With sleep in function):

Posted Image

(Without sleep in function):

Posted Image

That is 34 % faster!

Edited by gosu

[quote name='d2hacker88' date='Jan 6 2005, 05:10 PM']Can someone please help me out with autoit like gimme a link on how to use it cause i have no experience with computer languages and i'd like to make a program with autoit in order to empress my computer teacher.[right][snapback]52215[/snapback][/right][/quote]

Share this post


Link to post
Share on other sites

im just saying that it doesnt take much more time, and if you do it you can implement my idea to split the file up and compress it way faster


[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

im just saying that it doesnt take much more time, and if you do it you can implement my idea to split the file up and compress it way faster

<{POST_SNAPBACK}>

It _does_ take much more time :lmao:

And what should splitting the file up do? Why should it be faster? 4 / 2 is still 2 + 2; it won´t get less.

EDIT: i started typing before i saw your post, the sleeps are only 1 millesecond and it doesnt matter if it is using the whole cpu, the result is the same. if i compressed a file that took 35 seconds it would not even take a second more with the sleep in there. and you don't want it to take tons of cpu or it will slow people down and they wont use it

<{POST_SNAPBACK}>

That´s not right. Look for example at WinRar or something. It always uses 100 % - and you tell me people don´t use it cause it uses 100 % cpu? o:) Edited by gosu

[quote name='d2hacker88' date='Jan 6 2005, 05:10 PM']Can someone please help me out with autoit like gimme a link on how to use it cause i have no experience with computer languages and i'd like to make a program with autoit in order to empress my computer teacher.[right][snapback]52215[/snapback][/right][/quote]

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

i will take the sleeps out of the gui script, but splitting the file up and running different programs compressing different parts is faster because you are compressing the start and the middle at the same time, that will cut the time to compress in half

EDIT: yeah that will be awesome

Edited by Xenogis

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Share this post


Link to post
Share on other sites

i will take the sleeps out of the gui script, but splitting the file up and running different programs compressing different parts is faster because you are compressing the start and the middle at the same time, that will cut the time to compress in half

EDIT: yeah that will be awesome

<{POST_SNAPBACK}>

Ehm? What are you talking 'bout? I´m compressing line for line. I read in a line and compress. I´m not reading out the start and the middle at the same time...

@Larry: Man, never thought of that. Is it on the to-do-list? Would be wonderful :lmao:


[quote name='d2hacker88' date='Jan 6 2005, 05:10 PM']Can someone please help me out with autoit like gimme a link on how to use it cause i have no experience with computer languages and i'd like to make a program with autoit in order to empress my computer teacher.[right][snapback]52215[/snapback][/right][/quote]

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

im talking about if we split the file up, it would compress from the start and from the middle because it is split in half

EDIT: that is if we run the compression twice

Edited by Xenogis

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Share this post


Link to post
Share on other sites

im talking about if we split the file up, it would compress from the start and from the middle because it is split in half

EDIT: that is if we run the compression twice

<{POST_SNAPBACK}>

What the heck would that change? It would change _nothing_.... It maybe even would make it slower....

[quote name='d2hacker88' date='Jan 6 2005, 05:10 PM']Can someone please help me out with autoit like gimme a link on how to use it cause i have no experience with computer languages and i'd like to make a program with autoit in order to empress my computer teacher.[right][snapback]52215[/snapback][/right][/quote]

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