Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Well I played a little with it, but I have some problems:

 

I every time get the exception, first byte doens't match

 

But i'm sure it's compressed with gzip..

  • Administrators
Posted

Yes. The library at the link I gave you should give you everything you need to do it. If you are having a problem then could you post the relevant code / errors as it it makes it much easier for people to help.

 

Also are you sure it is a gzipped file?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

I thought it only can be used with streams?

 

How can I decompress a byte array then?

 

I'm using this function:

 

	static void Main(string[] args)
	{
		FileStream fs = new FileStream(@"C:\Documents and Settings\Lucas\My Documents\Mijn downloads\test.age3rec", FileMode.Open, FileAccess.Read);
		
		BinaryReader reader = new BinaryReader(fs);
		
		byte[] header = new byte[4];
		byte[] bytes = new byte[4];
		
		header = reader.ReadBytes(4);
		bytes = reader.ReadBytes(4);
		
		int ByteSize = (int) Convert.ToInt16(bytes[0]) + (Convert.ToInt16(bytes[1]) << 8) + (Convert.ToInt16(bytes[2]) << 16) + (Convert.ToInt16(bytes[3]) << 24);
		
		// This array needs to be gzip uncompressed
		byte[] contents = reader.ReadBytes((int)fs.Length - 8);
		
		Console.ReadLine();			
	}

 

And I'm 100% sure it is gzip compressed, because I found a PHP script, which does the same as what I want my program to do. And that PHP script uses gzuncompress();

Posted

Great thanks! :)

 

But here's my next problem:

With a memory stream I thought I could finally uncompress the contents, but no. I still got an error with the message that the first byte didn't matched.

 

After some searching, I found that the PHP function gzcompress() is not the same as gzip compression. so gzuncompress() is also not the same als gzip uncompression.

 

The difference: (found in the PHP manual (http://www.php.net/gzcompress))

Note: This is not the same as gzip compression, which includes some header data. See gzencode() for gzip compression.

 

So there's no header in my file I want to be uncompressed, and that's why I still get the error I think.

 

But how can I uncompress this then?

  • Administrators
Posted
It looks like (from the link you provided) that the data is just compressed using the ZLIB compression, the library I pointed to also handles this as well. Try using one of the zip related streams (IIRC there is a DeflateStream or similar).

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...