]>
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 RC |
18 | |
19 | /* this is the parent class for all compress IO operations. | |
20 | * It | |
21 | */ | |
22 | ||
b16e07fc | 23 | #include "compress.h" |
e76de0f5 | 24 | #include <zlib.h> |
b16e07fc | 25 | |
b24c88b3 RC |
26 | class compress_gz:public compress |
27 | { | |
28 | public: | |
29 | /* assumes decompression */ | |
30 | compress_gz (io_stream *); | |
31 | /* the mode allows control, but this implementation only does compression */ | |
32 | compress_gz (io_stream *, const char *); | |
33 | /* read data (duh!) */ | |
34 | virtual ssize_t read (void *buffer, size_t len); | |
35 | /* provide data to (double duh!) */ | |
ca9506cc | 36 | virtual ssize_t write (const void *buffer, size_t len); |
b24c88b3 RC |
37 | /* read data without removing it from the class's internal buffer */ |
38 | virtual ssize_t peek (void *buffer, size_t len); | |
39 | virtual long tell (); | |
ca9506cc | 40 | virtual int seek (long where, io_stream_seek_t whence); |
b24c88b3 RC |
41 | /* try guessing this one */ |
42 | virtual int error (); | |
43 | /* Find out the next stream name - | |
44 | * ie for foo.tar.gz, at offset 0, next_file_name = foo.tar | |
45 | * for foobar that is an compress, next_file_name is the next | |
46 | * extractable filename. | |
47 | */ | |
48 | virtual const char *next_file_name () | |
49 | { | |
50 | return NULL; | |
51 | }; | |
26922cd2 | 52 | virtual int set_mtime (time_t); |
b41c2908 CV |
53 | virtual time_t get_mtime (); |
54 | virtual mode_t get_mode (); | |
341988b9 RC |
55 | /* Use seek EOF, then tell (). get_size won't do this incase you are sucking down |
56 | * over a WAN :} */ | |
57 | virtual size_t get_size () {return 0;}; | |
5bc84ff1 | 58 | virtual void release_original (); /* give up ownership of original io_stream */ |
b24c88b3 | 59 | /* if you are still needing these hints... give up now! */ |
341988b9 | 60 | virtual ~ compress_gz (); |
b24c88b3 RC |
61 | private: |
62 | compress_gz () | |
63 | { | |
64 | }; | |
65 | char peekbuf[512]; | |
66 | size_t peeklen; | |
67 | void construct (io_stream *, const char *); | |
68 | void check_header (); | |
69 | int get_byte (); | |
70 | unsigned long getLong (); | |
71 | void putLong (unsigned long); | |
72 | void destroy (); | |
73 | int do_flush (int); | |
74 | io_stream *original; | |
5bc84ff1 | 75 | bool owns_original; |
b24c88b3 RC |
76 | /* from zlib */ |
77 | z_stream stream; | |
78 | int z_err; /* error code for last stream operation */ | |
79 | int z_eof; /* set if end of input file */ | |
80 | unsigned char *inbuf; /* input buffer */ | |
81 | unsigned char *outbuf; /* output buffer */ | |
82 | uLong crc; /* crc32 of uncompressed data */ | |
83 | char *msg; /* error message */ | |
84 | int transparent; /* 1 if input file is not a .gz file */ | |
85 | char mode; /* 'w' or 'r' */ | |
86 | long startpos; /* start of compressed data in file (header skipped) */ | |
87 | }; | |
88 | ||
c93bc6d0 | 89 | #endif /* SETUP_COMPRESS_GZ_H */ |