473,473 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help me to implement code compress file .

2 New Member
Hi all. I have project compress file using C#. I'm using name space IO.Compression and i saw this code on Internet but it is compress to file bigger than source file. Can you help me, please.Thanks for your help.
Expand|Select|Wrap|Line Numbers
  1. public void CompressFile(string inputFileName, string outputFileName)
  2. {
  3. byte[] buffer = new byte[4096];
  4. if (File.Exists(inputFileName))
  5. {
  6. using (FileStream inputFile = File.Open(inputFileName, FileMode.Open), outputFile = File.Create(outputFileName))
  7. {
  8.  
  9. using (GZipStream gzip = new GZipStream(outputFile, CompressionMode.Compress))
  10. {
  11. int n = 0;
  12. while ((n = inputFile.Read(buffer, 0, buffer.Length)) != 0)
  13. {
  14. gzip.Write(buffer, 0, n);
  15. }
  16. }
  17. }
  18. }
  19. }
  20.  
  21.  
  22. public void UncompressFile(string inputFileName, string outputFileName)
  23. {
  24. byte[] buffer = new byte[4096];
  25. if (File.Exists(inputFileName))
  26. {
  27. using (FileStream intputFile = File.Open(inputFileName, FileMode.Open), outputFile = File.Create(outputFileName))
  28. {
  29. using (GZipStream gzip = new GZipStream(intputFile, CompressionMode.Decompress))
  30. {
  31. int n;
  32. while ((n = gzip.Read(buffer, 0, buffer.Length)) != 0)
  33. {
  34. outputFile.Write(buffer, 0, n);
  35. }
  36. }
  37. }
  38. }
  39. }
Jan 11 '08 #1
0 1305

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...
0
by: Tony | last post by:
Hello, Any assistance would be appreciated: As the subject suggests I am trying to gunzip files using the Compress::Zlib module. The following is basically the code that I am working with: ...
14
by: nullptr | last post by:
Hi, As an exercise, I've written a program implementing run-length encoding. I would be more that happy to hear your comments, suggestions, etc Thanks, --- #include <stdio.h> #include...
6
by: Null Reference | last post by:
Anybody here who can explain or point me to a link ? I wish to create a blank MS Access DB file programmatically using C# . Thanks, nfs
1
by: treelife | last post by:
I'm getting and internal server error when | run the following mod_python script. I am actually trying to run Django. Script: from mod_python import apache def handler(req):...
6
by: JACK GUNAWAN via AccessMonster.com | last post by:
Hi, I have trouble setting up an access database on a wan because I am using dial up which charges per minute. How can I get the database to be sharred across miles with much stability and lower...
46
by: Bruce W. Darby | last post by:
This will be my very first VB.Net application and it's pretty simple. But I've got a snag in my syntax somewhere. Was hoping that someone could point me in the right direction. The history: My...
5
by: _dwin | last post by:
Hi, Does anyone know how to implement your own preprocessor directive? For instance, I would like to have a directive which goes like: #<directive_name<parameters, ...> ie. #compress...
4
by: tekion | last post by:
Hi, Could some one take a look at the below code snipet which keep failing: import optparse p = optparse.OptionParser(description="script to do stuff", prog="myscript.py", ....)...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.