3 /// API for reading and writing sequentially from compressed
7 Copyright (C) 2007-2010, 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__
37 // Compression options... more op sets can be added based on
38 // threading needs, or threading library support.
41 /// Compression op set for zlib, non-threadsafe.
42 extern tartype_t gztar_ops_nonthread
;
49 std::string m_last_error
;
52 bool False(const char *msg
);
53 bool False(const std::string
&str
) { return False(str
.c_str()); }
54 bool False(const std::string
&msg
, int err
);
57 class TarError
: public std::runtime_error
60 TarError(const std::string
&msg
) : std::runtime_error(msg
) {}
64 explicit TarFile(const char *filename
, bool write
= false,
65 tartype_t
*compress_ops
= 0, bool always_throw
= false);
68 const std::string
& get_last_error() const { return m_last_error
; }
72 /// Appends a new file to the current tarfile, using tarpath as
73 /// its internal filename, and data as the complete file contents.
74 /// Uses current date and time as file mtime.
75 bool AppendFile(const char *tarpath
, const std::string
&data
);
77 /// Reads next available file into data, filling tarpath with
78 /// internal filename from tarball.
79 /// Returns false on end of archive.
80 bool ReadNextFile(std::string
&tarpath
, std::string
&data
);
81 bool ReadNextFile(std::string
&tarpath
, Barry::Data
&data
);
83 /// Read next available filename, skipping the data if it is
85 bool ReadNextFilenameOnly(std::string
&tarpath
);