Results 1 to 4 of 4

Thread: LZW (.Z files, uncompress/compress in linux) library?

  1. #1
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default LZW (.Z files, uncompress/compress in linux) library?

    Hi,

    Does anyone know about a library for handling LZW compressed files?
    ZLIB/Quazip doesn't handle these, as that is only good for deflate method.

    My aim is to uncompress files from *.z files, so compression is not needed.

    Thanks!

  2. #2
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: LZW (.Z files, uncompress/compress in linux) library?

    I have successfully found a wrapper for GZIP using LZW compression, but I could only manage to compile it as a console application the way you can see it in the included files.
    If I want to add the same source and header to my GUI application, it doesn't find <iostream>. I don't know why, since it is able to compile as console application in a different project.
    Does anyone know why it fails to compile as GUI?

    I think that an expert could make a QT-compliant wrapper easily from it. I failed to do this, since I'm a newbie, and the compile error is:

    In file included from ..\NESA\gzstream.c:29:
    ..\NESA/gzstream.h:34:20: error: iostream: No such file or directory
    ..\NESA/gzstream.h:35:19: error: fstream: No such file or directory
    In file included from ..\NESA\gzstream.c:29:
    ..\NESA/gzstream.h:46: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'gzstreambuf'
    ..\NESA/gzstream.h:75: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'gzstreambase'
    ..\NESA/gzstream.h:93: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'igzstream'
    ..\NESA/gzstream.h:104: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'ogzstream'
    ...etc...

    The only difference between .pro files is:

    Console project:

    QT += core
    QT -= gui
    TARGET = gzstream
    CONFIG += console
    CONFIG -= app_bundle
    TEMPLATE = app

    GUI project:

    QT += core gui xml
    TARGET = NESA
    TEMPLATE = app

    The working combination is here (so others can also use it to uncompress .z files), but somehow it adds additional line breaks for some reason:

    gzstream.h:

    Qt Code:
    1. // ============================================================================
    2. // gzstream, C++ iostream classes wrapping the zlib compression library.
    3. // Copyright (C) 2001 Deepak Bandyopadhyay, Lutz Kettner
    4. //
    5. // This library is free software; you can redistribute it and/or
    6. // modify it under the terms of the GNU Lesser General Public
    7. // License as published by the Free Software Foundation; either
    8. // version 2.1 of the License, or (at your option) any later version.
    9. //
    10. // This library is distributed in the hope that it will be useful,
    11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    13. // Lesser General Public License for more details.
    14. //
    15. // You should have received a copy of the GNU Lesser General Public
    16. // License along with this library; if not, write to the Free Software
    17. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    18. // ============================================================================
    19. //
    20. // File : gzstream.h
    21. // Revision : $Revision: 1.5 $
    22. // Revision_date : $Date: 2002/04/26 23:30:15 $
    23. // Author(s) : Deepak Bandyopadhyay, Lutz Kettner
    24. //
    25. // Standard streambuf implementation following Nicolai Josuttis, "The
    26. // Standard C++ Library".
    27. // ============================================================================
    28.  
    29. #ifndef GZSTREAM_H
    30. #define GZSTREAM_H 1
    31.  
    32. // standard C++ with new header file names and std:: namespace
    33. #include <iostream>
    34. #include <fstream>
    35. #include <../../../gzip/zip/zlib.h>
    36.  
    37. #ifdef GZSTREAM_NAMESPACE
    38. namespace GZSTREAM_NAMESPACE {
    39. #endif
    40.  
    41. // ----------------------------------------------------------------------------
    42. // Internal classes to implement gzstream. See below for user classes.
    43. // ----------------------------------------------------------------------------
    44.  
    45. class gzstreambuf : public std::streambuf {
    46. private:
    47. static const int bufferSize = 47+256; // size of data buff
    48. // totals 512 bytes under g++ for igzstream at the end.
    49.  
    50. gzFile file; // file handle for compressed file
    51. char buffer[bufferSize]; // data buffer
    52. char opened; // open/close state of stream
    53. int mode; // I/O mode
    54.  
    55. int flush_buffer();
    56. public:
    57. gzstreambuf() : opened(0) {
    58. setp( buffer, buffer + (bufferSize-1));
    59. setg( buffer + 4, // beginning of putback area
    60. buffer + 4, // read position
    61. buffer + 4); // end position
    62. // ASSERT: both input & output capabilities will not be used together
    63. }
    64. int is_open() { return opened; }
    65. gzstreambuf* open( const char* name, int open_mode);
    66. gzstreambuf* close();
    67. ~gzstreambuf() { close(); }
    68.  
    69. virtual int overflow( int c = EOF);
    70. virtual int underflow();
    71. virtual int sync();
    72. };
    73.  
    74. class gzstreambase : virtual public std::ios {
    75. protected:
    76. gzstreambuf buf;
    77. public:
    78. gzstreambase() { init(&buf); }
    79. gzstreambase( const char* name, int open_mode);
    80. ~gzstreambase();
    81. void open( const char* name, int open_mode);
    82. void close();
    83. gzstreambuf* rdbuf() { return &buf; }
    84. };
    85.  
    86. // ----------------------------------------------------------------------------
    87. // User classes. Use igzstream and ogzstream analogously to ifstream and
    88. // ofstream respectively. They read and write files based on the gz*
    89. // function interface of the zlib. Files are compatible with gzip compression.
    90. // ----------------------------------------------------------------------------
    91.  
    92. class igzstream : public gzstreambase, public std::istream {
    93. public:
    94. igzstream() : std::istream( &buf) {}
    95. igzstream( const char* name, int open_mode = std::ios::in)
    96. : gzstreambase( name, open_mode), std::istream( &buf) {}
    97. gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); }
    98. void open( const char* name, int open_mode = std::ios::in) {
    99. gzstreambase::open( name, open_mode);
    100. }
    101. };
    102.  
    103. class ogzstream : public gzstreambase, public std::ostream {
    104. public:
    105. ogzstream() : std::ostream( &buf) {}
    106. ogzstream( const char* name, int mode = std::ios::out)
    107. : gzstreambase( name, mode), std::ostream( &buf) {}
    108. gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); }
    109. void open( const char* name, int open_mode = std::ios::out) {
    110. gzstreambase::open( name, open_mode);
    111. }
    112. };
    113.  
    114. #ifdef GZSTREAM_NAMESPACE
    115. } // namespace GZSTREAM_NAMESPACE
    116. #endif
    117.  
    118. #endif // GZSTREAM_H
    119. // ============================================================================
    120. // EOF //
    To copy to clipboard, switch view to plain text mode 

    gzstream.c:

    Qt Code:
    1. // ============================================================================
    2. // gzstream, C++ iostream classes wrapping the zlib compression library.
    3. // Copyright (C) 2001 Deepak Bandyopadhyay, Lutz Kettner
    4. //
    5. // This library is free software; you can redistribute it and/or
    6. // modify it under the terms of the GNU Lesser General Public
    7. // License as published by the Free Software Foundation; either
    8. // version 2.1 of the License, or (at your option) any later version.
    9. //
    10. // This library is distributed in the hope that it will be useful,
    11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    13. // Lesser General Public License for more details.
    14. //
    15. // You should have received a copy of the GNU Lesser General Public
    16. // License along with this library; if not, write to the Free Software
    17. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    18. // ============================================================================
    19. //
    20. // File : gzstream.C
    21. // Revision : $Revision: 1.7 $
    22. // Revision_date : $Date: 2003/01/08 14:41:27 $
    23. // Author(s) : Deepak Bandyopadhyay, Lutz Kettner
    24. //
    25. // Standard streambuf implementation following Nicolai Josuttis, "The
    26. // Standard C++ Library".
    27. // ============================================================================
    28.  
    29. #include <gzstream.h>
    30. #include <iostream>
    31. #include <string.h> // for memcpy
    32.  
    33. #ifdef GZSTREAM_NAMESPACE
    34. namespace GZSTREAM_NAMESPACE {
    35. #endif
    36.  
    37. // ----------------------------------------------------------------------------
    38. // Internal classes to implement gzstream. See header file for user classes.
    39. // ----------------------------------------------------------------------------
    40.  
    41. // --------------------------------------
    42. // class gzstreambuf:
    43. // --------------------------------------
    44.  
    45. gzstreambuf* gzstreambuf::open( const char* name, int open_mode) {
    46. if ( is_open())
    47. return (gzstreambuf*)0;
    48. mode = open_mode;
    49. // no append nor read/write mode
    50. if ((mode & std::ios::ate) || (mode & std::ios::app)
    51. || ((mode & std::ios::in) && (mode & std::ios::out)))
    52. return (gzstreambuf*)0;
    53. char fmode[10];
    54. char* fmodeptr = fmode;
    55. if ( mode & std::ios::in)
    56. *fmodeptr++ = 'r';
    57. else if ( mode & std::ios::out)
    58. *fmodeptr++ = 'w';
    59. *fmodeptr++ = 'b';
    60. *fmodeptr = '\0';
    61. file = gzopen( name, fmode);
    62. if (file == 0)
    63. return (gzstreambuf*)0;
    64. opened = 1;
    65. return this;
    66. }
    67.  
    68. gzstreambuf * gzstreambuf::close() {
    69. if ( is_open()) {
    70. sync();
    71. opened = 0;
    72. if ( gzclose( file) == Z_OK)
    73. return this;
    74. }
    75. return (gzstreambuf*)0;
    76. }
    77.  
    78. int gzstreambuf::underflow() { // used for input buffer only
    79. if ( gptr() && ( gptr() < egptr()))
    80. return * reinterpret_cast<unsigned char *>( gptr());
    81.  
    82. if ( ! (mode & std::ios::in) || ! opened)
    83. return EOF;
    84. // Josuttis' implementation of inbuf
    85. int n_putback = gptr() - eback();
    86. if ( n_putback > 4)
    87. n_putback = 4;
    88. memcpy( buffer + (4 - n_putback), gptr() - n_putback, n_putback);
    89.  
    90. int num = gzread( file, buffer+4, bufferSize-4);
    91. if (num <= 0) // ERROR or EOF
    92. return EOF;
    93.  
    94. // reset buffer pointers
    95. setg( buffer + (4 - n_putback), // beginning of putback area
    96. buffer + 4, // read position
    97. buffer + 4 + num); // end of buffer
    98.  
    99. // return next character
    100. return * reinterpret_cast<unsigned char *>( gptr());
    101. }
    102.  
    103. int gzstreambuf::flush_buffer() {
    104. // Separate the writing of the buffer from overflow() and
    105. // sync() operation.
    106. int w = pptr() - pbase();
    107. if ( gzwrite( file, pbase(), w) != w)
    108. return EOF;
    109. pbump( -w);
    110. return w;
    111. }
    112.  
    113. int gzstreambuf::overflow( int c) { // used for output buffer only
    114. if ( ! ( mode & std::ios::out) || ! opened)
    115. return EOF;
    116. if (c != EOF) {
    117. *pptr() = c;
    118. pbump(1);
    119. }
    120. if ( flush_buffer() == EOF)
    121. return EOF;
    122. return c;
    123. }
    124.  
    125. int gzstreambuf::sync() {
    126. // Changed to use flush_buffer() instead of overflow( EOF)
    127. // which caused improper behavior with std::endl and flush(),
    128. // bug reported by Vincent Ricard.
    129. if ( pptr() && pptr() > pbase()) {
    130. if ( flush_buffer() == EOF)
    131. return -1;
    132. }
    133. return 0;
    134. }
    135.  
    136. // --------------------------------------
    137. // class gzstreambase:
    138. // --------------------------------------
    139.  
    140. gzstreambase::gzstreambase( const char* name, int mode) {
    141. init( &buf);
    142. open( name, mode);
    143. }
    144.  
    145. gzstreambase::~gzstreambase() {
    146. buf.close();
    147. }
    148.  
    149. void gzstreambase::open( const char* name, int open_mode) {
    150. if ( ! buf.open( name, open_mode))
    151. clear( rdstate() | std::ios::badbit);
    152. }
    153.  
    154. void gzstreambase::close() {
    155. if ( buf.is_open())
    156. if ( ! buf.close())
    157. clear( rdstate() | std::ios::badbit);
    158. }
    159.  
    160. #ifdef GZSTREAM_NAMESPACE
    161. } // namespace GZSTREAM_NAMESPACE
    162. #endif
    163.  
    164. // ============================================================================
    165. // EOF //
    To copy to clipboard, switch view to plain text mode 

    main.c:

    Qt Code:
    1. // ============================================================================
    2. // gzstream, C++ iostream classes wrapping the zlib compression library.
    3. // Copyright (C) 2001 Deepak Bandyopadhyay, Lutz Kettner
    4. //
    5. // This library is free software; you can redistribute it and/or
    6. // modify it under the terms of the GNU Lesser General Public
    7. // License as published by the Free Software Foundation; either
    8. // version 2.1 of the License, or (at your option) any later version.
    9. //
    10. // This library is distributed in the hope that it will be useful,
    11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    13. // Lesser General Public License for more details.
    14. //
    15. // You should have received a copy of the GNU Lesser General Public
    16. // License along with this library; if not, write to the Free Software
    17. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    18. // ============================================================================
    19. //
    20. // File : test_gunzip.C
    21. // Revision : $Revision: 1.3 $
    22. // Revision_date : $Date: 2001/10/04 15:09:28 $
    23. // Author(s) : Deepak Bandyopadhyay, Lutz Kettner
    24. //
    25. // Short test program reading a file, uncompressing it, and writing it.
    26. // ============================================================================
    27.  
    28. #include <gzstream.h>
    29. #include <iostream>
    30. #include <fstream>
    31. #include <stdlib.h>
    32.  
    33. int main( int argc, char*argv[]) {
    34. if ( argc != 3) {
    35. std::cerr << "Usage: " << argv[0] <<" <in-file> <out-file>\n";
    36. return EXIT_FAILURE;
    37. }
    38. // check alternate way of opening file
    39. igzstream in2;
    40. in2.open( argv[1]);
    41. if ( ! in2.good()) {
    42. std::cerr << "ERROR: Opening file `" << argv[1] << "' failed.\n";
    43. return EXIT_FAILURE;
    44. }
    45. in2.close();
    46. if ( ! in2.good()) {
    47. std::cerr << "ERROR: Closing file `" << argv[1] << "' failed.\n";
    48. return EXIT_FAILURE;
    49. }
    50. // now use the shorter way with the constructor to open the same file
    51. igzstream in( argv[1]);
    52. if ( ! in.good()) {
    53. std::cerr << "ERROR: Opening file `" << argv[1] << "' failed.\n";
    54. return EXIT_FAILURE;
    55. }
    56. std::ofstream out( argv[2]);
    57. if ( ! out.good()) {
    58. std::cerr << "ERROR: Opening file `" << argv[2] << "' failed.\n";
    59. return EXIT_FAILURE;
    60. }
    61. char c;
    62. while ( in.get(c))
    63. out << c;
    64. in.close();
    65. out.close();
    66. if ( ! in.eof()) {
    67. std::cerr << "ERROR: Reading file `" << argv[1] << "' failed.\n";
    68. return EXIT_FAILURE;
    69. }
    70. if ( ! out.good()) {
    71. std::cerr << "ERROR: Writing file `" << argv[2] << "' failed.\n";
    72. return EXIT_FAILURE;
    73. }
    74. return EXIT_SUCCESS;
    75. }
    76.  
    77. // ============================================================================
    78. // EOF
    To copy to clipboard, switch view to plain text mode 

    Project file:
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2011-04-17T03:53:26
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core
    8.  
    9. QT -= gui
    10.  
    11. TARGET = gzstream
    12. CONFIG += console
    13. CONFIG -= app_bundle
    14.  
    15. TEMPLATE = app
    16.  
    17.  
    18. SOURCES += test_gunzip.C \
    19. gzstream.C
    20.  
    21. HEADERS += \
    22. gzstream.h
    To copy to clipboard, switch view to plain text mode 


    Added after 4 minutes:


    ZLIB is also needed for this wrapper, so maybe ZLIB does support .Z files too, not just deflation in .ZIP files, but yet I'm too weak to find out how I could use it without a wrapper.


    Added after 9 minutes:


    Is there something (e.g. a switch) included in its makefile of the original project which why it is able to use <iostream>?

    Qt Code:
    1. # ============================================================================
    2. # gzstream, C++ iostream classes wrapping the zlib compression library.
    3. # Copyright (C) 2001 Deepak Bandyopadhyay, Lutz Kettner
    4. #
    5. # This library is free software; you can redistribute it and/or
    6. # modify it under the terms of the GNU Lesser General Public
    7. # License as published by the Free Software Foundation; either
    8. # version 2.1 of the License, or (at your option) any later version.
    9. #
    10. # This library is distributed in the hope that it will be useful,
    11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
    12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    13. # Lesser General Public License for more details.
    14. #
    15. # You should have received a copy of the GNU Lesser General Public
    16. # License along with this library; if not, write to the Free Software
    17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    18. # ============================================================================
    19. #
    20. # File : Makefile
    21. # Revision : $Revision: 1.3 $
    22. # Revision_date : $Date: 2001/10/04 15:09:28 $
    23. # Author(s) : Deepak Bandyopadhyay, Lutz Kettner
    24. #
    25. # ============================================================================
    26.  
    27. # ----------------------------------------------------------------------------
    28. # adapt these settings to your need:
    29. # add '-DGZSTREAM_NAMESPACE=name' to CPPFLAGS to place the classes
    30. # in its own namespace. Note, this macro needs to be set while creating
    31. # the library as well while compiling applications based on it.
    32. # As an alternative, gzstream.C and gzstream.h can be edited.
    33. # ----------------------------------------------------------------------------
    34.  
    35. # CXX = CC -n32 -LANG:std # for SGI Irix 6.5, MIPSpro CC version 7.30
    36. CXX = g++ # for Linux RedHat 6.1, g++ version 2.95.2
    37.  
    38. CPPFLAGS = -I. -O
    39. LDFLAGS = -L. -lgzstream -lz
    40. AR = ar cr
    41.  
    42. # ----------------------------------------------------------------------------
    43. # plain simple rules to make and cleanup the library:
    44. # make default; compiles the library
    45. # make test; compiles and executes test. O.K. message marks success.
    46. # make clean; removes temporary files
    47. # make cleanall; removes temporary files, the library, and programs
    48. # ----------------------------------------------------------------------------
    49.  
    50. default: libgzstream.a
    51.  
    52. test: test_gzip test_gunzip
    53. ./test_gzip COPYING.LIB gz.tmp.gz
    54. gunzip gz.tmp.gz
    55. diff COPYING.LIB gz.tmp
    56. gzip gz.tmp
    57. ./test_gunzip gz.tmp.gz gz.tmp
    58. diff COPYING.LIB gz.tmp
    59. rm gz.tmp.gz gz.tmp
    60. # *** O.K. Test finished successfully. ***
    61.  
    62. gzstream.o : gzstream.C gzstream.h
    63. ${CXX} ${CPPFLAGS} -c -o gzstream.o gzstream.C
    64.  
    65. test_gzip.o : test_gzip.C gzstream.h
    66. ${CXX} ${CPPFLAGS} -c -o test_gzip.o test_gzip.C
    67.  
    68. test_gunzip.o : test_gunzip.C gzstream.h
    69. ${CXX} ${CPPFLAGS} -c -o test_gunzip.o test_gunzip.C
    70.  
    71. libgzstream.a : gzstream.o
    72. ${AR} libgzstream.a gzstream.o
    73.  
    74. test_gzip : test_gzip.o libgzstream.a
    75. ${CXX} -o test_gzip test_gzip.o ${LDFLAGS}
    76.  
    77. test_gunzip : test_gunzip.o libgzstream.a
    78. ${CXX} -o test_gunzip test_gunzip.o ${LDFLAGS}
    79.  
    80. clean :
    81. rm *.o
    82.  
    83. cleanall :
    84. rm *.o libgzstream.a test_gzip test_gunzip
    85.  
    86. # ============================================================================
    87. # EOF
    To copy to clipboard, switch view to plain text mode 
    Last edited by falconium; 17th April 2011 at 22:46.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: LZW (.Z files, uncompress/compress in linux) library?

    Your trying to include a C++ header file from a C project.

    Try changing your project to a C++ project and trying again.

    (GCC detects this via the file extension, so you should rename your .c to .cpp or pass the appropriate options if you wish to keep the same file extension)

    The original makefile specifies that the .c files should be compiled with the C++ compiler.

  4. The following user says thank you to squidge for this useful post:

    falconium (17th April 2011)

  5. #4
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: LZW (.Z files, uncompress/compress in linux) library?

    YEeeeees! Thank you very much, squidge!!!
    Changing the extension from .C to .CPP did the trick! I owe you one!

Similar Threads

  1. SVG files in Qwt library
    By Hogwarts in forum Qwt
    Replies: 1
    Last Post: 30th March 2011, 07:13
  2. Qt Creator How to debug into Qt library on Linux
    By Al_ in forum Qt Tools
    Replies: 3
    Last Post: 14th January 2011, 17:39
  3. Is it possible to link the qt library files into exe?
    By hashb in forum Installation and Deployment
    Replies: 2
    Last Post: 7th January 2010, 14:41
  4. how does Qt know the library path in LINUX
    By babu198649 in forum General Programming
    Replies: 1
    Last Post: 14th November 2008, 17:10
  5. Compress and Uncompress large files in QTcpSocket
    By vishesh in forum Qt Programming
    Replies: 4
    Last Post: 26th June 2007, 22:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.