├── .gitignore ├── archive_exception.cpp ├── archive_writer_filter.hpp ├── archive_reader_filter.hpp ├── archive_reader_format.hpp ├── archive_exception.hpp ├── archive_writer_format.hpp ├── archive_reader_entry_buffer.hpp ├── archive_writer.ipp ├── archive_reader_iterator.hpp ├── archive_reader_iterator.cpp ├── archive_reader_entry_buffer.cpp ├── archive_reader.ipp ├── README.md ├── CMakeLists.txt ├── archive_writer.hpp ├── archive_reader.hpp ├── archive_entry.hpp ├── archive_writer.cpp ├── archive_reader.cpp └── archive_entry.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | */ 3 | -------------------------------------------------------------------------------- /archive_exception.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include "archive_exception.hpp" 30 | 31 | namespace ns_archive { 32 | 33 | archive_exception::archive_exception(std::string&& what) noexcept : 34 | _what(std::forward(what)) 35 | { 36 | // 37 | } 38 | 39 | const char* archive_exception::what() const noexcept 40 | { 41 | return _what.c_str(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /archive_writer_filter.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef ARCHIVE_WRITER_FILTER_HPP_INCLUDED 30 | #define ARCHIVE_WRITER_FILTER_HPP_INCLUDED 31 | 32 | namespace ns_archive { 33 | namespace ns_writer { 34 | 35 | enum class filter 36 | { 37 | _NONE, 38 | _GZIP, 39 | _BZIP2, 40 | _COMPRESS, 41 | _GRZIP, 42 | _LRZIP, 43 | _LZIP, 44 | _LZMA, 45 | _LZOP, 46 | _UU, 47 | _XZ 48 | }; 49 | 50 | }} 51 | 52 | #endif // ARCHIVE_WRITER_FILTER_HPP_INCLUDED 53 | -------------------------------------------------------------------------------- /archive_reader_filter.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef ARCHIVE_READER_FILTER_HPP_INCLUDED 30 | #define ARCHIVE_READER_FILTER_HPP_INCLUDED 31 | 32 | namespace ns_archive { 33 | namespace ns_reader { 34 | 35 | enum class filter 36 | { 37 | _ALL, 38 | _BZIP2, 39 | _COMPRESS, 40 | _GZIP, 41 | _LZIP, 42 | _LZMA, 43 | _XZ, 44 | _UU, 45 | _RPM, 46 | _LRZIP, 47 | _LZOP, 48 | _GRZIP 49 | }; 50 | 51 | }} 52 | 53 | #endif // ARCHIVE_READER_FILTER_HPP_INCLUDED 54 | -------------------------------------------------------------------------------- /archive_reader_format.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef ARCHIVE_READER_FORMAT_HPP_INCLUDED 30 | #define ARCHIVE_READER_FORMAT_HPP_INCLUDED 31 | 32 | namespace ns_archive { 33 | namespace ns_reader { 34 | 35 | enum class format 36 | { 37 | _RAW, 38 | _ALL, 39 | _7ZIP, 40 | _AR, 41 | _CAB, 42 | _CPIO, 43 | _ISO9660, 44 | _LHA, 45 | _MTREE, 46 | _RAR, 47 | _TAR, 48 | _XAR, 49 | _ZIP 50 | }; 51 | 52 | }} 53 | 54 | #endif // ARCHIVE_READER_FORMAT_HPP_INCLUDED 55 | -------------------------------------------------------------------------------- /archive_exception.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef ARCHIVE_EXCEPTION_HPP_INCLUDED 30 | #define ARCHIVE_EXCEPTION_HPP_INCLUDED 31 | 32 | #include 33 | #include 34 | 35 | namespace ns_archive { 36 | 37 | class archive_exception : public std::exception 38 | { 39 | public: 40 | archive_exception(std::string&& what) noexcept; 41 | 42 | const char* what() const noexcept override; 43 | 44 | private: 45 | std::string _what; 46 | }; 47 | 48 | } 49 | 50 | #endif // ARCHIVE_EXCEPTION_HPP_INCLUDED 51 | -------------------------------------------------------------------------------- /archive_writer_format.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef ARCHIVE_WRITER_FORMAT_HPP_INCLUDED 30 | #define ARCHIVE_WRITER_FORMAT_HPP_INCLUDED 31 | 32 | namespace ns_archive { 33 | namespace ns_writer { 34 | 35 | enum class format 36 | { 37 | _7ZIP, 38 | _CPIO, 39 | _CPIO_POSIX, 40 | _CPIO_SVR4_NOCRC, 41 | _ISO9660, 42 | _MTREE, 43 | _SHAR, 44 | _SHAR_BASE, 45 | _SHAR_DUMP, 46 | _TAR, 47 | _TAR_GNUTAR, 48 | _TAR_PAX_INTERCHANGE, 49 | _TAR_PAX_RESTRICTED, 50 | _TAR_USTAR, 51 | _XAR, 52 | _ZIP 53 | }; 54 | 55 | }} 56 | 57 | #endif // ARCHIVE_WRITER_FORMAT_HPP_INCLUDED 58 | -------------------------------------------------------------------------------- /archive_reader_entry_buffer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef ARCHIVE_READER_ENTRY_BUFFER_HPP_INCLUDED 30 | #define ARCHIVE_READER_ENTRY_BUFFER_HPP_INCLUDED 31 | 32 | #include 33 | #include "archive.h" 34 | 35 | namespace ns_archive { 36 | namespace ns_reader { 37 | 38 | class entry_buffer : public std::streambuf 39 | { 40 | public: 41 | entry_buffer(archive* archive); 42 | 43 | int underflow(); 44 | 45 | private: 46 | archive *_archive; 47 | size_t _buff_max_size = 8192; 48 | char _buff[8192]; 49 | }; 50 | 51 | }} 52 | 53 | #endif // ARCHIVE_READER_ENTRY_BUFFER_HPP_INCLUDED 54 | -------------------------------------------------------------------------------- /archive_writer.ipp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | namespace ns_archive { 30 | 31 | template 32 | writer writer::make_writer(std::ostream& stream, size_t block_size) 33 | { 34 | writer a_writer( stream, block_size ); 35 | a_writer.init_format(); 36 | a_writer.init_filter(); 37 | a_writer.init_data(); 38 | 39 | return a_writer; 40 | } 41 | 42 | template 43 | writer writer::make_writer(std::ostream& stream, size_t block_size) 44 | { 45 | return make_writer( stream, block_size ); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /archive_reader_iterator.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef ARCHIVE_READER_ITERATOR_HPP_INCLUDED 30 | #define ARCHIVE_READER_ITERATOR_HPP_INCLUDED 31 | 32 | #include "archive_entry.hpp" 33 | #include 34 | 35 | namespace ns_archive { 36 | 37 | class reader; 38 | 39 | namespace ns_reader { 40 | 41 | class iterator 42 | { 43 | public: 44 | iterator(reader* p_reader, bool end_pos); 45 | bool operator!=(const iterator& other) const; 46 | std::shared_ptr operator*(); 47 | const iterator& operator++(); 48 | 49 | private: 50 | bool _end_pos; 51 | reader *_p_reader; 52 | }; 53 | 54 | }} 55 | 56 | #endif // ARCHIVE_READER_ITERATOR_HPP_INCLUDED 57 | -------------------------------------------------------------------------------- /archive_reader_iterator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include "archive_reader_iterator.hpp" 30 | #include "archive_reader.hpp" 31 | 32 | namespace ns_archive { 33 | namespace ns_reader { 34 | 35 | iterator::iterator(reader* p_reader, bool end_pos) : 36 | _end_pos( end_pos ), 37 | _p_reader( p_reader ) 38 | { 39 | // 40 | } 41 | 42 | bool iterator::operator!=(const iterator& other) const 43 | { 44 | return _end_pos != other._end_pos; 45 | } 46 | 47 | std::shared_ptr iterator::operator*() 48 | { 49 | return _p_reader->get_next_entry(); 50 | } 51 | 52 | const iterator& iterator::operator++() 53 | { 54 | if(!_p_reader->has_next_entry()) 55 | { 56 | _end_pos = true; 57 | } 58 | 59 | return *this; 60 | } 61 | 62 | }} 63 | -------------------------------------------------------------------------------- /archive_reader_entry_buffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include "archive_reader_entry_buffer.hpp" 30 | 31 | #include "archive_exception.hpp" 32 | 33 | namespace ns_archive { 34 | namespace ns_reader { 35 | 36 | entry_buffer::entry_buffer(archive* archive) : 37 | _archive(archive) 38 | { 39 | // 40 | } 41 | 42 | int entry_buffer::underflow() 43 | { 44 | if(gptr() == egptr()) 45 | { 46 | size_t _buff_size = archive_read_data(_archive, _buff, _buff_max_size); 47 | 48 | if( _buff_size < 0 ) 49 | { 50 | throw archive_exception( "Archive reader buffer reading error." ); 51 | } 52 | 53 | if( _buff_size ) 54 | { 55 | setg(_buff, _buff, _buff + _buff_size); 56 | } 57 | } 58 | 59 | return this->gptr() == this->egptr() 60 | ? std::char_traits::eof() 61 | : std::char_traits::to_int_type(*gptr()); 62 | } 63 | 64 | }} 65 | -------------------------------------------------------------------------------- /archive_reader.ipp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | namespace ns_archive { 30 | 31 | template 32 | reader reader::make_reader( std::istream& stream, size_t block_size ) 33 | { 34 | reader a_reader( stream, block_size ); 35 | a_reader.init_format(); 36 | a_reader.init_data(); 37 | 38 | return a_reader; 39 | } 40 | 41 | template 42 | reader reader::make_reader( std::istream& stream, size_t block_size ) 43 | { 44 | reader a_reader( stream, block_size ); 45 | a_reader.init_format(); 46 | a_reader.init_filter(); 47 | a_reader.init_data(); 48 | 49 | return a_reader; 50 | } 51 | 52 | template 53 | reader reader::make_reader( std::istream& stream, size_t block_size ) 54 | { 55 | reader a_reader( stream, block_size ); 56 | a_reader.init_format(); 57 | a_reader.init_filter(); 58 | a_reader.init_data(); 59 | 60 | return a_reader; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | libarchive cpp wrapper library 2 | ============================ 3 | This is a C++ wrapper arround libarchive library. 4 | 5 | Dependencies 6 | ============================ 7 | - libarchive (https://github.com/libarchive/libarchive) 8 | - CMake (http://cmake.org/) 9 | 10 | Current version was tested with gcc 4.9 on 64 bit Linux - Ubuntu 14.04 with libarchive13 3.1.2-9 11 | 12 | Example usage 13 | ============================ 14 | 15 | Read from archive 16 | 17 | ```C++ 18 | #include "archive_reader.hpp" 19 | #include "archive_exception.hpp" 20 | 21 | ... 22 | 23 | try 24 | { 25 | namespace ar = ns_archive::ns_reader; 26 | std::fstream fs("some_tar_file.tar"); 27 | ns_archive::reader reader = ns_archive::reader::make_reader(fs, 10240); 28 | 29 | for(auto entry : reader) 30 | { 31 | // get file name 32 | std::cout << entry->get_header_value_pathname() << std::endl; 33 | // get file content 34 | std::cout << entry->get_stream().rdbuf() << std::endl << std::endl; 35 | } 36 | } 37 | catch(ns_archive::archive_exception& e) 38 | { 39 | std::cout << e.what() << std::endl; 40 | } 41 | ``` 42 | 43 | Write to archive 44 | 45 | ```C++ 46 | #include "archive_writer.hpp" 47 | #include "archive_exception.hpp" 48 | 49 | ... 50 | 51 | try 52 | { 53 | namespace ar = ns_archive::ns_reader; 54 | std::ofstream outfs("output.tar"); 55 | ns_archive::writer writer2 = ns_archive::writer::make_writer(outfs, 10240); 56 | std::stringstream ss; 57 | ss << "foo"; 58 | 59 | ns_archive::entry out_entry(ss); 60 | out_entry.set_header_value_pathname("foo.txt"); 61 | writer.add_entry(out_entry); 62 | } 63 | catch(ns_archive::archive_exception& e) 64 | { 65 | std::cout << e.what() << std::endl; 66 | } 67 | ``` 68 | 69 | Copy archive 70 | 71 | ```C++ 72 | #include "archive_reader.hpp" 73 | #include "archive_writer.hpp" 74 | #include "archive_exception.hpp" 75 | 76 | ... 77 | 78 | try 79 | { 80 | namespace ar = ns_archive::ns_reader; 81 | std::fstream fs( "some_tar_file.tar" ); 82 | ns_archive::reader reader = ns_archive::reader::make_reader(fs, 10240); 83 | 84 | std::ofstream outfs( "out.tar" ); 85 | ns_archive::writer writer = ns_archive::writer::make_writer(outfs, 10240); 86 | 87 | for(auto entry : reader) 88 | { 89 | writer.add_entry(*entry.get()); 90 | } 91 | } 92 | catch(ns_archive::archive_exception& e) 93 | { 94 | std::cout << e.what() << std::endl; 95 | } 96 | ``` 97 | 98 | License 99 | ============================ 100 | BSD 2-Clause license (http://opensource.org/licenses/bsd-license.php) 101 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #BSD 2-Clause license 2 | # 3 | #Copyright (c) 2014, Domen Vrankar 4 | #All rights reserved. 5 | # 6 | #Redistribution and use in source and binary forms, with or without modification, 7 | #are permitted provided that the following conditions are met: 8 | # 9 | #1. Redistributions of source code must retain the above copyright notice, this 10 | # list of conditions and the following disclaimer. 11 | # 12 | #2. Redistributions in binary form must reproduce the above copyright notice, 13 | # this list of conditions and the following disclaimer in the documentation 14 | # and/or other materials provided with the distribution. 15 | # 16 | #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | #ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | #WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | #DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | #ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | #(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | #LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | #ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | #(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | #SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | cmake_minimum_required( VERSION 2.8.12 ) 28 | 29 | project(archive_cpp_wrapper) 30 | 31 | if(NOT libarchive_LIBRARIES) 32 | # set defaults for ubuntu 33 | set( libarchive_LIBRARIES "/usr/lib/x86_64-linux-gnu/libarchive.so" ) 34 | set( libarchive_INCLUDE_DIRS "" ) 35 | endif() 36 | 37 | set(CMAKE_CXX_FLAGS "-Wall -std=c++11") 38 | 39 | file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp") 40 | file(GLOB template_implementations "${CMAKE_CURRENT_SOURCE_DIR}/*.ipp") 41 | 42 | include_directories( ${libarchive_INCLUDE_DIRS} ) 43 | 44 | add_library( ${PROJECT_NAME} SHARED 45 | 46 | archive_entry.cpp 47 | 48 | archive_reader.cpp 49 | archive_reader_iterator.cpp 50 | archive_reader_entry_buffer.cpp 51 | 52 | archive_writer.cpp 53 | 54 | archive_exception.cpp 55 | 56 | ${headers} 57 | ${template_implementations} 58 | ) 59 | 60 | target_link_libraries( ${PROJECT_NAME} ${libarchive_LIBRARIES} ) 61 | 62 | set_target_properties( ${PROJECT_NAME} PROPERTIES VERSION "1.0.0" SOVERSION "1" ) 63 | 64 | install( 65 | TARGETS ${PROJECT_NAME} LIBRARY 66 | DESTINATION lib 67 | ) 68 | 69 | install( 70 | FILES 71 | 72 | archive_reader_entry_buffer.hpp 73 | archive_reader.hpp 74 | archive_writer_format.hpp 75 | archive_exception.hpp 76 | archive_reader_iterator.hpp 77 | archive_reader_format.hpp 78 | archive_writer_filter.hpp 79 | archive_reader_filter.hpp 80 | archive_entry.hpp 81 | archive_writer.hpp 82 | archive_reader.ipp 83 | archive_writer.ipp 84 | 85 | DESTINATION include 86 | ) 87 | -------------------------------------------------------------------------------- /archive_writer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef ARCHIVE_WRITER_HPP_INCLUDED 30 | #define ARCHIVE_WRITER_HPP_INCLUDED 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include "archive_writer_format.hpp" 37 | #include "archive_writer_filter.hpp" 38 | #include "archive_entry.hpp" 39 | 40 | namespace ns_archive { 41 | 42 | namespace ns_writer { 43 | 44 | ssize_t writer_callback( archive* archive, void* out_writer_container, const void* buff, size_t buff_size ); 45 | 46 | } // ns_writer 47 | 48 | class writer 49 | { 50 | public: 51 | writer(writer&&) = default; 52 | 53 | writer(const writer&) = delete; 54 | writer& operator=(const writer&) = delete; 55 | 56 | void finish(); 57 | 58 | template 59 | static writer make_writer(std::ostream& stream, size_t block_size); 60 | 61 | template 62 | static writer make_writer(std::ostream& stream, size_t block_size); 63 | 64 | void add_entry( entry& a_entry ); 65 | 66 | private: 67 | writer(std::ostream& stream, size_t block_size); 68 | 69 | template 70 | void init_format(); 71 | 72 | template 73 | void init_filter(); 74 | 75 | void init_data(); 76 | 77 | std::shared_ptr _archive; 78 | std::ostream& _writer_container; 79 | size_t _block_size; 80 | 81 | friend ssize_t ns_writer::writer_callback( archive* archive, void* out_writer_container, const void* buff, size_t buff_size ); 82 | }; 83 | 84 | } 85 | 86 | #include "archive_writer.ipp" 87 | 88 | #endif // ARCHIVE_WRITER_HPP_INCLUDED 89 | 90 | -------------------------------------------------------------------------------- /archive_reader.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef ARCHIVE_READER_HPP_INCLUDED 30 | #define ARCHIVE_READER_HPP_INCLUDED 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "archive_reader_format.hpp" 38 | #include "archive_reader_filter.hpp" 39 | #include "archive_entry.hpp" 40 | #include "archive_reader_iterator.hpp" 41 | 42 | namespace ns_archive { 43 | namespace ns_reader { 44 | 45 | ssize_t reader_callback( archive* archive, void* in_reader_container, const void** buff ); 46 | 47 | } // ns_reader 48 | 49 | class reader 50 | { 51 | public: 52 | reader(reader&&) = default; 53 | 54 | reader(const reader&) = delete; 55 | reader& operator=(const reader&) = delete; 56 | 57 | template 58 | static reader make_reader( std::istream& stream, size_t block_size ); 59 | 60 | template 61 | static reader make_reader( std::istream& stream, size_t block_size); 62 | 63 | template 64 | static reader make_reader( std::istream& stream, size_t block_size); 65 | 66 | std::shared_ptr get_next_entry(); 67 | bool has_next_entry(); 68 | 69 | ns_reader::iterator begin(); 70 | ns_reader::iterator end(); 71 | 72 | private: 73 | reader( std::istream& stream, size_t block_size ); 74 | 75 | template 76 | void init_format(); 77 | 78 | template 79 | void init_filter(); 80 | 81 | void init_data(); 82 | 83 | std::shared_ptr _archive; 84 | std::shared_ptr _next_entry = nullptr; 85 | std::shared_ptr _buffer; 86 | 87 | class reader_container 88 | { 89 | public: 90 | reader_container( std::istream& stream, size_t block_size ) : 91 | _stream( stream ) 92 | { 93 | _buff.resize( block_size ); 94 | } 95 | public: 96 | std::istream& _stream; 97 | std::vector _buff; 98 | } _reader_container; 99 | 100 | friend ssize_t ns_reader::reader_callback( archive* archive, void* in_reader_container, const void** buff ); 101 | }; 102 | 103 | } 104 | 105 | #include "archive_reader.ipp" 106 | 107 | #endif // ARCHIVE_READER_HPP_INCLUDED 108 | -------------------------------------------------------------------------------- /archive_entry.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef ARCHIVE_WRITER_ENTRY_HPP_INCLUDED 30 | #define ARCHIVE_WRITER_ENTRY_HPP_INCLUDED 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "archive_reader_entry_buffer.hpp" 41 | 42 | namespace ns_archive { 43 | 44 | class entry 45 | { 46 | public: 47 | entry(archive_entry* entry, ns_reader::entry_buffer& entry_buffer); // TODO change to private and friend reader? 48 | entry(std::istream& stream); 49 | 50 | void clear_entry(std::istream& stream); 51 | 52 | int64_t get_header_value_gid(); 53 | int64_t get_header_value_ino(); 54 | int64_t get_header_value_ino64(); 55 | int64_t get_header_value_size(); 56 | int64_t get_header_value_uid(); 57 | mode_t get_header_value_mode(); 58 | mode_t get_header_value_perm(); 59 | dev_t get_header_value_rdev(); 60 | dev_t get_header_value_rdevmajor(); 61 | dev_t get_header_value_rdevminor(); 62 | std::string get_header_value_gname(); 63 | std::string get_header_value_hardlink(); 64 | std::string get_header_value_pathname(); 65 | std::string get_header_value_symlink(); 66 | std::string get_header_value_uname(); 67 | unsigned int get_header_value_nlink(); 68 | 69 | 70 | void set_header_value_gid(int64_t value); 71 | void set_header_value_ino(int64_t value); 72 | void set_header_value_ino64(int64_t value); 73 | void set_header_value_size(int64_t value); 74 | void set_header_value_uid(int64_t value); 75 | void set_header_value_mode(mode_t value); 76 | void set_header_value_perm(mode_t value); 77 | void set_header_value_rdev(dev_t value); 78 | void set_header_value_rdevmajor(dev_t value); 79 | void set_header_value_rdevminor(dev_t value); 80 | void set_header_value_gname(const std::string& value); 81 | void set_header_value_hardlink(const std::string& value); 82 | void set_header_value_link(const std::string& value); 83 | void set_header_value_pathname(const std::string& value); 84 | void set_header_value_symlink(const std::string& value); 85 | void set_header_value_uname(const std::string& value); 86 | void set_header_value_nlink(unsigned int value); 87 | void set_header_value_mtime(time_t time, long value); 88 | 89 | archive_entry* get_entry() const; 90 | std::istream& get_stream(); 91 | 92 | private: 93 | std::shared_ptr _entry; 94 | std::istream _stream; 95 | bool _has_stream; 96 | }; 97 | 98 | } 99 | 100 | #endif // ARCHIVE_WRITER_ENTRY_HPP_INCLUDED 101 | -------------------------------------------------------------------------------- /archive_writer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include "archive_writer.hpp" 30 | 31 | #include "archive_exception.hpp" 32 | #include "string" 33 | 34 | #include 35 | #include 36 | 37 | namespace ns_archive { 38 | 39 | writer::writer(std::ostream& stream, size_t block_size) : 40 | _archive( archive_write_new(), [](archive* archive){ archive_write_free(archive); } ), // errors in destructor will be silently ignored 41 | _writer_container( stream ), 42 | _block_size( block_size ) 43 | { 44 | // TODO enable setting of padding parameters in constructor 45 | /// OTHER OPTION archive_write_set_bytes_per_block( _archive.get(), 0 ); // prevent zero padding of last block (this also causes write callback to be called on each write without blocking until a block is full) 46 | archive_write_set_bytes_in_last_block( _archive.get(), 1 ); // prevent zero padding of last block 47 | } 48 | 49 | void writer::finish() 50 | { 51 | archive_write_close(_archive.get()); // TODO throw on error 52 | } 53 | 54 | void writer::add_entry( entry& a_entry ) 55 | { 56 | if( archive_write_header( _archive.get(), a_entry.get_entry() ) != ARCHIVE_OK) 57 | { 58 | throw archive_exception( "Error writing header to archive!" ); 59 | } 60 | 61 | auto& stream = a_entry.get_stream(); 62 | std::vector buffer( _block_size ); 63 | 64 | while( stream ) 65 | { 66 | stream.read( &buffer[0], _block_size ); 67 | archive_write_data( _archive.get(), &buffer[0], stream.gcount() ); 68 | } 69 | } 70 | 71 | /// ---------------- init_format ---------------- // 72 | 73 | #define WRITER_INIT_FORMAT(__FORMAT__, __FUNCTION_SUFFIX__) \ 74 | template<> \ 75 | void writer::init_format()\ 76 | {\ 77 | archive_write_set_format_##__FUNCTION_SUFFIX__(_archive.get());\ 78 | } 79 | 80 | WRITER_INIT_FORMAT(7ZIP, 7zip) 81 | WRITER_INIT_FORMAT(CPIO_SVR4_NOCRC, cpio_newc) 82 | WRITER_INIT_FORMAT(ISO9660, iso9660) 83 | WRITER_INIT_FORMAT(MTREE, mtree) 84 | WRITER_INIT_FORMAT(SHAR, shar) 85 | WRITER_INIT_FORMAT(SHAR_BASE, shar) 86 | WRITER_INIT_FORMAT(SHAR_DUMP, shar_dump) 87 | WRITER_INIT_FORMAT(TAR, pax_restricted) 88 | WRITER_INIT_FORMAT(TAR_GNUTAR, gnutar) 89 | WRITER_INIT_FORMAT(TAR_PAX_INTERCHANGE, pax) 90 | WRITER_INIT_FORMAT(TAR_PAX_RESTRICTED, pax_restricted) 91 | WRITER_INIT_FORMAT(TAR_USTAR, ustar) 92 | WRITER_INIT_FORMAT(XAR, xar) 93 | WRITER_INIT_FORMAT(ZIP, zip) 94 | 95 | /// ---------------- init_filter ---------------- // 96 | 97 | #define WRITER_INIT_FILTER(__FILTER__, __FUNCTION_SUFFIX__) \ 98 | template<> \ 99 | void writer::init_filter()\ 100 | {\ 101 | archive_write_add_filter_##__FUNCTION_SUFFIX__(_archive.get());\ 102 | } 103 | 104 | WRITER_INIT_FILTER(NONE, none) 105 | WRITER_INIT_FILTER(GZIP, gzip) 106 | WRITER_INIT_FILTER(BZIP2, bzip2) 107 | WRITER_INIT_FILTER(COMPRESS, compress) 108 | WRITER_INIT_FILTER(GRZIP, grzip) 109 | WRITER_INIT_FILTER(LRZIP, lrzip) 110 | WRITER_INIT_FILTER(LZIP, lzip) 111 | WRITER_INIT_FILTER(LZMA, lzma) 112 | WRITER_INIT_FILTER(LZOP, lzip) 113 | WRITER_INIT_FILTER(UU, uuencode) 114 | WRITER_INIT_FILTER(XZ, xz) 115 | 116 | /// ---------------- init_data ---------------- // 117 | namespace ns_writer { 118 | 119 | ssize_t writer_callback( archive* archive, void* out_writer_container, const void* buff, size_t buff_size ) 120 | { 121 | std::ostream* stream = reinterpret_cast( out_writer_container ); 122 | 123 | stream->write( (const char*)buff, buff_size ); 124 | 125 | return buff_size; 126 | } 127 | 128 | } // ns_writer 129 | 130 | void writer::init_data() 131 | { 132 | if(archive_write_open( _archive.get(), &_writer_container, nullptr, ns_writer::writer_callback, nullptr ) != ARCHIVE_OK) 133 | { 134 | throw archive_exception( "Failed to write the archive!" ); 135 | } 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /archive_reader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include "archive_reader.hpp" 30 | 31 | #include "archive_exception.hpp" 32 | #include 33 | 34 | namespace ns_archive { 35 | 36 | reader::reader(std::istream& stream, size_t block_size) : 37 | _archive( archive_read_new(), [](archive* archive){ archive_read_free(archive); } ), // errors in destructor will be silently ignored 38 | _buffer( new ns_reader::entry_buffer( _archive.get() ) ), 39 | _reader_container( stream, block_size ) 40 | { 41 | // 42 | } 43 | 44 | std::shared_ptr reader::get_next_entry() 45 | { 46 | if(!has_next_entry()) 47 | { 48 | throw archive_exception( "get_next_entry was called after all the entries were read" ); 49 | } 50 | 51 | std::shared_ptr a_entry( _next_entry ); 52 | _next_entry = nullptr; 53 | 54 | return a_entry; 55 | } 56 | 57 | bool reader::has_next_entry() 58 | { 59 | bool has_next = true; 60 | 61 | if(_next_entry == nullptr) 62 | { 63 | archive_entry* a_entry; 64 | has_next = (archive_read_next_header(_archive.get(), &a_entry) == ARCHIVE_OK); 65 | 66 | if(has_next) 67 | { 68 | _next_entry = std::make_shared( a_entry, *_buffer.get() ); 69 | } 70 | } 71 | 72 | return has_next; 73 | } 74 | 75 | /// ---------------- init_format ---------------- // 76 | 77 | #define READER_INIT_FORMAT(__FORMAT__, __FUNCTION_SUFFIX__) \ 78 | template<> \ 79 | void reader::init_format()\ 80 | {\ 81 | archive_read_support_format_##__FUNCTION_SUFFIX__(_archive.get());\ 82 | } 83 | 84 | READER_INIT_FORMAT(RAW, raw) 85 | READER_INIT_FORMAT(ALL, all) 86 | READER_INIT_FORMAT(7ZIP, 7zip) 87 | READER_INIT_FORMAT(AR, ar) 88 | READER_INIT_FORMAT(CAB, cab) 89 | READER_INIT_FORMAT(CPIO, cpio) 90 | READER_INIT_FORMAT(ISO9660, iso9660) 91 | READER_INIT_FORMAT(LHA, lha) 92 | READER_INIT_FORMAT(MTREE, mtree) 93 | READER_INIT_FORMAT(RAR, rar) 94 | READER_INIT_FORMAT(TAR, tar) 95 | READER_INIT_FORMAT(XAR, xar) 96 | READER_INIT_FORMAT(ZIP, zip) 97 | 98 | /// ---------------- init_filter ---------------- // 99 | 100 | #define READER_INIT_FILTER(__FILTER__, __FUNCTION_SUFFIX__) \ 101 | template<> \ 102 | void reader::init_filter()\ 103 | {\ 104 | archive_read_support_filter_##__FUNCTION_SUFFIX__(_archive.get());\ 105 | } 106 | 107 | READER_INIT_FILTER(ALL, all) 108 | READER_INIT_FILTER(BZIP2, bzip2) 109 | READER_INIT_FILTER(COMPRESS, compress) 110 | READER_INIT_FILTER(GZIP, gzip) 111 | READER_INIT_FILTER(LZIP, lzip) 112 | READER_INIT_FILTER(LZMA, lzma) 113 | READER_INIT_FILTER(XZ, xz) 114 | READER_INIT_FILTER(UU, uu) 115 | READER_INIT_FILTER(RPM, rpm) 116 | READER_INIT_FILTER(LRZIP, lrzip) 117 | READER_INIT_FILTER(LZOP, lzop) 118 | READER_INIT_FILTER(GRZIP, gzip) 119 | 120 | /// ---------------- init_data ---------------- // 121 | namespace ns_reader { 122 | 123 | ssize_t reader_callback( archive* archive, void* in_reader_container, const void** buff ) 124 | { 125 | reader::reader_container* p_reader_container = reinterpret_cast( in_reader_container ); 126 | 127 | p_reader_container->_stream.read( &p_reader_container->_buff[0], p_reader_container->_buff.size() ); 128 | *buff = &p_reader_container->_buff[0]; 129 | 130 | return p_reader_container->_stream.gcount(); 131 | } 132 | 133 | } // ns_reader 134 | 135 | void reader::init_data() 136 | { 137 | if(archive_read_open( _archive.get(), &_reader_container, nullptr, ns_reader::reader_callback, nullptr ) != ARCHIVE_OK) 138 | { 139 | throw archive_exception( "Failed to read the archive!" ); 140 | } 141 | } 142 | 143 | ns_reader::iterator reader::begin() 144 | { 145 | return ns_reader::iterator( this, false ); 146 | } 147 | 148 | ns_reader::iterator reader::end() 149 | { 150 | return ns_reader::iterator( this, true ); 151 | } 152 | 153 | } 154 | -------------------------------------------------------------------------------- /archive_entry.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 2-Clause license 3 | 4 | Copyright (c) 2014, Domen Vrankar 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include "archive_entry.hpp" 30 | #include "archive_exception.hpp" 31 | 32 | namespace ns_archive { 33 | 34 | entry::entry(archive_entry* entry, ns_reader::entry_buffer& entry_buffer) : 35 | _entry( entry, []( archive_entry* entry ){ /* do nothing as this entry is owned by a reader */ } ), 36 | _stream(&entry_buffer), 37 | _has_stream(true) 38 | { 39 | // 40 | } 41 | 42 | entry::entry(std::istream& stream) : 43 | _entry( archive_entry_new(), []( archive_entry* entry ){ archive_entry_free( entry ); } ), 44 | _stream( stream.rdbuf() ), 45 | _has_stream(true) 46 | { 47 | auto* pbuf = _stream.rdbuf(); 48 | std::size_t stream_size = pbuf->pubseekoff( 0, _stream.end, _stream.in ); 49 | pbuf->pubseekpos( 0, _stream.in ); 50 | 51 | archive_entry_set_mode( _entry.get(), S_IFREG ); 52 | archive_entry_set_size( _entry.get(), stream_size ); 53 | } 54 | 55 | void entry::clear_entry(std::istream& stream) 56 | { 57 | archive_entry_clear( _entry.get() ); 58 | _stream.rdbuf( stream.rdbuf() ); 59 | _has_stream = true; 60 | 61 | auto* pbuf = _stream.rdbuf(); 62 | std::size_t stream_size = pbuf->pubseekoff( 0, _stream.end, _stream.in ); 63 | pbuf->pubseekpos( 0, _stream.in ); 64 | 65 | archive_entry_set_mode( _entry.get(), S_IFREG ); 66 | archive_entry_set_size( _entry.get(), stream_size ); 67 | } 68 | 69 | //-------------------------getters---------------------------// 70 | int64_t entry::get_header_value_gid() 71 | { 72 | return archive_entry_gid(_entry.get()); 73 | } 74 | 75 | int64_t entry::get_header_value_ino() 76 | { 77 | return archive_entry_ino(_entry.get()); 78 | } 79 | 80 | int64_t entry::get_header_value_ino64() 81 | { 82 | return archive_entry_ino64(_entry.get()); 83 | } 84 | 85 | int64_t entry::get_header_value_size() 86 | { 87 | return archive_entry_size(_entry.get()); 88 | } 89 | 90 | int64_t entry::get_header_value_uid() 91 | { 92 | return archive_entry_uid(_entry.get()); 93 | } 94 | 95 | mode_t entry::get_header_value_mode() 96 | { 97 | return archive_entry_mode(_entry.get()); 98 | } 99 | 100 | mode_t entry::get_header_value_perm() 101 | { 102 | return archive_entry_perm(_entry.get()); 103 | } 104 | 105 | dev_t entry::get_header_value_rdev() 106 | { 107 | return archive_entry_rdev(_entry.get()); 108 | } 109 | 110 | dev_t entry::get_header_value_rdevmajor() 111 | { 112 | return archive_entry_rdevmajor(_entry.get()); 113 | } 114 | 115 | dev_t entry::get_header_value_rdevminor() 116 | { 117 | return archive_entry_rdevminor(_entry.get()); 118 | } 119 | 120 | std::string entry::get_header_value_gname() 121 | { 122 | return archive_entry_gname(_entry.get()); 123 | } 124 | 125 | std::string entry::get_header_value_hardlink() 126 | { 127 | return archive_entry_hardlink(_entry.get()); 128 | } 129 | 130 | std::string entry::get_header_value_pathname() 131 | { 132 | return archive_entry_pathname(_entry.get()); 133 | } 134 | 135 | std::string entry::get_header_value_symlink() 136 | { 137 | return archive_entry_symlink(_entry.get()); 138 | } 139 | 140 | std::string entry::get_header_value_uname() 141 | { 142 | return archive_entry_uname(_entry.get()); 143 | } 144 | 145 | unsigned int entry::get_header_value_nlink() 146 | { 147 | return archive_entry_nlink(_entry.get()); 148 | } 149 | 150 | //-------------------------setters---------------------------// 151 | void entry::set_header_value_gid(int64_t value) 152 | { 153 | archive_entry_set_gid(_entry.get(), value); 154 | } 155 | 156 | void entry::set_header_value_ino(int64_t value) 157 | { 158 | archive_entry_set_ino(_entry.get(), value); 159 | } 160 | 161 | void entry::set_header_value_ino64(int64_t value) 162 | { 163 | archive_entry_set_ino64(_entry.get(), value); 164 | } 165 | 166 | void entry::set_header_value_size(int64_t value) 167 | { 168 | archive_entry_set_size(_entry.get(), value); 169 | } 170 | 171 | void entry::set_header_value_uid(int64_t value) 172 | { 173 | archive_entry_set_uid(_entry.get(), value); 174 | } 175 | 176 | void entry::set_header_value_mode(mode_t value) 177 | { 178 | archive_entry_set_mode(_entry.get(), value); 179 | } 180 | 181 | void entry::set_header_value_perm(mode_t value) 182 | { 183 | archive_entry_set_perm(_entry.get(), value); 184 | } 185 | 186 | void entry::set_header_value_rdev(dev_t value) 187 | { 188 | archive_entry_set_rdev(_entry.get(), value); 189 | } 190 | 191 | void entry::set_header_value_rdevmajor(dev_t value) 192 | { 193 | archive_entry_set_rdevmajor(_entry.get(), value); 194 | } 195 | 196 | void entry::set_header_value_rdevminor(dev_t value) 197 | { 198 | archive_entry_set_rdevminor(_entry.get(), value); 199 | } 200 | 201 | void entry::set_header_value_gname(const std::string& value) 202 | { 203 | archive_entry_set_gname(_entry.get(), value.c_str()); 204 | } 205 | 206 | void entry::set_header_value_hardlink(const std::string& value) 207 | { 208 | archive_entry_set_hardlink(_entry.get(), value.c_str()); 209 | } 210 | 211 | void entry::set_header_value_link(const std::string& value) 212 | { 213 | archive_entry_set_link(_entry.get(), value.c_str()); 214 | } 215 | 216 | void entry::set_header_value_pathname(const std::string& value) 217 | { 218 | archive_entry_set_pathname(_entry.get(), value.c_str()); 219 | } 220 | 221 | void entry::set_header_value_symlink(const std::string& value) 222 | { 223 | archive_entry_set_symlink(_entry.get(), value.c_str()); 224 | } 225 | 226 | void entry::set_header_value_uname(const std::string& value) 227 | { 228 | archive_entry_set_uname(_entry.get(), value.c_str()); 229 | } 230 | 231 | void entry::set_header_value_nlink(unsigned int value) 232 | { 233 | archive_entry_set_nlink(_entry.get(), value); 234 | } 235 | 236 | void entry::set_header_value_mtime(time_t time, long value) 237 | { 238 | archive_entry_set_mtime(_entry.get(), time, value); 239 | } 240 | 241 | archive_entry* entry::get_entry() const 242 | { 243 | return _entry.get(); 244 | } 245 | 246 | std::istream& entry::get_stream() 247 | { 248 | if(_has_stream) 249 | { 250 | _has_stream = false; 251 | 252 | return _stream; 253 | } 254 | 255 | throw archive_exception( "Archive entry stream was already read!" ); 256 | } 257 | 258 | } 259 | --------------------------------------------------------------------------------