`
zj5121
  • 浏览: 4200 次
  • 性别: Icon_minigender_1
  • 来自: 渥村
最近访客 更多访客>>
社区版块
存档分类
最新评论

a compete demo of iostream filter chain

阅读更多
#include <sys/stat.h>
#include <fcntl.h>
#include <sstream>
#include <string>
#include <list>
#include <boost/iostreams/concepts.hpp>
#include <boost/filesystem.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/stream.hpp>
#include <time.h>
#include <unistd.h>
#include <stdio.h>
#include <iostream>

using namespace std;
namespace fs = boost::filesystem;
namespace io = boost::iostreams;

struct opipestream : io::stream< io::file_descriptor_sink >
{

  typedef io::stream< io::file_descriptor_sink > base ;

  explicit opipestream( const char* command )
	  :base( fileno( pipe = popen( command, "w" ) ) ) {}
  ~opipestream() { close() ; pclose( pipe ) ; }
  private : 
	FILE* pipe ;
};
class mydev : public io::sink {
public:
	std::streamsize write(const char* s, std::streamsize n) {
		cout<<s;
		(*opipe) << s;
	}
	mydev(const char* cmd){
		opipe = new opipestream(cmd);
	}
	~mydev(){
		delete opipe;
	}
private:
	opipestream *opipe;
};
int unpack(const char* src_file)
{
	fs::path out_dir = "/tmp/myunpack";
	if (fs::exists(out_dir)) {
		fs::remove_all(out_dir);
	}
	fs::create_directory(out_dir);
	string cmd = "/bin/tar xf - ";

	ifstream file(src_file, ios_base::in | ios_base::binary);
	io::filtering_streambuf<io::input> in;
	in.push(io::gzip_decompressor());
	in.push(file);

	//mydev out(cmd.c_str());
	FILE* tar = popen(cmd.c_str(),"w");
	io::file_descriptor_sink out(fileno(tar));
	io::copy(in,out);
	fclose(tar);
	return -1;

}

int main()
{
	return unpack("./cabal.tar.gz");

}
 

A complete demo of iostream

 

分享到:
评论

相关推荐

    shiyan.5.3.cpp

    假设一个班级中的学生分为A、B两类,A类同学学习热情很高,乐于做题,采用compete模式可以获得成就感并且在期末拿到高分,compete模式可以让他们有10分的收益;采用standard模式他们也可以在期末拿到高分,但不能...

    design AIs to compete in simple games

    design AIs to compete in simple games

    SC Compete with Big “4”.pptx

    SC Compete with Big “4”.pptx

    Internal Readiness - Pricing and Licensing - VMWare Compete

    Internal Readiness - Pricing and Licensing - VMWare Compete

    Pricing and Licensing - VMWare Compete-EN.pptx

    Pricing and Licensing - VMWare Compete-EN.pptx

    twxproxy_pro_v211.zip

    By 2002, it was almost impossible to compete in TW2002 tournament play without prior programming experience or the use of TWX Proxy. The revolutionary proxy design that was the major selling point of...

    Learning Storm

    but has become a necessity for businesses that want to compete, and Apache Storm is becoming the de facto standard to develop real-time processing pipelines. The key features of Storm are that it is...

    How to XBMC

    Appealing to a broad range of users, XBMC is an open source media center which was originally created for Xbox. Its graphical user interface (GUI) allows the user to easily browse and view videos, ...

    Advanced Machine Learning with Python.2016

    Compete with top data scientists by gaining a practical and theoretical understanding of cutting-edge deep learning algorithms Apply your new found skills to solve real problems, through clearly-...

    英文原版-What To Do When Machines Do Everything 1st Edition

    The essential playbook for the future of your businessWhat To Do When Machines Do Everything is a guidebook to succeeding in the next generation of the digital economy. When systems running on ...

    Generalization in Machine Learning via Analytical Learning Theory.pdf

    This paper introduces a novel measure-theoreticlearning theory to analyze generalization behaviors of practical interest. The proposed learningtheory has the following abilities: 1) to utilizethe ...

    php in a nutshell

    PHP in a Nutshell is a complete reference to the core of the language as well as the most popular PHP extensions. This book doesn't try to compete with or replace the widely available online ...

    高一英语上学期Unit8测试题[精选].doc

    - "compete in" 用于表达参加某个比赛或活动,如"compete in a game"或"compete in a match"。 - "compete with/against sb." 则表示与某人进行竞争,如"He competes with his colleagues for the promotion."(他...

Global site tag (gtag.js) - Google Analytics