]>
Commit | Line | Data |
---|---|---|
b24c88b3 RC |
1 | /* |
2 | * Copyright (c) 2001, Robert Collins. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by Robert Collins <rbtcollins@hotmail.com> | |
13 | * | |
14 | */ | |
15 | ||
c93bc6d0 MB |
16 | #ifndef SETUP_COMPRESS_GZ_H |
17 | #define SETUP_COMPRESS_GZ_H | |
b24c88b3 | 18 | |
b16e07fc | 19 | #include "compress.h" |
e76de0f5 | 20 | #include <zlib.h> |
b16e07fc | 21 | |
b24c88b3 RC |
22 | class compress_gz:public compress |
23 | { | |
24 | public: | |
25 | /* assumes decompression */ | |
26 | compress_gz (io_stream *); | |
27 | /* the mode allows control, but this implementation only does compression */ | |
28 | compress_gz (io_stream *, const char *); | |
29 | /* read data (duh!) */ | |
30 | virtual ssize_t read (void *buffer, size_t len); | |
31 | /* provide data to (double duh!) */ | |
ca9506cc | 32 | virtual ssize_t write (const void *buffer, size_t len); |
b24c88b3 RC |
33 | /* read data without removing it from the class's internal buffer */ |
34 | virtual ssize_t peek (void *buffer, size_t len); | |
44d31ea0 CV |
35 | virtual off_t tell (); |
36 | virtual off_t seek (off_t where, io_stream_seek_t whence); | |
b24c88b3 RC |
37 | /* try guessing this one */ |
38 | virtual int error (); | |
39 | /* Find out the next stream name - | |
40 | * ie for foo.tar.gz, at offset 0, next_file_name = foo.tar | |
41 | * for foobar that is an compress, next_file_name is the next | |
42 | * extractable filename. | |
43 | */ | |
44 | virtual const char *next_file_name () | |
45 | { | |
46 | return NULL; | |
47 | }; | |
26922cd2 | 48 | virtual int set_mtime (time_t); |
b41c2908 CV |
49 | virtual time_t get_mtime (); |
50 | virtual mode_t get_mode (); | |
341988b9 RC |
51 | /* Use seek EOF, then tell (). get_size won't do this incase you are sucking down |
52 | * over a WAN :} */ | |
53 | virtual size_t get_size () {return 0;}; | |
5bc84ff1 | 54 | virtual void release_original (); /* give up ownership of original io_stream */ |
b24c88b3 | 55 | /* if you are still needing these hints... give up now! */ |
341988b9 | 56 | virtual ~ compress_gz (); |
b24c88b3 RC |
57 | private: |
58 | compress_gz () | |
59 | { | |
60 | }; | |
61 | char peekbuf[512]; | |
62 | size_t peeklen; | |
840e95c1 | 63 | void construct (); |
b24c88b3 RC |
64 | void check_header (); |
65 | int get_byte (); | |
66 | unsigned long getLong (); | |
67 | void putLong (unsigned long); | |
68 | void destroy (); | |
69 | int do_flush (int); | |
70 | io_stream *original; | |
5bc84ff1 | 71 | bool owns_original; |
840e95c1 | 72 | const char *openmode; |
b24c88b3 RC |
73 | /* from zlib */ |
74 | z_stream stream; | |
75 | int z_err; /* error code for last stream operation */ | |
76 | int z_eof; /* set if end of input file */ | |
77 | unsigned char *inbuf; /* input buffer */ | |
78 | unsigned char *outbuf; /* output buffer */ | |
79 | uLong crc; /* crc32 of uncompressed data */ | |
80 | char *msg; /* error message */ | |
81 | int transparent; /* 1 if input file is not a .gz file */ | |
82 | char mode; /* 'w' or 'r' */ | |
44d31ea0 | 83 | off_t startpos; /* start of compressed data in file (header skipped) */ |
b24c88b3 RC |
84 | }; |
85 | ||
c93bc6d0 | 86 | #endif /* SETUP_COMPRESS_GZ_H */ |