Re: Read compressed files and deal with byte swapping.
- From: "tianyf@xxxxxxxxx" <tianyf@xxxxxxxxx>
- Date: Sun, 30 Sep 2007 04:53:18 -0700
On Sep 30, 6:22 pm, "Charlie Gordon" <n...@xxxxxxxxxxx> wrote:
<tia...@xxxxxxxxx> a écrit dans le message de news:
1191128567.647665.226...@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Sep 29, 11:00 pm, santosh <santosh....@xxxxxxxxx> wrote:
tia...@xxxxxxxxx wrote:
1). Compressed data (.Z) from several servers (Sun/Linux).
The compressed files are in either big-endian or little-endian
style.
2). I'm programming in Cygwin (Windows XP) with gcc 3.4.
When use gzgetc to read data from compressed big-endian file, my
program hangs up. However, after uncompress and then compress the
file, the program works well. I supposed that the cause is the byte
ordering style. Is there a way to use gzgetc to read data directly
from big-endian .Z file when in a little-endian environment?
To get meaningful results you need to convert the input data to your
native
endianess before performing any other operation. All the major OSes have
APIs to do this. You need to look into your Cygwin documentation to find
out what routines you need to use. Since Cygwin is a POSIX emulation
layer
the functions you want might be htons, htonl, ntohs, and ntohl.
It turns out that the "compress" command in Cygwin is actually "gzip"
which produces a file (.Z) that cannot be decompressed by Solaris
"uncompress" command.
uncompress a.Za.Z: not in compressed format
I wonder whether there is a C library to deal with files compressed by
Solaris "uncompress", just like zlib can handle .gz files.
The easiest would be to use ``FILE *fp = popen("uncompress < filename",
"rb")'' on systems that support this Posix interface (linux, cygwin...)
--
Chqrlie.
It works.
FILE *fp;
fp=popen("gunzip a.Z","r");
fgets(,,);
fgetc(,,);
pclose(fp);
Make sure to use pclose() not fclose() to close the stream. I made a
mistake and the program only read the first file correctly. Now, it
works perfectly.
Thanks.
Regards,
Tian
.
- References:
- Read compressed files and deal with byte swapping.
- From: tianyf@xxxxxxxxx
- Re: Read compressed files and deal with byte swapping.
- From: santosh
- Re: Read compressed files and deal with byte swapping.
- From: tianyf@xxxxxxxxx
- Re: Read compressed files and deal with byte swapping.
- From: Charlie Gordon
- Read compressed files and deal with byte swapping.
- Prev by Date: Re: do structure definitions go in data area or in code area...
- Next by Date: Re: macro help
- Previous by thread: Re: Read compressed files and deal with byte swapping.
- Next by thread: What's wrong with this code?
- Index(es):
Relevant Pages
|