]>
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_ARCHIVE_H |
17 | #define SETUP_ARCHIVE_H | |
b24c88b3 | 18 | |
a3a02820 | 19 | /* this is the parent class for all archive IO operations. */ |
3c054baf | 20 | |
b24c88b3 RC |
21 | /* The read/write the archive stream to get the archive data is flawed. |
22 | * The problem is that you then need a *different* gzip etc class to be able | |
23 | * to ungzip a gzip from within an archive. | |
24 | * The correct way is to | |
25 | * 1) retrieve the file name. | |
26 | * 2) the user creates their own output object. | |
27 | * 3) the user calls extract_file (output strea,). | |
28 | */ | |
29 | ||
30 | typedef enum | |
31 | { | |
32 | ARCHIVE_FILE_INVALID, | |
33 | ARCHIVE_FILE_REGULAR, | |
34 | ARCHIVE_FILE_HARDLINK, | |
35 | ARCHIVE_FILE_SYMLINK, | |
36 | ARCHIVE_FILE_DIRECTORY | |
37 | } | |
38 | archive_file_t; | |
39 | ||
40 | ||
41 | class archive:public io_stream | |
42 | { | |
43 | public: | |
44 | /* get an archive child class from an io_stream */ | |
45 | static archive *extract (io_stream *); | |
46 | /* get an ouput stream for the next files from the archive. | |
47 | * returns NULL on failure. | |
48 | * The stream is not taken over - it will not be automatically deleted | |
49 | */ | |
6b68e703 | 50 | virtual io_stream *extract_file () = 0; |
6dc75764 | 51 | /* extract the next file to the given prefixURL+Path in one step, and name it with the |
ad3c7385 | 52 | * given suffix. |
b24c88b3 RC |
53 | * returns 1 on failure. |
54 | */ | |
a3a02820 MB |
55 | static int extract_file (archive *, const std::string&, const std::string&, |
56 | const std::string = std::string()); | |
b24c88b3 RC |
57 | |
58 | /* | |
59 | * To create a stream that will be compressed, you should open the url, and then get a new stream | |
60 | * from compress::compress. | |
61 | */ | |
62 | /* read data - not valid for archives (duh!) | |
63 | * Could be made valid via the read-child-directly model | |
64 | */ | |
65 | // virtual ssize_t read(void *buffer, size_t len) {return -1;}; | |
66 | /* provide data to (double duh!) */ | |
67 | // virtual ssize_t write(void *buffer, size_t len) { return -1;}; | |
68 | /* read data without removing it from the class's internal buffer */ | |
69 | // virtual ssize_t peek(void *buffer, size_t len); | |
70 | // virtual long tell (); | |
71 | /* try guessing this one */ | |
72 | // virtual int error (); | |
73 | /* Find out the next stream name - | |
74 | * ie for foo.tar.gz, at offset 0, next_file_name = foo.tar | |
75 | * for foobar that is an compress, next_file_name is the next | |
76 | * extractable filename. | |
77 | * The way this works is that when read returns 0, you are at the end of *a* file. | |
78 | * next_file_name will allow read to be called again, if it returns !NULL | |
79 | */ | |
a3a02820 | 80 | virtual const std::string next_file_name () = 0; |
d3c2a043 | 81 | virtual archive_file_t next_file_type () = 0; |
a3a02820 | 82 | virtual const std::string linktarget () = 0; |
b24c88b3 RC |
83 | virtual int skip_file () = 0; |
84 | /* if you are still needing these hints... give up now! */ | |
6b68e703 | 85 | virtual ~archive() = 0; |
cbfc4215 RC |
86 | protected: |
87 | void operator= (const archive &); | |
88 | archive () {}; | |
89 | archive (const archive &); | |
b24c88b3 RC |
90 | private: |
91 | // archive () {}; | |
92 | }; | |
93 | ||
c93bc6d0 | 94 | #endif /* SETUP_ARCHIVE_H */ |