ASP.Net: Better than Zip - File compression using .Tar.gz Part 1

·

Previously I wrote about extracting files from a .Tar.gz archive in Asp.net. This however begs the question, “How do I put my files in a .tar.gz archive in the first place?”

 

This is a post to answer that question.  In my opinion, the best way to put files in a tar.gz archive is to use the executable files for reasons of performance and the fact that most archiving are done in the backend.  It is also easier implemented especially if automation is involved. But if you think that you must and want only to compress files in ASP.Net then skip ahead to Part 2 of this post.  If you want to try my recommendation then read on.

 

First, download the Gzip executable here. Just extract and place the file gzip.exe to your windows folder (or any folder on your system path). The objective is to be able to call the program from anywhere.

 

For the Tar executable you can download this one. Likewise, place it on your windows folder. For simplicity, it’s probably best to rename the file to just “tar.exe”.

 

You may then compress files from the command prompt like this.

 

    Tar –czf myarchive.tar.gz *.xml

 

Where the executable will compress all xml files in the current directory into an archive with filename myarchive.tar.gz

 

You may also  automate the process using vbscript like this.

 

    dim WshShell

    Set WshShell = WScript.CreateObject("WScript.Shell")

    dim oZip

    set oZip = WshShell.Exec("tar -czf myarchive.tar.gz *.xml")

    do while oZip.Status = 0

        wscript.Sleep(100)

    loop

    set WshShell = nothing

 

Don’t forget to read my post on how to extract files from .TAR.GZ files using ASP.Net if you haven’t done so yet. Continue to Part 2

0 comments: