GZip ASP.NET 2.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fayazmd
    New Member
    • Jul 2007
    • 41

    GZip ASP.NET 2.0

    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

    Code:
    protected void btnCompress_Click(object sender, EventArgs e) 
    {
    
    if (fUpload.PostedFile == null) 
    {
    
    lblMessage.Text = "No File Selected to Upload."; 
    }
    
    string strName = Path.GetFileName(fUpload.PostedFile.FileName); 
    try
    
    {
    
    Stream oStream = fUpload.PostedFile.InputStream;
    
    byte[] buffer = new byte[oStream.Length];
    
    oStream.Read(buffer, 0, buffer.Length);
    
    oStream.Close();
    
    FileStream oFileStream = File.Create(Server.MapPath(Path.ChangeExtension(strName, "gz"))); 
    
    GZipStream oGZipStream = new GZipStream(oFileStream, CompressionMode.Compress);oGZipStream.Write(buffer, 0, buffer.Length); 
    oGZipStream.Close();
    
    lblMessage.Text = "\"" + strName + "\" was compressed & uploaded successfully."; 
    }
    
    catch (Exception) 
    {
    
    lblMessage.Text = "An Error Occured While Uploading File."; 
    }
    
    }
    Last edited by kenobewan; Oct 17 '08, 01:29 PM. Reason: Use code tags
  • SvenV
    New Member
    • Oct 2008
    • 50

    #2
    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?

    Comment

    • fayazmd
      New Member
      • Jul 2007
      • 41

      #3
      Originally posted by SvenV
      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.

      Comment

      Working...