-(add) initial archive reader wrapper

This commit is contained in:
Domen Vrankar 2014-06-17 00:09:12 +02:00
parent ff34cb2ab2
commit 35a4692f53
18 changed files with 1061 additions and 0 deletions

25
CMakeLists.txt Normal file
View File

@ -0,0 +1,25 @@
cmake_minimum_required( VERSION 2.8.12 )
project(libarchive_cpp_wrapper)
set(CMAKE_CXX_FLAGS "-Wall -std=c++11")
file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp")
file(GLOB template_implementations "${CMAKE_CURRENT_SOURCE_DIR}/*.tpp")
add_library( ${PROJECT_NAME} SHARED
archive_reader.cpp
archive_reader_entry.cpp
archive_reader_iterator.cpp
archive_reader_file_container.cpp
archive_reader_memory_container.cpp
archive_reader_entry_buffer.cpp
archive_exception.cpp
${headers}
${template_implementations}
)
target_link_libraries( ${PROJECT_NAME} /usr/lib/x86_64-linux-gnu/libarchive.so.13 )

16
archive_exception.cpp Normal file
View File

@ -0,0 +1,16 @@
#include "archive_exception.hpp"
namespace ns_archive {
archive_exception::archive_exception(const std::string& what) :
_what(what)
{
//
}
const char* archive_exception::what()
{
return _what.c_str();
}
}

22
archive_exception.hpp Normal file
View File

@ -0,0 +1,22 @@
#ifndef ARCHIVE_EXCEPTION_HPP_INCLUDED
#define ARCHIVE_EXCEPTION_HPP_INCLUDED
#include <exception>
#include <string>
namespace ns_archive {
class archive_exception : public std::exception
{
public:
archive_exception(const std::string& what);
const char* what();
private:
std::string _what;
};
}
#endif // ARCHIVE_EXCEPTION_HPP_INCLUDED

151
archive_reader.cpp Normal file
View File

@ -0,0 +1,151 @@
/*
BSD 2-Clause license
Copyright (c) 2014, Domen Vrankar
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "archive_reader.hpp"
#include "archive_reader_file_container.hpp"
#include "archive_reader_memory_container.hpp"
#include "archive_exception.hpp"
#include <archive_entry.h>
namespace ns_archive {
reader::reader() :
_archive( archive_read_new(), [](archive* archive){ archive_read_free(archive); } ) // errors in destructor will be silently ignored
{
//
}
ns_reader::entry* reader::get_next_entry()
{
if(!has_next_entry())
{
throw archive_exception( "get_next_entry was called after all the entries were read" );
}
ns_reader::entry* entry = _next_entry;
_next_entry = nullptr;
return entry;
}
bool reader::has_next_entry()
{
bool has_next = true;
if(_next_entry == nullptr)
{
archive_entry* entry;
has_next = (archive_read_next_header(_archive.get(), &entry) == ARCHIVE_OK);
if(has_next)
{
_next_entry = new ns_reader::entry(_archive.get(), entry);
}
}
return has_next;
}
/// ---------------- init_format ---------------- //
#define READER_INIT_FORMAT(__FORMAT__, __FUNCTION_SUFFIX__) \
template<> \
void reader::init_format<ns_reader::format::_##__FORMAT__>()\
{\
archive_read_support_format_##__FUNCTION_SUFFIX__(_archive.get());\
}
READER_INIT_FORMAT(RAW, raw)
READER_INIT_FORMAT(ALL, all)
READER_INIT_FORMAT(7ZIP, 7zip)
READER_INIT_FORMAT(AR, ar)
READER_INIT_FORMAT(CAB, cab)
READER_INIT_FORMAT(CPIO, cpio)
READER_INIT_FORMAT(ISO9660, iso9660)
READER_INIT_FORMAT(LHA, lha)
READER_INIT_FORMAT(MTREE, mtree)
READER_INIT_FORMAT(RAR, rar)
READER_INIT_FORMAT(TAR, tar)
READER_INIT_FORMAT(XAR, xar)
READER_INIT_FORMAT(ZIP, zip)
/// ---------------- init_filter ---------------- //
#define READER_INIT_FILTER(__FILTER__, __FUNCTION_SUFFIX__) \
template<> \
void reader::init_filter<ns_reader::filter::_##__FILTER__>()\
{\
archive_read_support_filter_##__FUNCTION_SUFFIX__(_archive.get());\
}
READER_INIT_FILTER(ALL, all)
READER_INIT_FILTER(BZIP2, bzip2)
READER_INIT_FILTER(COMPRESS, compress)
READER_INIT_FILTER(GZIP, gzip)
READER_INIT_FILTER(LZIP, lzip)
READER_INIT_FILTER(LZMA, lzma)
READER_INIT_FILTER(XZ, xz)
READER_INIT_FILTER(UU, uu)
READER_INIT_FILTER(RPM, rpm)
READER_INIT_FILTER(LRZIP, lrzip)
READER_INIT_FILTER(LZOP, lzop)
READER_INIT_FILTER(GRZIP, gzip)
/// ---------------- init_data ---------------- //
template<>
void reader::init_data(ns_reader::file_container&& container)
{
if(archive_read_open_filename(_archive.get(), container.get_path().c_str(), container.get_block_size()) != ARCHIVE_OK)
{
throw archive_exception( "Failed to open archive '" + container.get_path() + "'" );
}
}
template<>
void reader::init_data(ns_reader::memory_container&& container)
{
std::vector<char> content = container.move_get_buffer();
if(archive_read_open_memory(_archive.get(), content.data(), content.size()) != ARCHIVE_OK)
{
throw archive_exception( "Failed to open memory archive" );
}
}
ns_reader::iterator reader::begin()
{
return ns_reader::iterator( this, false );
}
ns_reader::iterator reader::end()
{
return ns_reader::iterator( this, true );
}
}

83
archive_reader.hpp Normal file
View File

@ -0,0 +1,83 @@
/*
BSD 2-Clause license
Copyright (c) 2014, Domen Vrankar
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ARCHIVE_READER_HPP_INCLUDED
#define ARCHIVE_READER_HPP_INCLUDED
#include <istream>
#include <memory>
#include <archive.h>
#include "archive_reader_format.hpp"
#include "archive_reader_filter.hpp"
#include "archive_reader_entry.hpp"
#include "archive_reader_iterator.hpp"
namespace ns_archive {
class reader
{
public:
reader(reader&&) = default;
reader(const reader&) = delete;
reader& operator=(const reader&) = delete;
template<ns_reader::format FORMAT, ns_reader::filter FILTER, typename DATA_CONTAINER>
static reader make_reader(DATA_CONTAINER&& container);
template<ns_reader::format FORMAT, typename DATA_CONTAINER>
static reader make_reader(DATA_CONTAINER&& container);
ns_reader::entry* get_next_entry();
bool has_next_entry();
ns_reader::iterator begin();
ns_reader::iterator end();
private:
reader();
template<ns_reader::format FORMAT>
void init_format();
template<ns_reader::filter FILTER>
void init_filter();
template<typename DATA_CONTAINER>
void init_data(DATA_CONTAINER&& container);
std::shared_ptr<archive> _archive;
ns_reader::entry *_next_entry = nullptr;
};
}
#include "archive_reader.tpp"
#endif // ARCHIVE_READER_HPP_INCLUDED

52
archive_reader.tpp Normal file
View File

@ -0,0 +1,52 @@
/*
BSD 2-Clause license
Copyright (c) 2014, Domen Vrankar
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace ns_archive {
template<ns_reader::format FORMAT, ns_reader::filter FILTER, typename DATA_CONTAINER>
reader reader::make_reader(DATA_CONTAINER&& container)
{
reader a_reader;
a_reader.init_format<FORMAT>();
a_reader.init_filter<FILTER>();
a_reader.init_data(std::move(container));
return a_reader;
}
template<ns_reader::format FORMAT, typename DATA_CONTAINER>
reader reader::make_reader(DATA_CONTAINER&& container)
{
reader a_reader;
a_reader.init_format<FORMAT>();
a_reader.init_data(std::move(container));
return a_reader;
}
}

84
archive_reader_entry.cpp Normal file
View File

@ -0,0 +1,84 @@
/*
BSD 2-Clause license
Copyright (c) 2014, Domen Vrankar
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "archive_reader_entry.hpp"
#include "archive_exception.hpp"
namespace ns_archive {
namespace ns_reader {
entry::entry(archive* archive, archive_entry* entry) :
_archive(archive),
_entry(entry),
_entry_buffer(_archive),
_entry_stream(&_entry_buffer)
{
//
}
// -------------------------------- //
template<>
std::string entry::get_header_value<entry::string_value::HARDLINK>() const
{
return archive_entry_hardlink(_entry);
}
template<>
std::string entry::get_header_value<entry::string_value::PATHNAME>() const
{
return archive_entry_pathname(_entry);
}
template<>
std::string entry::get_header_value<entry::string_value::SOURCEPATH>() const
{
return archive_entry_sourcepath(_entry);
}
template<>
std::string entry::get_header_value<entry::string_value::SYMLINK>() const
{
return archive_entry_symlink(_entry);
}
// -------------------------------- //
std::istream& entry::get_entry_content_stream()
{
if(_already_requested_content_stream)
{
throw archive_exception( "get_entry_content_stream requested more than once for the same entry" );
}
_already_requested_content_stream = true;
return _entry_stream;
}
}
}

68
archive_reader_entry.hpp Normal file
View File

@ -0,0 +1,68 @@
/*
BSD 2-Clause license
Copyright (c) 2014, Domen Vrankar
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ARCHIVE_READER_ENTRY_HPP_INCLUDED
#define ARCHIVE_READER_ENTRY_HPP_INCLUDED
#include <string>
#include <istream>
#include "archive_entry.h"
#include "archive_reader_entry_buffer.hpp"
namespace ns_archive {
namespace ns_reader {
class entry
{
public:
enum class string_value
{
HARDLINK,
PATHNAME,
SOURCEPATH,
SYMLINK
};
public:
entry(archive* archive, archive_entry* entry);
template<string_value ENUM>
std::string get_header_value() const;
std::istream& get_entry_content_stream();
private:
archive *_archive;
archive_entry *_entry;
entry_buffer _entry_buffer;
std::istream _entry_stream;
bool _already_requested_content_stream = false;
};
}
}
#endif // ARCHIVE_READER_ENTRY_HPP_INCLUDED

View File

@ -0,0 +1,65 @@
/*
BSD 2-Clause license
Copyright (c) 2014, Domen Vrankar
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "archive_reader_entry_buffer.hpp"
#include "archive_exception.hpp"
namespace ns_archive {
namespace ns_reader {
entry_buffer::entry_buffer(archive* archive) :
_archive(archive)
{
//
}
int entry_buffer::underflow()
{
if(gptr() == egptr())
{
size_t _buff_size = archive_read_data(_archive, _buff, _buff_max_size);
if( _buff_size < 0 )
{
throw archive_exception( "Archive reader buffer reading error." );
}
if( _buff_size )
{
setg(_buff, _buff, _buff + _buff_size);
}
}
return this->gptr() == this->egptr()
? std::char_traits<char>::eof()
: std::char_traits<char>::to_int_type(*gptr());
}
}
}

View File

@ -0,0 +1,54 @@
/*
BSD 2-Clause license
Copyright (c) 2014, Domen Vrankar
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ARCHIVE_READER_ENTRY_BUFFER_HPP_INCLUDED
#define ARCHIVE_READER_ENTRY_BUFFER_HPP_INCLUDED
#include <streambuf>
#include "archive.h"
namespace ns_archive {
namespace ns_reader {
class entry_buffer : public std::streambuf
{
public:
entry_buffer(archive* archive);
int underflow();
private:
archive *_archive;
size_t _buff_max_size = 8192;
char _buff[8192];
};
}
}
#endif // ARCHIVE_READER_ENTRY_BUFFER_HPP_INCLUDED

View File

@ -0,0 +1,52 @@
/*
BSD 2-Clause license
Copyright (c) 2014, Domen Vrankar
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "archive_reader_file_container.hpp"
namespace ns_archive {
namespace ns_reader {
file_container::file_container(const std::string& file_path, size_t block_size) :
_file_path(file_path),
_block_size(block_size)
{
//
}
const std::string& file_container::get_path() const
{
return _file_path;
}
size_t file_container::get_block_size() const
{
return _block_size;
}
}
}

View File

@ -0,0 +1,53 @@
/*
BSD 2-Clause license
Copyright (c) 2014, Domen Vrankar
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ARCHIVE_READER_FILE_CONTAINER_HPP_INCLUDED
#define ARCHIVE_READER_FILE_CONTAINER_HPP_INCLUDED
#include <string>
namespace ns_archive {
namespace ns_reader {
class file_container
{
public:
file_container(const std::string& file_path, size_t block_size);
const std::string& get_path() const;
size_t get_block_size() const;
private:
std::string _file_path;
size_t _block_size;
};
}
}
#endif // ARCHIVE_READER_FILE_CONTAINER_HPP_INCLUDED

54
archive_reader_filter.hpp Normal file
View File

@ -0,0 +1,54 @@
/*
BSD 2-Clause license
Copyright (c) 2014, Domen Vrankar
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ARCHIVE_READER_FILTER_HPP_INCLUDED
#define ARCHIVE_READER_FILTER_HPP_INCLUDED
namespace ns_archive {
namespace ns_reader {
enum class filter
{
_ALL,
_BZIP2,
_COMPRESS,
_GZIP,
_LZIP,
_LZMA,
_XZ,
_UU,
_RPM,
_LRZIP,
_LZOP,
_GRZIP
};
}
}
#endif // ARCHIVE_READER_FILTER_HPP_INCLUDED

55
archive_reader_format.hpp Normal file
View File

@ -0,0 +1,55 @@
/*
BSD 2-Clause license
Copyright (c) 2014, Domen Vrankar
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ARCHIVE_READER_FORMAT_HPP_INCLUDED
#define ARCHIVE_READER_FORMAT_HPP_INCLUDED
namespace ns_archive {
namespace ns_reader {
enum class format
{
_RAW,
_ALL,
_7ZIP,
_AR,
_CAB,
_CPIO,
_ISO9660,
_LHA,
_MTREE,
_RAR,
_TAR,
_XAR,
_ZIP
};
}
}
#endif // ARCHIVE_READER_FORMAT_HPP_INCLUDED

View File

@ -0,0 +1,64 @@
/*
BSD 2-Clause license
Copyright (c) 2014, Domen Vrankar
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "archive_reader_iterator.hpp"
#include "archive_reader.hpp"
namespace ns_archive {
namespace ns_reader {
iterator::iterator(reader* p_reader, bool end_pos) :
_end_pos( end_pos ),
_p_reader( p_reader )
{
//
}
bool iterator::operator!=(const iterator& other) const
{
return _end_pos != other._end_pos;
}
entry* iterator::operator*()
{
return _p_reader->get_next_entry();
}
const iterator& iterator::operator++()
{
if(!_p_reader->has_next_entry())
{
_end_pos = true;
}
return *this;
}
}
}

View File

@ -0,0 +1,56 @@
/*
BSD 2-Clause license
Copyright (c) 2014, Domen Vrankar
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ARCHIVE_READER_ITERATOR_HPP_INCLUDED
#define ARCHIVE_READER_ITERATOR_HPP_INCLUDED
#include "archive_reader_entry.hpp"
namespace ns_archive {
class reader;
namespace ns_reader {
class iterator
{
public:
iterator(reader* p_reader, bool end_pos);
bool operator!=(const iterator& other) const;
entry* operator*();
const iterator& operator++();
private:
bool _end_pos;
reader *_p_reader;
};
}
}
#endif // ARCHIVE_READER_ITERATOR_HPP_INCLUDED

View File

@ -0,0 +1,54 @@
/*
BSD 2-Clause license
Copyright (c) 2014, Domen Vrankar
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "archive_reader_memory_container.hpp"
#include <algorithm>
#include <iterator>
namespace ns_archive {
namespace ns_reader {
memory_container::memory_container(std::istream& input_stream)
{
std::copy(std::istream_iterator<char>(input_stream), std::istream_iterator<char>(), std::back_inserter(_buffer));
}
memory_container::memory_container(std::vector<char>&& buffer) :
_buffer(std::forward<std::vector<char>>(buffer))
{
//
}
std::vector<char>&& memory_container::move_get_buffer()
{
return std::move(_buffer);
}
}
}

View File

@ -0,0 +1,53 @@
/*
BSD 2-Clause license
Copyright (c) 2014, Domen Vrankar
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ARCHIVE_READER_MEMORY_CONTAINER_HPP_INCLUDED
#define ARCHIVE_READER_MEMORY_CONTAINER_HPP_INCLUDED
#include <vector>
#include <istream>
namespace ns_archive {
namespace ns_reader {
class memory_container
{
public:
memory_container(std::istream& input_stream);
memory_container(std::vector<char>&& buffer);
std::vector<char>&& move_get_buffer();
private:
std::vector<char> _buffer;
};
}
}
#endif // ARCHIVE_READER_MEMORY_CONTAINER_HPP_INCLUDED