如何在Poco::DeflatingOutputStream中查找索引
How to find the index in Poco::DeflatingOutputStream
嗨,我是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()
相关文章:
- 查找最接近的大于当前数字的数字的索引
- 查找字符在两个索引之间出现的次数
- 如何查找哪个类对象位于数组的特定索引上(多态性)
- 在对向量中查找元素的索引
- 查找索引的最接近的真实值
- C++ char 类查找字符索引
- 保持排序的数据结构,允许log N插入时间,并且可以返回我在log N中查找的元素的索引
- 查找数组中重复(重复)数字的索引
- 查找下一个具有真值C++的数组索引
- 在不进行排序的情况下查找数组中n个最小值的索引
- 在索引0为0的数组中查找非零最小值C++
- 查找索引数据结构,例如`sTD :: vector`(非数组)
- 查找索引值在char表中
- C++ std::lower_bound() 函数来查找索引排序向量的插入点
- 在数组中查找索引 给出它之前和之后的总和
- 使用向量时查找索引<>::迭代器
- 如何在Poco::DeflatingOutputStream中查找索引
- 如何在首次出现最大值的排序数组中查找索引
- 在字符串 C++ 中查找索引
- 使用AddFontResource()临时添加到系统字体表中的字体的C++查找索引,以便在控制台中使用