473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

The magic number in GZip header is not correct.(decompressing a .zip file)

I've just tried the following code for decompressing a .zip file, but get the following error message:
"The magic number in GZip header is not correct. Make sure you are passing in a GZip stream."
The error is on line 27: "int bytesRead = compressedZipStream.Read(smallBuffer, 0, 100);"

My code is as follows:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.IO.Compression;


namespace GZipText_decompression
{
class decompressionTest
{
static void Main(string[] args)
{
FileStream inputFile= null;
GZipStream compressedZipStream = null;

try
{
//determine the uncompressed size of the file
inputFile = new FileStream("c:\\translated_catalog.zip", FileMode.Open, FileAccess.Read, FileShare.Read);
compressedZipStream = new GZipStream(inputFile, CompressionMode.Decompress);
int offSet = 0;
int totalBytes = 0;
byte[] smallBuffer = new byte[100];
while (true)
{
int bytesRead = compressedZipStream.Read(smallBuffer, 0, 100);
if (bytesRead == 0)
{
break;
}
offSet += bytesRead;
totalBytes += bytesRead;
}
compressedZipStream.Close();

//open and read contents of the file no that the uncompressed size is known
inputFile = new FileStream("c:\\translated_catalog.zip", FileMode.Open, FileAccess.Read, FileShare.Read);

//Decompress the file contents
compressedZipStream = new GZipStream(inputFile, CompressionMode.Decompress);

byte[] buffer = new byte[totalBytes];
compressedZipStream.Read(buffer, 0, totalBytes);

//Display decompression information
Console.WriteLine(Encoding.UTF7.GetString(buffer)) ;
Console.WriteLine("Compressed size is {0} and decompressed size is {1} ", inputFile.Length, buffer.Length);
compressedZipStream.Close();
Console.ReadLine();


}
finally
{
if (inputFile != null)
{
inputFile.Close();
}
if (compressedZipStream != null)
{
compressedZipStream.Close();
}
}
}
}
}

The file that I'm decompressing is a .zip file.
Any ideas?
Sep 18 '06 #1
0 8901

Sign in to post your reply or Sign up for a free account.

Similar topics

36
by: Dag | last post by:
Is there a python module that includes functions for working with prime numbers? I mainly need A function that returns the Nth prime number and that returns how many prime numbers are less than N,...
3
by: rohisingh | last post by:
I have a tar file. The content of the file are as following. rohits@sandman 12-08-04 $ tar tvf 20041208.tar drwxr-xr-x root/root 0 2004-12-08 21:39:19 20041208/ -rw-r--r-- root/root ...
10
by: Xah Lee | last post by:
today i need to use Python to decompress gzip files. since i'm familiar with Python doc and have 10 years of computing experience with 4 years in unix admin and perl, i have quickly located the...
25
by: Xah Lee | last post by:
Python Doc Problem Example: gzip Xah Lee, 20050831 Today i need to use Python to compress/decompress gzip files. Since i've read the official Python tutorial 8 months ago, have spent 30...
19
by: youpak2000 | last post by:
Are MAGIC numbers always bad? Using magic numbers (constant numbers) in programs are generally considered a bad programming practice, and it's recommended that to define constants in single,...
14
by: Bill | last post by:
I've written a small program that, in part, reads in a file and parses it. Sometimes, the file is gzipped. The code that I use to get the file object is like so: if filename.endswith(".gz"):...
9
by: Rajarshi | last post by:
Hi, I have some code that takes a string and obtains a compressed version using zlib.compress Does anybody know how I can remove the header portion of the compressed bytes, such that I only have...
0
by: Matt | last post by:
Hi all, I'm using the gzip module to return a gzip response from a small python httpserver. I'd like to know the number of bytes written to the underlying socket, but it doesn't seem to support...
1
Unicron
by: Unicron | last post by:
Hi folks, I couldn't find any posts about this issue- I am using Firebug to examine my page loading. When I call a large JS file, it gets downloaded once and then shows as being cached the next...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.