473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

GZip ASP.NET 2.0

fayazmd
41
Hi,

Im my application, users will upload files to server. I want to impliment GZip to compress files.

But the compressed file is consuming more memory than actual file size.

What might be the problem?

Here is my code

Expand|Select|Wrap|Line Numbers
  1. protected void btnCompress_Click(object sender, EventArgs e) 
  2. {
  3.  
  4. if (fUpload.PostedFile == null) 
  5. {
  6.  
  7. lblMessage.Text = "No File Selected to Upload."; 
  8. }
  9.  
  10. string strName = Path.GetFileName(fUpload.PostedFile.FileName); 
  11. try
  12.  
  13. {
  14.  
  15. Stream oStream = fUpload.PostedFile.InputStream;
  16.  
  17. byte[] buffer = new byte[oStream.Length];
  18.  
  19. oStream.Read(buffer, 0, buffer.Length);
  20.  
  21. oStream.Close();
  22.  
  23. FileStream oFileStream = File.Create(Server.MapPath(Path.ChangeExtension(strName, "gz"))); 
  24.  
  25. GZipStream oGZipStream = new GZipStream(oFileStream, CompressionMode.Compress);oGZipStream.Write(buffer, 0, buffer.Length); 
  26. oGZipStream.Close();
  27.  
  28. lblMessage.Text = "\"" + strName + "\" was compressed & uploaded successfully."; 
  29. }
  30.  
  31. catch (Exception) 
  32. {
  33.  
  34. lblMessage.Text = "An Error Occured While Uploading File."; 
  35. }
  36.  
  37. }
Oct 17 '08 #1
2 1140
SvenV
50
Your code seems right,
Maybe you should try DeflateStream instead of GzipStream. Gzip performes CRC , DeflateStream doesn't so this could resolve in a decrease in size. But how much increase are we talking about?
Oct 17 '08 #2
fayazmd
41
Your code seems right,
Maybe you should try DeflateStream instead of GzipStream. Gzip performes CRC , DeflateStream doesn't so this could resolve in a decrease in size. But how much increase are we talking about?
Hi,
I have tried with Deflate also. While testing, when i upload a 11MB file, its taking 15MB.
Oct 20 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: bmgz | last post by:
I am having problems trying to use the gzip module, I do the followig >>>import gzip >>>file = gzip.GzipFile("testfile.txt") >>>file.write() -which params does this accept?, archive name? I...
10
by: Xah Lee | last post by:
today i need to use Python to decompress gzip files. since i'm familiar with Python doc and have 10 years of computing experience with 4 years in unix admin and perl, i have quickly located the...
2
by: comp.lang.php | last post by:
I am simply trying to zip together selected files into a single ZIP file. Windows XP doesn't have a native process by which you can do this, so I borrowed gzip, downloaded and installed, and upon...
25
by: Xah Lee | last post by:
Python Doc Problem Example: gzip Xah Lee, 20050831 Today i need to use Python to compress/decompress gzip files. Since i've read the official Python tutorial 8 months ago, have spent 30...
14
by: Bill | last post by:
I've written a small program that, in part, reads in a file and parses it. Sometimes, the file is gzipped. The code that I use to get the file object is like so: if filename.endswith(".gz"):...
4
by: Aidan | last post by:
Hi, I'm having a bit of trouble with a python script I wrote, though I'm not sure if it's related directly to python, or one of the other software packages... The situation is that I'm trying...
1
by: Nader | last post by:
Hello, I have a gzip file and I try to read from this file withe the next statements: gunziped_file = gzip.GzipFile('gzip-file') input_file = open(gunziped_file,'r') But I get the nezt...
1
by: Nader | last post by:
Hello, I have a gzip file and I try to read from this file withe the next statements: gunziped_file = gzip.GzipFile('gzip-file') input_file = open(gunziped_file,'r') But I get the nezt...
0
by: Gabriel Genellina | last post by:
En Wed, 19 Nov 2008 13:25:03 -0200, Barak, Ron <Ron.Barak@lsi.com> escribió: Note *where* the exception is raised. Until something is actually read, no check is made for the file format. --...
0
by: Barak, Ron | last post by:
Thanks Gabriel, Okay, I get it: I was under the impression that the format check would be done on the open. Bye, Ron. -----Original Message----- From: Gabriel Genellina Sent: Thursday,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.