Decompression (SharpZipLib )

C

csharpula csharp

Hello ,

In case someone uses SharpZipLib :

I am using SharpZipLib in order to compress and decompress gzip files. I
decompress a fie which was compressed with SharpZipLib code in a
following way:

//args[0] - gzip file ,args[1] - folder to extract to

TarArchive archive = null;

using (Stream s = new GZipInputStream(File.OpenRead(args[0])))

{

archive = TarArchive.CreateInputTarArchive(s);

if (!Directory.Exists(args[1]))

{

Directory.CreateDirectory(args[1]);

}

archive.ExtractContents(args[1]);



But I get the following error (for inpur that was also compressed by
SharpZipLib code) : Error GZIP header, first magic byte doesn't match.

Why is that? How can I solve this?

Thanks!
 
J

Jeff Johnson

But I get the following error (for inpur that was also compressed by
SharpZipLib code) : Error GZIP header, first magic byte doesn't match.

Why is that? How can I solve this?

Have you considered asking in the SharpZipLib forums? I've been there in the
past and they were pretty helpful.

I don't use GZip, so I can't help you.
 
A

Arne Vajhøj

csharpula said:
In case someone uses SharpZipLib :

I am using SharpZipLib in order to compress and decompress gzip files. I
decompress a fie which was compressed with SharpZipLib code in a
following way:

//args[0] - gzip file ,args[1] - folder to extract to

TarArchive archive = null;

using (Stream s = new GZipInputStream(File.OpenRead(args[0])))

{

archive = TarArchive.CreateInputTarArchive(s);

if (!Directory.Exists(args[1]))

{

Directory.CreateDirectory(args[1]);

}

archive.ExtractContents(args[1]);



But I get the following error (for inpur that was also compressed by
SharpZipLib code) : Error GZIP header, first magic byte doesn't match.

Why is that? How can I solve this?

The error message tell you that the first two bytes of the files
is not what it should be to be avalid GZIP file.

Can you create a simple example of code that creates the
file and code that attempts to read the file ?

Then I am sure that we can find the problem.

Arne
 
C

csharpula csharp

That's how I compress (and I wrote in previous mail how I decompress)
Why do I still get this error on decompression if I compress this way?

try
{

byte[] dataBuffer = new byte[4096];

TarArchive archive = null;

using (Stream tarS = new
TarOutputStream(File.Create(_filePath)))
{

archive = TarArchive.CreateOutputTarArchive(tarS);



foreach (string file in _filesList)
{
TarEntry entry =
TarEntry.CreateEntryFromFile(file);
archive.WriteEntry(entry, true);
}

archive.Close();

using (Stream gzipS = new
GZipOutputStream(File.Create(_filePath + ".gz")))
{
using (FileStream fs = File.OpenRead(_filePath))
{
StreamUtils.Copy(fs, gzipS, dataBuffer);
}

}



}
 
A

Arne Vajhøj

csharpula said:
That's how I compress (and I wrote in previous mail how I decompress)
try
{

byte[] dataBuffer = new byte[4096];

TarArchive archive = null;

using (Stream tarS = new
TarOutputStream(File.Create(_filePath)))

I am sure that I could copy those code fragments into
source files and build the stuff around necessary to make
them compilable programs, if I were willing to spend time
on it.

But it is not my problem, so ...

Arne
 
F

Family Tree Mike

csharpula csharp said:
That's how I compress (and I wrote in previous mail how I decompress)
Why do I still get this error on decompression if I compress this way?

try
{

byte[] dataBuffer = new byte[4096];

TarArchive archive = null;

using (Stream tarS = new
TarOutputStream(File.Create(_filePath)))
{

archive = TarArchive.CreateOutputTarArchive(tarS);



foreach (string file in _filesList)
{
TarEntry entry =
TarEntry.CreateEntryFromFile(file);
archive.WriteEntry(entry, true);
}

archive.Close();

using (Stream gzipS = new
GZipOutputStream(File.Create(_filePath + ".gz")))
{
using (FileStream fs = File.OpenRead(_filePath))
{
StreamUtils.Copy(fs, gzipS, dataBuffer);
}

}



}


I would try closing the "using (Stream tarS)" before doing the gzip process.
You are done with the tar stream at that point anyways.
 

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