Compression and Decompression of Files using Visual Basic 2005
page 1 of 9
Published: 21 May 2007
Abstract
In this article Abhishek describes the usage of GZipStream and DeflateStream class libraries in Visual Basic 2005 with the help of a sample application.
by Abhishek Kumar Singh
Feedback
Average Rating: 
Views (Total / Last 10 Days): 59667/ 453

Introduction

Compression is the technique to minimize the size of data (or file) by applying some encoding algorithm. The output of the compression is called compressed or zipped data (or file). Decompression is the reverse of compression to get the source data (or file) back by applying some decoding algorithm. The output of decompression is called decompressed or unzipped data (or file).

We used to share data from one computer to another (over LAN, WAN, etc), one device to another. In most cases data being transferred contains redundancy. The compression and decompression algorithms use these redundancy attributes (e.g. number of occurrences, locations of occurrence, etc.). In one way we can say - more redundancy in data (or file) would result more compressed (i.e. less size) data (or file).  In compressed data communication, sender and receiver must have mutual understanding of encoding and decoding schemes or they must have based on same standard.

The purpose of compression technique is to optimize the disk space while storing data in computer and to use less bandwidth while data is to be transferred over network. There are security benefits as well.

In general we use different data formats like text, image, audio and video during our day to day communication and data transfer. One particular encoding scheme may not be effective for every data format. For example, it is not necessary that the encoding scheme, which works well upon text data, would also give good results with image format data.


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 4 and 7 and type the answer here:

User Comments

Title: Very Impressive   
Name: Paul Myers
Date: 9/22/2009 10:14:52 AM
Comment:
Thank you for this sample code. It is well written and very understandable.
Title: request   
Name: swarup saha
Date: 6/30/2009 12:49:22 PM
Comment:
dear bhaia,can i get C# code of image compression and decompression.if possible pls send me in this address:
swarup_04cse@yahoo.com
Title: Thank you   
Name: Mikael
Date: 6/30/2009 9:49:22 AM
Comment:
A thousand thanks, works perfect.
Title: Tanks man   
Name: Tim
Date: 5/5/2009 5:00:45 AM
Comment:
Hello, thank you for the tutorial, it was great, i love it.
i have som problem but i figure it out, so, now it works, and thanks agen...
Title: Training   
Name: Obama - USA President
Date: 2/5/2009 3:57:12 PM
Comment:
Great of you to share...yes we can.
Title: help me yaar as soon as   
Name: prince walia
Date: 11/23/2008 12:11:07 PM
Comment:
hello frnd,,,i m doing mca,,my sar give me aa project to cpmrss the files,,,but my project is nt complete,,plz send me the project oe help me,,
Title: Compression   
Name: Avaloan
Date: 11/23/2008 3:34:22 AM
Comment:
I think it's good but I don't see any compresses just a expand of file size.!
Title: Compression   
Name: Sree
Date: 10/30/2008 2:21:43 AM
Comment:
I have used the code in the script task in SQL Integration services. First it gives me an error at the step "objMemStream.Length" saying: disallows implicit conversion from Long to Int.
So i have tried type conversions.
It gets executed and a zip file is created but when i try to decompress it, it says it is bad or invalid file.
Can anybody help me on this?
Title: Compression   
Name: Stacy
Date: 10/2/2008 4:24:41 AM
Comment:
Hi,

I am working on an asp application and I have a string that needs to be passed from script file to asp page, but the string breaks coz of its large size.Can this function be used for the same.Also how do i convert string to byte.

Please reply soon
Title: compression   
Name: mike
Date: 9/4/2008 5:31:06 AM
Comment:
it can't comprees large file...65k is the limit..i hv tried compressing 90k file(TXT FILE)..bt to my surprise the compressed file is showg a larger memory thn its initial size..and there is no or a very little difference between gzip and deflate.am i doin any mistake here.?.plz help!!!
Title: compression   
Name: Jeevitha
Date: 8/29/2008 9:39:38 AM
Comment:
Nice Article. It's very useful to me. Thanks a lot.
Title: Compression and Decompression   
Name: Padma
Date: 5/29/2008 2:25:36 AM
Comment:
Article is very good....it helped me a lot...can u give article abt transferring an image file in vb6 using udp protocol....
mailid:belpadma@gmail.com
PH:080 22195854
Title: Senior Programmer/Analyst   
Name: Guillermo
Date: 5/14/2008 10:23:12 AM
Comment:
I am very thankful for this article because it helped me very very much...
Title: Senior Programmer/Analyst   
Name: J Eaves
Date: 5/12/2008 11:58:09 AM
Comment:
Great article and easy to follow. However, 2 issues. 1)I couldn't get code to work with CompressData() as MemoryStream. And 2)After I created a zip file and tried to open with WinZip 11, I get the following error "Cannot open file: it does not appear to be a valid archive."
Does anyone have thoughts or suggestions.
Thanks.
Title: Compression and Decompression of Files using Visual Basic 2005   
Name: Gary
Date: 3/12/2008 10:38:09 AM
Comment:
omg thank you. MSDN sample is complete shite in comparison
Title: Compression and Decompression of Files using Visual Basic 2005   
Name: Cammie McGinty
Date: 1/27/2008 3:04:27 PM
Comment:
Thank you for a clear and straightforward example.
Title: Reply to: Bloated results   
Name: Abhishek (Author)
Date: 11/21/2007 2:58:05 AM
Comment:
hi Jacob,
BTW which type of files you are trying to compress and decompress?
Are you using the byte counters properly if you are not decompressing entire compressed file at a time?
Title: Reply to: Give me idea   
Name: Abhishek (Author)
Date: 11/21/2007 2:55:50 AM
Comment:
Hi Netra,
sorry for late reply, i had stuck in some stuff.
You can achieve entire folder compression using DeflateStream but for this you have to implement your own logic to compress each file one by one inside the folder and then you can make a bundle of all compress files and also there should be a information file which should keep details of each file name, size etc which you can use while decompressing.
Frankly saying i have done this by myself but had some finding on this.
hope it helps you. If you got anyt idea on this please let me know. I will be thankful to you.
thanks.
Title: Bloated results   
Name: Jacob Kennedy
Date: 11/2/2007 5:29:13 PM
Comment:
I'm implementing your DecompressByte on a folder of files that were zipped using GZipStream, and it's working a lot better than what I had, but my decompressed files are ending up over a hundred times bigger than the original non-compressed files... any ideas?
Title: Give me idea   
Name: Netra
Date: 10/22/2007 5:26:55 AM
Comment:
Hi abhi,
i want to zip the folder containg files for eg. i have folder named ABC and in that folder i have 3 .txt files , i want to zip that ABC folder not only the files in that.
Can i done it at runtime , plz give me the idea. And i want to do it by using DeflateStream.
Title: Excellent idea....   
Name: Rajiv Tripathi
Date: 7/5/2007 3:40:00 PM
Comment:
Hi Abhi,
That's a really gr8 idea. Thx for sharing it with all of us.That has helped a lot. i hope you remember me by my name, I implemented your idea and it produced remarkable result.
thx & all the best!!
Title: rijovg@gmail.com   
Name: rijo
Date: 6/28/2007 6:23:07 AM
Comment:
i need an help would u plz contact on this id
Title: Re: File Extension   
Name: Abhishek Kumar Singh
Date: 6/15/2007 7:52:18 PM
Comment:
As the gzipstream and deflatestream are stream based classes, one way would be- you can add file exetension in byte() at first/last position before compression. Then read those bytes to get the file extenstion and remove those bytes before writing the file.
Usually you need to know the extension of file by any mean while writing decompressed file. If compressed byte() are being transferred using remote methods you can send file extension as extra parameter in the method.

Thanx.
Title: file extension   
Name: Theuns
Date: 6/14/2007 10:45:01 AM
Comment:
How do you keep the file extension when compressing it?
Title: My Feedback   
Name: Sunny Adeshara
Date: 6/8/2007 8:53:00 AM
Comment:
I am very thankful for this article because it helped me very much.
Title: Good Article Keep it up   
Name: Anjaiah Keesari
Date: 5/24/2007 9:05:54 AM
Comment:
Even I am working on Compression and Decompression with C# code your Article is very good. You Explained concepts very nice thanks keesari_anjaiah@yahoo.co.in
Title: I m proud of my best frined   
Name: Vinit Pratap Singh
Date: 5/23/2007 9:13:57 AM
Comment:
Hi... i don't know Visual Basic.. but i think its a very big implement by you.. i m very proud of u.. keep it up... with lots of new adventure.. . vinitpratap@gmail.com

Product Spotlight
Product Spotlight 






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2009 ASPAlliance.com  |  Page Processed at 11/21/2009 7:38:43 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search