doc: added link to Nicolas Vivien's development blog
[barry.git] / src / tarfile.h
blobda945e5213aa4af9054128f26c0af6099aeeaa60
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 Barry {
31 class Data;
34 namespace reuse {
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;
44 class BXLOCAL TarFile
46 TAR *m_tar;
47 bool m_throw;
48 bool m_writemode;
49 std::string m_last_error;
51 private:
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);
56 public:
57 class TarError : public std::runtime_error
59 public:
60 TarError(const std::string &msg) : std::runtime_error(msg) {}
63 public:
64 explicit TarFile(const char *filename, bool write = false,
65 tartype_t *compress_ops = 0, bool always_throw = false);
66 ~TarFile();
68 const std::string& get_last_error() const { return m_last_error; }
70 bool Close();
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
84 /// a regular file
85 bool ReadNextFilenameOnly(std::string &tarpath);
90 #endif