Translated using Weblate (Chinese (Simplified))
[cygwin-setup.git] / archive.h
blob1299eb12c64730eb0b2d11f3c8c4b5ed6920cdbc
1 /*
2 * Copyright (c) 2001, Robert Collins.
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.
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
12 * Written by Robert Collins <rbtcollins@hotmail.com>
16 #ifndef SETUP_ARCHIVE_H
17 #define SETUP_ARCHIVE_H
19 /* this is the parent class for all archive IO operations. */
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,).
30 typedef enum
32 ARCHIVE_FILE_INVALID,
33 ARCHIVE_FILE_REGULAR,
34 ARCHIVE_FILE_HARDLINK,
35 ARCHIVE_FILE_SYMLINK,
36 ARCHIVE_FILE_DIRECTORY
38 archive_file_t;
41 class archive:public io_stream
43 public:
44 enum extract_results
46 extract_inuse = 7, /* Arbitrary number != 1 */
47 extract_ok = 0,
48 extract_other = 9
50 /* get an archive child class from an io_stream */
51 static archive *extract (io_stream *);
52 /* get an ouput stream for the next files from the archive.
53 * returns NULL on failure.
54 * The stream is not taken over - it will not be automatically deleted
56 virtual io_stream *extract_file () = 0;
57 /* extract the next file to the given prefixURL+Path in one step, and name it with the
58 * given suffix.
59 * returns 1 on failure.
61 static extract_results extract_file (archive *, const std::string&,
62 const std::string&,
63 const std::string = std::string());
65 /*
66 * To create a stream that will be compressed, you should open the url, and then get a new stream
67 * from compress::compress.
69 /* read data - not valid for archives (duh!)
70 * Could be made valid via the read-child-directly model
73 virtual off_t seek (off_t offset, io_stream_seek_t whence) = 0;
75 /* Find out the next stream name -
76 * ie for foo.tar.gz, at offset 0, next_file_name = foo.tar
77 * for foobar that is an compress, next_file_name is the next
78 * extractable filename.
79 * The way this works is that when read returns 0, you are at the end of *a* file.
80 * next_file_name will allow read to be called again, if it returns !NULL
82 virtual const std::string next_file_name () = 0;
83 virtual archive_file_t next_file_type () = 0;
84 virtual const std::string linktarget () = 0;
85 virtual int skip_file () = 0;
86 virtual ~archive() = 0;
87 protected:
88 void operator= (const archive &);
89 archive () {};
90 archive (const archive &);
93 #endif /* SETUP_ARCHIVE_H */