-(mod) renamed .tpp files to .ipp as code blocks editor doesn't recognise tpp out of the box
-(mod) cleanup of archive reader code -(add) added new constructor for reader if we only need filter and no format -(add) added initial version of archive writer
This commit is contained in:
parent
756cab1b15
commit
1ca06b2412
@ -31,7 +31,7 @@ project(archive_cpp_wrapper)
|
|||||||
set(CMAKE_CXX_FLAGS "-Wall -std=c++11")
|
set(CMAKE_CXX_FLAGS "-Wall -std=c++11")
|
||||||
|
|
||||||
file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp")
|
file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp")
|
||||||
file(GLOB template_implementations "${CMAKE_CURRENT_SOURCE_DIR}/*.tpp")
|
file(GLOB template_implementations "${CMAKE_CURRENT_SOURCE_DIR}/*.ipp")
|
||||||
|
|
||||||
add_library( ${PROJECT_NAME} SHARED
|
add_library( ${PROJECT_NAME} SHARED
|
||||||
|
|
||||||
@ -40,6 +40,9 @@ add_library( ${PROJECT_NAME} SHARED
|
|||||||
archive_reader_iterator.cpp
|
archive_reader_iterator.cpp
|
||||||
archive_reader_entry_buffer.cpp
|
archive_reader_entry_buffer.cpp
|
||||||
|
|
||||||
|
archive_writer.cpp
|
||||||
|
archive_writer_entry.cpp
|
||||||
|
|
||||||
archive_exception.cpp
|
archive_exception.cpp
|
||||||
|
|
||||||
${headers}
|
${headers}
|
||||||
@ -68,7 +71,8 @@ install(
|
|||||||
archive_reader_filter.hpp
|
archive_reader_filter.hpp
|
||||||
archive_reader_entry.hpp
|
archive_reader_entry.hpp
|
||||||
archive_writer.hpp
|
archive_writer.hpp
|
||||||
archive_reader.tpp
|
archive_reader.ipp
|
||||||
|
archive_writer.ipp
|
||||||
|
|
||||||
DESTINATION include
|
DESTINATION include
|
||||||
)
|
)
|
||||||
|
@ -117,6 +117,8 @@ READER_INIT_FILTER(LZOP, lzop)
|
|||||||
READER_INIT_FILTER(GRZIP, gzip)
|
READER_INIT_FILTER(GRZIP, gzip)
|
||||||
|
|
||||||
/// ---------------- init_data ---------------- //
|
/// ---------------- init_data ---------------- //
|
||||||
|
namespace ns_reader {
|
||||||
|
|
||||||
ssize_t reader_callback( archive* archive, void* in_reader_container, const void** buff )
|
ssize_t reader_callback( archive* archive, void* in_reader_container, const void** buff )
|
||||||
{
|
{
|
||||||
reader::reader_container* p_reader_container = reinterpret_cast<reader::reader_container*>( in_reader_container );
|
reader::reader_container* p_reader_container = reinterpret_cast<reader::reader_container*>( in_reader_container );
|
||||||
@ -127,14 +129,11 @@ ssize_t reader_callback( archive* archive, void* in_reader_container, const void
|
|||||||
return p_reader_container->_stream.gcount();
|
return p_reader_container->_stream.gcount();
|
||||||
}
|
}
|
||||||
|
|
||||||
int close_callback( archive*, void* )
|
} // ns_reader
|
||||||
{
|
|
||||||
return ARCHIVE_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
void reader::init_data()
|
void reader::init_data()
|
||||||
{
|
{
|
||||||
if(archive_read_open( _archive.get(), &_reader_container, nullptr, reader_callback, close_callback ) != ARCHIVE_OK)
|
if(archive_read_open( _archive.get(), &_reader_container, nullptr, ns_reader::reader_callback, nullptr ) != ARCHIVE_OK)
|
||||||
{
|
{
|
||||||
throw archive_exception( "Failed to read the archive!" );
|
throw archive_exception( "Failed to read the archive!" );
|
||||||
}
|
}
|
||||||
@ -150,4 +149,4 @@ ns_reader::iterator reader::end()
|
|||||||
return ns_reader::iterator( this, true );
|
return ns_reader::iterator( this, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // ns_archive
|
||||||
|
@ -41,6 +41,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
namespace ns_archive {
|
namespace ns_archive {
|
||||||
|
|
||||||
|
namespace ns_reader {
|
||||||
|
|
||||||
|
ssize_t reader_callback( archive* archive, void* in_reader_container, const void** buff );
|
||||||
|
|
||||||
|
} // ns_reader
|
||||||
|
|
||||||
class reader
|
class reader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -55,6 +61,9 @@ public:
|
|||||||
template<ns_reader::format FORMAT, ns_reader::filter FILTER>
|
template<ns_reader::format FORMAT, ns_reader::filter FILTER>
|
||||||
static reader make_reader( std::istream& stream, size_t block_size);
|
static reader make_reader( std::istream& stream, size_t block_size);
|
||||||
|
|
||||||
|
template<ns_reader::filter FILTER>
|
||||||
|
static reader make_reader( std::istream& stream, size_t block_size);
|
||||||
|
|
||||||
ns_reader::entry* get_next_entry();
|
ns_reader::entry* get_next_entry();
|
||||||
bool has_next_entry();
|
bool has_next_entry();
|
||||||
|
|
||||||
@ -88,12 +97,11 @@ private:
|
|||||||
std::vector<char> _buff;
|
std::vector<char> _buff;
|
||||||
} _reader_container;
|
} _reader_container;
|
||||||
|
|
||||||
friend ssize_t reader_callback( archive* archive, void* in_reader_container, const void** buff );
|
friend ssize_t ns_reader::reader_callback( archive* archive, void* in_reader_container, const void** buff );
|
||||||
friend int close_callback( archive*, void* );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // ns_archive
|
||||||
|
|
||||||
#include "archive_reader.tpp"
|
#include "archive_reader.ipp"
|
||||||
|
|
||||||
#endif // ARCHIVE_READER_HPP_INCLUDED
|
#endif // ARCHIVE_READER_HPP_INCLUDED
|
||||||
|
@ -49,4 +49,15 @@ reader reader::make_reader( std::istream& stream, size_t block_size )
|
|||||||
return a_reader;
|
return a_reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<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<ns_reader::format::_RAW>();
|
||||||
|
a_reader.init_filter<FILTER>();
|
||||||
|
a_reader.init_data();
|
||||||
|
|
||||||
|
return a_reader;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
131
archive_writer.cpp
Normal file
131
archive_writer.cpp
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
/*
|
||||||
|
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_writer.hpp"
|
||||||
|
|
||||||
|
#include "archive_exception.hpp"
|
||||||
|
#include "string"
|
||||||
|
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
namespace ns_archive {
|
||||||
|
|
||||||
|
writer::writer(std::ostream& stream) :
|
||||||
|
_archive( archive_write_new(), [](archive* archive){ archive_read_free(archive); } ), // errors in destructor will be silently ignored
|
||||||
|
_writer_container( stream )
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void writer::finish()
|
||||||
|
{
|
||||||
|
archive_write_close(_archive.get()); // TODO throw on error
|
||||||
|
}
|
||||||
|
|
||||||
|
void writer::add_entry( ns_writer::entry& entry )
|
||||||
|
{
|
||||||
|
if( archive_write_header( _archive.get(), entry.get_entry() ) != ARCHIVE_OK)
|
||||||
|
{
|
||||||
|
throw archive_exception( "Error writing header to archive!" );
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& stream = entry.get_stream();
|
||||||
|
std::istreambuf_iterator<char> eos;
|
||||||
|
std::string tmp( std::istreambuf_iterator<char>(stream), eos );
|
||||||
|
|
||||||
|
archive_write_data( _archive.get(), tmp.c_str(), tmp.size() );
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ---------------- init_format ---------------- //
|
||||||
|
|
||||||
|
#define WRITER_INIT_FORMAT(__FORMAT__, __FUNCTION_SUFFIX__) \
|
||||||
|
template<> \
|
||||||
|
void writer::init_format<ns_writer::format::_##__FORMAT__>()\
|
||||||
|
{\
|
||||||
|
archive_write_set_format_##__FUNCTION_SUFFIX__(_archive.get());\
|
||||||
|
}
|
||||||
|
|
||||||
|
WRITER_INIT_FORMAT(7ZIP, 7zip)
|
||||||
|
WRITER_INIT_FORMAT(CPIO_SVR4_NOCRC, cpio_newc)
|
||||||
|
WRITER_INIT_FORMAT(ISO9660, iso9660)
|
||||||
|
WRITER_INIT_FORMAT(MTREE, mtree)
|
||||||
|
WRITER_INIT_FORMAT(SHAR, shar)
|
||||||
|
WRITER_INIT_FORMAT(SHAR_BASE, shar)
|
||||||
|
WRITER_INIT_FORMAT(SHAR_DUMP, shar_dump)
|
||||||
|
WRITER_INIT_FORMAT(TAR, pax_restricted)
|
||||||
|
WRITER_INIT_FORMAT(TAR_GNUTAR, gnutar)
|
||||||
|
WRITER_INIT_FORMAT(TAR_PAX_INTERCHANGE, pax)
|
||||||
|
WRITER_INIT_FORMAT(TAR_PAX_RESTRICTED, pax_restricted)
|
||||||
|
WRITER_INIT_FORMAT(TAR_USTAR, ustar)
|
||||||
|
WRITER_INIT_FORMAT(XAR, xar)
|
||||||
|
WRITER_INIT_FORMAT(ZIP, zip)
|
||||||
|
|
||||||
|
/// ---------------- init_filter ---------------- //
|
||||||
|
|
||||||
|
#define WRITER_INIT_FILTER(__FILTER__, __FUNCTION_SUFFIX__) \
|
||||||
|
template<> \
|
||||||
|
void writer::init_filter<ns_writer::filter::_##__FILTER__>()\
|
||||||
|
{\
|
||||||
|
archive_write_add_filter_##__FUNCTION_SUFFIX__(_archive.get());\
|
||||||
|
}
|
||||||
|
|
||||||
|
WRITER_INIT_FILTER(NONE, none)
|
||||||
|
WRITER_INIT_FILTER(GZIP, gzip)
|
||||||
|
WRITER_INIT_FILTER(BZIP2, bzip2)
|
||||||
|
WRITER_INIT_FILTER(COMPRESS, compress)
|
||||||
|
WRITER_INIT_FILTER(GRZIP, grzip)
|
||||||
|
WRITER_INIT_FILTER(LRZIP, lrzip)
|
||||||
|
WRITER_INIT_FILTER(LZIP, lzip)
|
||||||
|
WRITER_INIT_FILTER(LZMA, lzma)
|
||||||
|
WRITER_INIT_FILTER(LZOP, lzip)
|
||||||
|
WRITER_INIT_FILTER(UU, uuencode)
|
||||||
|
WRITER_INIT_FILTER(XZ, xz)
|
||||||
|
|
||||||
|
/// ---------------- init_data ---------------- //
|
||||||
|
namespace ns_writer {
|
||||||
|
|
||||||
|
ssize_t writer_callback( archive* archive, void* out_writer_container, const void* buff, size_t buff_size )
|
||||||
|
{
|
||||||
|
std::ostream* stream = reinterpret_cast<std::ostream*>( out_writer_container );
|
||||||
|
|
||||||
|
stream->write( (const char*)buff, buff_size );
|
||||||
|
|
||||||
|
return buff_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // ns_writer
|
||||||
|
|
||||||
|
void writer::init_data()
|
||||||
|
{
|
||||||
|
if(archive_write_open( _archive.get(), &_writer_container, nullptr, ns_writer::writer_callback, nullptr ) != ARCHIVE_OK)
|
||||||
|
{
|
||||||
|
throw archive_exception( "Failed to write the archive!" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
88
archive_writer.hpp
Normal file
88
archive_writer.hpp
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
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_WRITER_HPP_INCLUDED
|
||||||
|
#define ARCHIVE_WRITER_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include <ostream>
|
||||||
|
#include <memory>
|
||||||
|
#include <archive.h>
|
||||||
|
|
||||||
|
#include "archive_writer_format.hpp"
|
||||||
|
#include "archive_writer_filter.hpp"
|
||||||
|
#include "archive_writer_entry.hpp"
|
||||||
|
|
||||||
|
namespace ns_archive {
|
||||||
|
|
||||||
|
namespace ns_writer {
|
||||||
|
|
||||||
|
ssize_t writer_callback( archive* archive, void* out_writer_container, const void* buff, size_t buff_size );
|
||||||
|
|
||||||
|
} // ns_writer
|
||||||
|
|
||||||
|
class writer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
writer(writer&&) = default;
|
||||||
|
|
||||||
|
writer(const writer&) = delete;
|
||||||
|
writer& operator=(const writer&) = delete;
|
||||||
|
|
||||||
|
void finish();
|
||||||
|
|
||||||
|
template<ns_writer::format FORMAT, ns_writer::filter FILTER>
|
||||||
|
static writer make_writer(std::ostream& stream);
|
||||||
|
|
||||||
|
template<ns_writer::format FORMAT>
|
||||||
|
static writer make_writer(std::ostream& stream);
|
||||||
|
|
||||||
|
void add_entry( ns_writer::entry& entry );
|
||||||
|
|
||||||
|
private:
|
||||||
|
writer(std::ostream& stream);
|
||||||
|
|
||||||
|
template<ns_writer::format FORMAT>
|
||||||
|
void init_format();
|
||||||
|
|
||||||
|
template<ns_writer::filter FILTER>
|
||||||
|
void init_filter();
|
||||||
|
|
||||||
|
void init_data();
|
||||||
|
|
||||||
|
std::shared_ptr<archive> _archive;
|
||||||
|
std::ostream& _writer_container;
|
||||||
|
|
||||||
|
friend ssize_t ns_writer::writer_callback( archive* archive, void* out_writer_container, const void* buff, size_t buff_size );
|
||||||
|
};
|
||||||
|
|
||||||
|
} // ns_archive
|
||||||
|
|
||||||
|
#include "archive_writer.ipp"
|
||||||
|
|
||||||
|
#endif // ARCHIVE_WRITER_HPP_INCLUDED
|
||||||
|
|
50
archive_writer.ipp
Normal file
50
archive_writer.ipp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
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_writer::format FORMAT, ns_writer::filter FILTER>
|
||||||
|
writer writer::make_writer(std::ostream& stream)
|
||||||
|
{
|
||||||
|
writer a_writer( stream );
|
||||||
|
a_writer.init_format<FORMAT>();
|
||||||
|
a_writer.init_filter<FILTER>();
|
||||||
|
a_writer.init_data();
|
||||||
|
|
||||||
|
return a_writer;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<ns_writer::format FORMAT>
|
||||||
|
writer writer::make_writer(std::ostream& stream)
|
||||||
|
{
|
||||||
|
return make_writer<FORMAT, ns_writer::filter::_NONE>( stream );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
124
archive_writer_entry.cpp
Normal file
124
archive_writer_entry.cpp
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
#include "archive_writer_entry.hpp"
|
||||||
|
|
||||||
|
namespace ns_archive {
|
||||||
|
namespace ns_writer {
|
||||||
|
|
||||||
|
entry::entry(std::istream& stream, size_t stream_size) :
|
||||||
|
_entry( archive_entry_new() ),
|
||||||
|
_stream( &stream )
|
||||||
|
{
|
||||||
|
archive_entry_set_mode( _entry, S_IFREG );
|
||||||
|
archive_entry_set_size( _entry, stream_size );
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::clear_entry(std::istream& stream, size_t stream_size)
|
||||||
|
{
|
||||||
|
archive_entry_clear( _entry );
|
||||||
|
_stream = &stream;
|
||||||
|
archive_entry_set_mode( _entry, S_IFREG );
|
||||||
|
archive_entry_set_size( _entry, stream_size );
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------//
|
||||||
|
void entry::set_header_value_gid(int64_t value)
|
||||||
|
{
|
||||||
|
archive_entry_set_gid(_entry, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::set_header_value_ino(int64_t value)
|
||||||
|
{
|
||||||
|
archive_entry_set_ino(_entry, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::set_header_value_ino64(int64_t value)
|
||||||
|
{
|
||||||
|
archive_entry_set_ino64(_entry, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::set_header_value_size(int64_t value)
|
||||||
|
{
|
||||||
|
archive_entry_set_size(_entry, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::set_header_value_uid(int64_t value)
|
||||||
|
{
|
||||||
|
archive_entry_set_uid(_entry, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::set_header_value_mode(mode_t value)
|
||||||
|
{
|
||||||
|
archive_entry_set_mode(_entry, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::set_header_value_perm(mode_t value)
|
||||||
|
{
|
||||||
|
archive_entry_set_perm(_entry, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::set_header_value_rdev(dev_t value)
|
||||||
|
{
|
||||||
|
archive_entry_set_rdev(_entry, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::set_header_value_rdevmajor(dev_t value)
|
||||||
|
{
|
||||||
|
archive_entry_set_rdevmajor(_entry, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::set_header_value_rdevminor(dev_t value)
|
||||||
|
{
|
||||||
|
archive_entry_set_rdevminor(_entry, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::set_header_value_gname(const std::string& value)
|
||||||
|
{
|
||||||
|
archive_entry_set_gname(_entry, value.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::set_header_value_hardlink(const std::string& value)
|
||||||
|
{
|
||||||
|
archive_entry_set_hardlink(_entry, value.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::set_header_value_link(const std::string& value)
|
||||||
|
{
|
||||||
|
archive_entry_set_link(_entry, value.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::set_header_value_pathname(const std::string& value)
|
||||||
|
{
|
||||||
|
archive_entry_set_pathname(_entry, value.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::set_header_value_symlink(const std::string& value)
|
||||||
|
{
|
||||||
|
archive_entry_set_symlink(_entry, value.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::set_header_value_uname(const std::string& value)
|
||||||
|
{
|
||||||
|
archive_entry_set_uname(_entry, value.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::set_header_value_nlink(unsigned int value)
|
||||||
|
{
|
||||||
|
archive_entry_set_nlink(_entry, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry::set_header_value_mtime(time_t time, long value)
|
||||||
|
{
|
||||||
|
archive_entry_set_mtime(_entry, time, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
archive_entry* entry::get_entry() const
|
||||||
|
{
|
||||||
|
return _entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::istream& entry::get_stream() const
|
||||||
|
{
|
||||||
|
return *_stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
77
archive_writer_entry.hpp
Normal file
77
archive_writer_entry.hpp
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
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_WRITER_ENTRY_HPP_INCLUDED
|
||||||
|
#define ARCHIVE_WRITER_ENTRY_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include <archive.h>
|
||||||
|
#include <archive_entry.h>
|
||||||
|
#include <string>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <linux/types.h>
|
||||||
|
|
||||||
|
namespace ns_archive {
|
||||||
|
namespace ns_writer {
|
||||||
|
|
||||||
|
class entry
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
entry(std::istream& stream, size_t stream_size);
|
||||||
|
|
||||||
|
void clear_entry(std::istream& stream, size_t stream_size);
|
||||||
|
|
||||||
|
void set_header_value_gid(int64_t value);
|
||||||
|
void set_header_value_ino(int64_t value);
|
||||||
|
void set_header_value_ino64(int64_t value);
|
||||||
|
void set_header_value_size(int64_t value);
|
||||||
|
void set_header_value_uid(int64_t value);
|
||||||
|
void set_header_value_mode(mode_t value);
|
||||||
|
void set_header_value_perm(mode_t value);
|
||||||
|
void set_header_value_rdev(dev_t value);
|
||||||
|
void set_header_value_rdevmajor(dev_t value);
|
||||||
|
void set_header_value_rdevminor(dev_t value);
|
||||||
|
void set_header_value_gname(const std::string& value);
|
||||||
|
void set_header_value_hardlink(const std::string& value);
|
||||||
|
void set_header_value_link(const std::string& value);
|
||||||
|
void set_header_value_pathname(const std::string& value);
|
||||||
|
void set_header_value_symlink(const std::string& value);
|
||||||
|
void set_header_value_uname(const std::string& value);
|
||||||
|
void set_header_value_nlink(unsigned int value);
|
||||||
|
void set_header_value_mtime(time_t time, long value);
|
||||||
|
|
||||||
|
archive_entry* get_entry() const;
|
||||||
|
std::istream& get_stream() const;
|
||||||
|
private:
|
||||||
|
archive_entry* _entry;
|
||||||
|
std::istream* _stream;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ARCHIVE_WRITER_ENTRY_HPP_INCLUDED
|
53
archive_writer_filter.hpp
Normal file
53
archive_writer_filter.hpp
Normal 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_WRITER_FILTER_HPP_INCLUDED
|
||||||
|
#define ARCHIVE_WRITER_FILTER_HPP_INCLUDED
|
||||||
|
|
||||||
|
namespace ns_archive {
|
||||||
|
namespace ns_writer {
|
||||||
|
|
||||||
|
enum class filter
|
||||||
|
{
|
||||||
|
_NONE,
|
||||||
|
_GZIP,
|
||||||
|
_BZIP2,
|
||||||
|
_COMPRESS,
|
||||||
|
_GRZIP,
|
||||||
|
_LRZIP,
|
||||||
|
_LZIP,
|
||||||
|
_LZMA,
|
||||||
|
_LZOP,
|
||||||
|
_UU,
|
||||||
|
_XZ
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ARCHIVE_WRITER_FILTER_HPP_INCLUDED
|
58
archive_writer_format.hpp
Normal file
58
archive_writer_format.hpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
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_WRITER_FORMAT_HPP_INCLUDED
|
||||||
|
#define ARCHIVE_WRITER_FORMAT_HPP_INCLUDED
|
||||||
|
|
||||||
|
namespace ns_archive {
|
||||||
|
namespace ns_writer {
|
||||||
|
|
||||||
|
enum class format
|
||||||
|
{
|
||||||
|
_7ZIP,
|
||||||
|
_CPIO,
|
||||||
|
_CPIO_POSIX,
|
||||||
|
_CPIO_SVR4_NOCRC,
|
||||||
|
_ISO9660,
|
||||||
|
_MTREE,
|
||||||
|
_SHAR,
|
||||||
|
_SHAR_BASE,
|
||||||
|
_SHAR_DUMP,
|
||||||
|
_TAR,
|
||||||
|
_TAR_GNUTAR,
|
||||||
|
_TAR_PAX_INTERCHANGE,
|
||||||
|
_TAR_PAX_RESTRICTED,
|
||||||
|
_TAR_USTAR,
|
||||||
|
_XAR,
|
||||||
|
_ZIP
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ARCHIVE_WRITER_FORMAT_HPP_INCLUDED
|
Loading…
x
Reference in New Issue
Block a user