compression issues

C

csharpula csharp

Hello,

I would like to know which one of the following compressiom methods are
the easiest to implement in c# and the most effective one in compression
of files? (text or code files)

Which one of those: zip, tar, tar.gz, gz. ?
And is there any code sample in C# of the API with compression?

Thank you!
 
A

Anthony Jones

csharpula csharp said:
Hello,

I would like to know which one of the following compressiom methods are
the easiest to implement in c# and the most effective one in compression
of files? (text or code files)

Which one of those: zip, tar, tar.gz, gz. ?
And is there any code sample in C# of the API with compression?

using System;
using System.IO;
using System.IO.Compression;

void static GZFile(string source, string destination)
{
using (
Stream src = File.Open(source, FileMode.Open),
dst = File.Open(destination, FileMode.Create) )
{
Stream gz = new GZipStream(dst, CompressionMode.Compress);
Pump(src, gz);
gz.Flush();
gz.Close();
}
}

This will create a gz file. Note Pump (code not shown) simply chunks a 128K
buffer from one stream to another.

It doesn't get any simpler. However other third party libraries would
probably get better compression.
 
C

csharpula csharp

But which one is the most efficent and how to API with it from C#?

Thanks a lot!
 
R

rhaazy

But which one is the  most efficent and how to API with it from C#?

Figure it out, do some research, its not hard to do a couple of google
searches about comparisons between compression methods.
Someone gave you the code you would need, what do you mean how to API
with it from c#?
 
A

Arne Vajhøj

csharpula said:
I would like to know which one of the following compressiom methods are
the easiest to implement in c# and the most effective one in compression
of files? (text or code files)

Which one of those: zip, tar, tar.gz, gz. ?
And is there any code sample in C# of the API with compression?

Tar is not compressing at all - it just bundles multiple files
in one file.

Zip and gzip basically use the same compression algorithm
(a combination of LZ77 with Huffman encoding and some
smart tricks). Zip format has the capability to bundle
multiple files in one file - gzip does not.

..NET framework support:
- the basic algorithm
- gzip
in namespace System.IO.Compression !

To get zip you will need something extra like:
- SharpZipLib
- J# runtime library from Microsoft

Arne
 
C

csharpula csharp

So that means that tar.gz and zip are the same from the compression
point of view?
 
A

Arne Vajhøj

csharpula said:
So that means that tar.gz and zip are the same from the compression
point of view?

They use the exact same compression algorithm, but you get
different resulting sizes.

Tar creates a bundle of all the files uncompressed and then
gzip compresses it and just add a tiny header.

Zip bundles and compress all the files individually.

This means that:
- a .tar.gz will often be sligtly smaller than the .zip because
you get better compression when you compressed everything
in one pass instead of compressing each file individually
- you can extract a single file from a zip while with a
.tar.gz even though it may look as if you extract a single
file then in fact you are decompressing the entire thing
(or at least up to where the exacted file are)

I don't know if that makes it same or different in your context.

Arne
 
A

Anthony Jones

Arne Vajhøj said:
Tar is not compressing at all - it just bundles multiple files
in one file.

Zip and gzip basically use the same compression algorithm
(a combination of LZ77 with Huffman encoding and some
smart tricks). Zip format has the capability to bundle
multiple files in one file - gzip does not.

.NET framework support:
- the basic algorithm
- gzip
in namespace System.IO.Compression !

To get zip you will need something extra like:
- SharpZipLib
- J# runtime library from Microsoft

Another Zip option would be System.IO.Packaging.Package which is
fundementally a Zip file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top