-(mod) removed distinguishing between different archive input sources
-(mod) changed the name of library so that it doesn't get the name of liblibarchive... -(add) added make install target -(add) added library versioning -(del) deleted file and memory container as they are obsolete
This commit is contained in:
parent
8b95419844
commit
756cab1b15
@ -1,6 +1,32 @@
|
||||
#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.
|
||||
|
||||
cmake_minimum_required( VERSION 2.8.12 )
|
||||
|
||||
project(libarchive_cpp_wrapper)
|
||||
project(archive_cpp_wrapper)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-Wall -std=c++11")
|
||||
|
||||
@ -12,8 +38,6 @@ 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
|
||||
@ -23,3 +47,28 @@ add_library( ${PROJECT_NAME} SHARED
|
||||
)
|
||||
|
||||
target_link_libraries( ${PROJECT_NAME} /usr/lib/x86_64-linux-gnu/libarchive.so.13 )
|
||||
set_target_properties( ${PROJECT_NAME} PROPERTIES VERSION "0.0.1" SOVERSION "1" )
|
||||
|
||||
install(
|
||||
TARGETS ${PROJECT_NAME} LIBRARY
|
||||
DESTINATION lib
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
|
||||
archive_reader_entry_buffer.hpp
|
||||
archive_reader.hpp
|
||||
archive_writer_format.hpp
|
||||
archive_exception.hpp
|
||||
archive_writer_entry.hpp
|
||||
archive_reader_iterator.hpp
|
||||
archive_reader_format.hpp
|
||||
archive_writer_filter.hpp
|
||||
archive_reader_filter.hpp
|
||||
archive_reader_entry.hpp
|
||||
archive_writer.hpp
|
||||
archive_reader.tpp
|
||||
|
||||
DESTINATION include
|
||||
)
|
||||
|
@ -28,16 +28,14 @@ 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
|
||||
reader::reader(std::istream& stream, size_t block_size) :
|
||||
_archive( archive_read_new(), [](archive* archive){ archive_read_free(archive); } ), // errors in destructor will be silently ignored
|
||||
_reader_container( stream, block_size )
|
||||
{
|
||||
//
|
||||
}
|
||||
@ -119,22 +117,26 @@ READER_INIT_FILTER(LZOP, lzop)
|
||||
READER_INIT_FILTER(GRZIP, gzip)
|
||||
|
||||
/// ---------------- init_data ---------------- //
|
||||
template<>
|
||||
void reader::init_data(ns_reader::file_container&& container)
|
||||
ssize_t reader_callback( archive* archive, void* in_reader_container, const void** buff )
|
||||
{
|
||||
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() + "'" );
|
||||
}
|
||||
reader::reader_container* p_reader_container = reinterpret_cast<reader::reader_container*>( in_reader_container );
|
||||
|
||||
p_reader_container->_stream.read( &p_reader_container->_buff[0], p_reader_container->_buff.size() );
|
||||
*buff = &p_reader_container->_buff[0];
|
||||
|
||||
return p_reader_container->_stream.gcount();
|
||||
}
|
||||
|
||||
template<>
|
||||
void reader::init_data(ns_reader::memory_container&& container)
|
||||
int close_callback( archive*, void* )
|
||||
{
|
||||
std::vector<char> content = container.move_get_buffer();
|
||||
if(archive_read_open_memory(_archive.get(), content.data(), content.size()) != ARCHIVE_OK)
|
||||
return ARCHIVE_OK;
|
||||
}
|
||||
|
||||
void reader::init_data()
|
||||
{
|
||||
if(archive_read_open( _archive.get(), &_reader_container, nullptr, reader_callback, close_callback ) != ARCHIVE_OK)
|
||||
{
|
||||
throw archive_exception( "Failed to open memory archive" );
|
||||
throw archive_exception( "Failed to read the archive!" );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <istream>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <archive.h>
|
||||
|
||||
#include "archive_reader_format.hpp"
|
||||
@ -48,11 +49,11 @@ public:
|
||||
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>
|
||||
static reader make_reader( std::istream& stream, size_t block_size );
|
||||
|
||||
template<ns_reader::format FORMAT, typename DATA_CONTAINER>
|
||||
static reader make_reader(DATA_CONTAINER&& container);
|
||||
template<ns_reader::format FORMAT, ns_reader::filter FILTER>
|
||||
static reader make_reader( std::istream& stream, size_t block_size);
|
||||
|
||||
ns_reader::entry* get_next_entry();
|
||||
bool has_next_entry();
|
||||
@ -61,7 +62,7 @@ public:
|
||||
ns_reader::iterator end();
|
||||
|
||||
private:
|
||||
reader();
|
||||
reader( std::istream& stream, size_t block_size );
|
||||
|
||||
template<ns_reader::format FORMAT>
|
||||
void init_format();
|
||||
@ -69,11 +70,26 @@ private:
|
||||
template<ns_reader::filter FILTER>
|
||||
void init_filter();
|
||||
|
||||
template<typename DATA_CONTAINER>
|
||||
void init_data(DATA_CONTAINER&& container);
|
||||
void init_data();
|
||||
|
||||
std::shared_ptr<archive> _archive;
|
||||
ns_reader::entry *_next_entry = nullptr;
|
||||
|
||||
class reader_container
|
||||
{
|
||||
public:
|
||||
reader_container( std::istream& stream, size_t block_size ) :
|
||||
_stream( stream )
|
||||
{
|
||||
_buff.resize( block_size );
|
||||
}
|
||||
public:
|
||||
std::istream& _stream;
|
||||
std::vector<char> _buff;
|
||||
} _reader_container;
|
||||
|
||||
friend ssize_t reader_callback( archive* archive, void* in_reader_container, const void** buff );
|
||||
friend int close_callback( archive*, void* );
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -28,23 +28,23 @@ 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)
|
||||
template<ns_reader::format FORMAT>
|
||||
reader reader::make_reader( std::istream& stream, size_t block_size )
|
||||
{
|
||||
reader a_reader;
|
||||
reader a_reader( stream, block_size );
|
||||
a_reader.init_format<FORMAT>();
|
||||
a_reader.init_data();
|
||||
|
||||
return a_reader;
|
||||
}
|
||||
|
||||
template<ns_reader::format FORMAT, ns_reader::filter FILTER>
|
||||
reader reader::make_reader( std::istream& stream, size_t block_size )
|
||||
{
|
||||
reader a_reader( stream, block_size );
|
||||
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));
|
||||
a_reader.init_data();
|
||||
|
||||
return a_reader;
|
||||
}
|
||||
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
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
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user