From d6787a8cd596d2297f4ac56ec2ac279e343b0f70 Mon Sep 17 00:00:00 2001 From: do-m-en Date: Tue, 23 Sep 2014 18:24:58 +0200 Subject: [PATCH] Update README.md --- README.md | 85 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c7a0383..4642555 100644 --- a/README.md +++ b/README.md @@ -7,24 +7,91 @@ Dependencies - libarchive (https://github.com/libarchive/libarchive) - CMake (http://cmake.org/) -Current version was tested with gcc 4.9 on 64 bit Linux - Ubuntu 14.04 +Current version was tested with gcc 4.9 on 64 bit Linux - Ubuntu 14.04 with libarchive13 3.1.2-9 Example usage ============================ +Read from archive + ```C++ #include "archive_reader.hpp" +#include "archive_exception.hpp" -namespace ar = ns_archive::ns_reader; -std::fstream fs( "some_tar_file.tar" ); -ns_archive::reader reader = ns_archive::reader::make_reader(fs, 1024); +... -for(auto entry : reader) +try { - // get file name - std::cout << entry->get_header_value() << std::endl; - // get file content - std::cout << entry->get_entry_content_stream().rdbuf() << std::endl << std::endl; + namespace ar = ns_archive::ns_reader; + std::fstream fs( "some_tar_file.tar" ); + ns_archive::reader reader = ns_archive::reader::make_reader(fs, 10240); + + for(auto entry : reader) + { + // get file name + std::cout << entry->get_header_value_pathname() << std::endl; + // get file content + std::cout << entry->get_stream().rdbuf() << std::endl << std::endl; + } +} +catch( ns_archive::archive_exception& e ) +{ + std::cout << e.what() << std::endl; +} +``` + +Write to archive + +```C++ +#include "archive_writer.hpp" +#include "archive_exception.hpp" + +... + +try +{ + namespace ar = ns_archive::ns_reader; + std::ofstream outfs( "output.tar" ); + ns_archive::writer writer2 = ns_archive::writer::make_writer( outfs, 2 ); + std::stringstream ss; + ss << "foo"; + + ns_archive::entry out_entry( ss ); + out_entry.set_header_value_pathname( "foo.txt" ); + writer.add_entry( out_entry ); +} +catch( ns_archive::archive_exception& e ) +{ + std::cout << e.what() << std::endl; +} +``` + +Copy archive + +```C++ +#include "archive_reader.hpp" +#include "archive_writer.hpp" +#include "archive_exception.hpp" + +... + +try +{ + namespace ar = ns_archive::ns_reader; + std::fstream fs( "some_tar_file.tar" ); + ns_archive::reader reader = ns_archive::reader::make_reader(fs, 10240); + + std::ofstream outfs( "out.tar" ); + ns_archive::writer writer = ns_archive::writer::make_writer(outfs, 10240); + + for(auto entry : reader) + { + writer.add_entry( *entry.get() ); + } +} +catch( ns_archive::archive_exception& e ) +{ + std::cout << e.what() << std::endl; } ```