lib: fixed stream output bug in HexDumpParser
[barry.git] / gui / src / tarfile.h
blob68c69a9a86ac9800daee89578f79b9fea2728226
1 ///
2 /// \file tarfile.h
3 /// API for reading and writing sequentially from compressed
4 /// tar files.
6 /*
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__
25 #include <string>
26 #include <stdexcept>
27 #include <libtar.h>
29 namespace reuse {
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;
39 class TarFile
41 TAR *m_tar;
42 bool m_throw;
43 bool m_writemode;
44 std::string m_last_error;
46 private:
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);
51 public:
52 class TarError : public std::runtime_error
54 public:
55 TarError(const std::string &msg) : std::runtime_error(msg) {}
58 public:
59 explicit TarFile(const char *filename, bool write = false,
60 tartype_t *compress_ops = 0, bool always_throw = false);
61 ~TarFile();
63 const std::string& get_last_error() const { return m_last_error; }
65 bool Close();
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
78 /// a regular file
79 bool ReadNextFilenameOnly(std::string &tarpath);
84 #endif