Re: Read compressed files and deal with byte swapping.



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.Z
a.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

.



Relevant Pages

  • Re: Read compressed files and deal with byte swapping.
    ... The compressed files are in either big-endian or little-endian ... after uncompress and then compress the ...
    (comp.lang.c)
  • Re: Read compressed files and deal with byte swapping.
    ... The compressed files are in either big-endian or little-endian ... program hangs up. ... after uncompress and then compress the ...
    (comp.lang.c)
  • Re: Batch file question - average size of file in directory
    ... when run with the -cd options will uncompress the ... It is easy then to pipe the uncompressed data to wcto count the ... With a slightly modified awkscript, you can even print a running ... When run with the same set of two compressed files this will print: ...
    (freebsd-questions)
  • Re: Read compressed files and deal with byte swapping.
    ... The compressed files are in either big-endian or little-endian ... program hangs up. ... after uncompress and then compress the ...
    (comp.lang.c)
  • Re: Clean Disk Question
    ... Now I am seeing many filenames show up in blue lettering in ... >> filenames that are now blue? ... Is there any need to uncompress these files? ... editor/viewer work properly with the compressed files from the DVD ...
    (microsoft.public.windowsxp.help_and_support)