lib: added back m_seen_usb_error check in DefaultRead()
[barry.git] / src / tarfile.h
blobf48a4611c9b74228a4cfbde9a4eefc636076fac0
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 "dll.h"
26 #include <string>
27 #include <stdexcept>
28 #include <libtar.h>
30 namespace reuse {
33 // Compression options... more op sets can be added based on
34 // threading needs, or threading library support.
37 /// Compression op set for zlib, non-threadsafe.
38 extern tartype_t gztar_ops_nonthread;
40 class BXLOCAL TarFile
42 TAR *m_tar;
43 bool m_throw;
44 bool m_writemode;
45 std::string m_last_error;
47 private:
48 bool False(const char *msg);
49 bool False(const std::string &str) { return False(str.c_str()); }
50 bool False(const std::string &msg, int err);
52 public:
53 class TarError : public std::runtime_error
55 public:
56 TarError(const std::string &msg) : std::runtime_error(msg) {}
59 public:
60 explicit TarFile(const char *filename, bool write = false,
61 tartype_t *compress_ops = 0, bool always_throw = false);
62 ~TarFile();
64 const std::string& get_last_error() const { return m_last_error; }
66 bool Close();
68 /// Appends a new file to the current tarfile, using tarpath as
69 /// its internal filename, and data as the complete file contents.
70 /// Uses current date and time as file mtime.
71 bool AppendFile(const char *tarpath, const std::string &data);
73 /// Reads next available file into data, filling tarpath with
74 /// internal filename from tarball.
75 /// Returns false on end of archive.
76 bool ReadNextFile(std::string &tarpath, std::string &data);
78 /// Read next available filename, skipping the data if it is
79 /// a regular file
80 bool ReadNextFilenameOnly(std::string &tarpath);
85 #endif