【问题标题】:How to find the index in Poco::DeflatingOutputStream如何在 Poco::DeflatingOutputStream 中找到索引
【发布时间】:2015-12-09 16:46:04
【问题描述】:

您好,我是 Poco 的新手,您能否帮我找到一种在写入放气流期间获取索引/位置的方法,以便我可以截断无效数据并确保我的文件仅包含有效数据.

    #include <stdexcept>
    #include <stdarg.h>
    #include <map>
    #include <iostream>
    #include <cstring>
    #include <fstream>
    #include <Poco/DeflatingStream.h>
    #include <stdio.h>
    #include <limits>
    #include <stdio.h>
    #include <unistd.h>
    using namespace std;

        std::ofstream* ostr;
        Poco::DeflatingOutputStream* ofstr;
        string fileName="/home/lamb/Cpp/simple.gzip";
        bool written = false;
        // int lastsucessfulwrite;

    compress(){
        *ofstr << "\t<xyz>\n";
        *ofstr << "\t</xyz>\n";
        *ofstr << " who=\"";
        *ofstr << "/>\n";
    written = true;
    /* "lastsucessfulwrite" How to store the index of ofstr , in case of normal files we use ftell but in DeflatingOutputStream how to get index so that I can erase it later based on this value */
    }

    timer(){
    sleep(2);
    // 2 second 
    written = false ;
    }

    close(){
        ofstr->close();
        delete ofstr;
        ofstr = NULL;
        ostr->close();
        delete ostr;
        ostr = NULL;
    }


    int main(){

        ostr = new std::ofstream;
        ostr->exceptions(std::ofstream::failbit|std::ofstream::badbit);
        ostr->open(_fileName.c_str(), std::ios::binary | std::ios::app);
        ofstr = new Poco::DeflatingOutputStream(*_ostr,         
        Poco::DeflatingStreamBuf::STREAM_GZIP);
        ofstr->precision(std::numeric_limits<double>::digits10);
        string data1 = "hello';
        string data2 = "hello';
        string data3 = "hello';
    written = false ;
    timer()//start
    compress(data1);
    if(written)
    {
    compress(data2);
    }

    if(written)
    {
    compress(data2);
    }

    if(written)
    {
    compress(data3);// timeup and time() is inovked and part of compress() is executed 
    }
    // Now I would like to use lastsucessfulwrite as the key and truncate the paritally witten data3
    // In case of normal file we use "truncate" system call

     close();
    }

【问题讨论】:

  • Hellooo 有人可以帮我解决上述问题

标签: c++ c++11 gzip poco poco-libraries


【解决方案1】:

您可以将任何标准 C++ 流函数与 Poco 流一起使用。

streampos pos = ofstr-&gt;tellp()

【讨论】:

  • 有没有像截断一样使用放气流中的位置擦除数据的方法?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-13
  • 2014-01-02
  • 2012-10-25
  • 1970-01-01
  • 2021-10-31
  • 2017-05-06
相关资源
最近更新 更多