3 /// API for reading and writing sequentially from compressed
7 Copyright (C) 2007-2008, Chris Frey <cdfrey@foursquare.net>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __REUSE_TARFILE_H__
23 #define __REUSE_TARFILE_H__
32 // Compression options... more op sets can be added based on
33 // threading needs, or threading library support.
36 /// Compression op set for zlib, non-threadsafe.
37 extern tartype_t gztar_ops_nonthread
;
44 std::string m_last_error
;
47 bool False(const char *msg
);
48 bool False(const std::string
&str
) { return False(str
.c_str()); }
49 bool False(const std::string
&msg
, int err
);
52 class TarError
: public std::runtime_error
55 TarError(const std::string
&msg
) : std::runtime_error(msg
) {}
59 explicit TarFile(const char *filename
, bool write
= false,
60 tartype_t
*compress_ops
= 0, bool always_throw
= false);
63 const std::string
& get_last_error() const { return m_last_error
; }
67 /// Appends a new file to the current tarfile, using tarpath as
68 /// its internal filename, and data as the complete file contents.
69 /// Uses current date and time as file mtime.
70 bool AppendFile(const char *tarpath
, const std::string
&data
);
72 /// Reads next available file into data, filling tarpath with
73 /// internal filename from tarball.
74 /// Returns false on end of archive.
75 bool ReadNextFile(std::string
&tarpath
, std::string
&data
);
77 /// Read next available filename, skipping the data if it is
79 bool ReadNextFilenameOnly(std::string
&tarpath
);