如何在Poco::DeflatingOutputStream中查找索引

How to find the index in Poco::DeflatingOutputStream

本文关键字:查找 索引 DeflatingOutputStream Poco      更新时间:2023-10-16

嗨,我是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();
    }

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

streampos pos = ofstr->tellp()