- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想解压缩文件并将其内容写入字符串流。
这是我试过的代码:
string readGZipLog () {
try {
using namespace boost::iostreams;
ifstream file(currentFile.c_str(), std::ios_base::in | std::ios_base::binary);
boost::iostreams::filtering_istream in;
in.push(gzip_decompressor());
in.push(file);
std::stringstream strstream;
boost::iostreams::copy(in, strstream);
return strstream.str();
} catch (std::exception& e) {
cout << e.what() << endl;
}
}
void writeGZipLog (char* data) {
try {
using namespace boost::iostreams;
std::ofstream file( currentFile.c_str(), std::ios_base::out | std::ios_base::binary );
boost::iostreams::filtering_ostream out;
out.push( gzip_compressor() );
out.push(file);
std::stringstream strstream;
strstream << data;
boost::iostreams::copy( strstream, data );
} catch (std::exception& e) {
cout << e.what() << endl;
}
}
它编译时没有任何警告(当然还有错误)但是函数 readGZipLog()
在运行时崩溃了:
gzip error
./build: line 3: 22174 Segmentation fault ./test
./build
是自动编译并启动应用程序./test
的脚本
我检查了文件:它包含一些东西,但我无法使用 gunzip
解压它。所以我不确定压缩是否正常工作,以及这是否与 Boost 抛出的 gzip 错误
有关。
你能给我打上错误的地方吗?
感谢您的帮助!
保罗
最佳答案
经过大量研究和尝试,我终于找到了一种正确处理(解)压缩的方法。
这是对我来说没有任何问题的代码(使用 gzip 和 bzip2):
string readGZipLog () {
using namespace boost::iostreams;
using namespace std;
try {
ifstream file(currentFile.c_str(), ios_base::in | ios_base::binary);
boost::iostreams::filtering_istream in;
in.push(gzip_decompressor());
in.push(file);
stringstream strstream;
boost::iostreams::copy(in, strstream);
return strstream.str();
} catch (const gzip_error& exception) {
cout << "Boost Description of Error: " << exception.what() << endl;
return "err";
}
}
bool writeGZipLog (char* data) {
using namespace boost::iostreams;
using namespace std;
try {
std::ofstream file( currentFile.c_str(), std::ios_base::app );
boost::iostreams::filtering_ostream out;
out.push( gzip_compressor() );
out.push(file);
stringstream strstream;
strstream << data;
boost::iostreams::copy(strstream, out);
return true;
} catch (const gzip_error& exception) {
cout << "Boost Description of Error: " << exception.what() << endl;
return false;
}
}
我能说的是,我犯了一些不必要的错误,我只是在几个小时后再次查看代码时才发现。 boost::iostreams::copy( std::stringstream , char* );
例如,如果 1 + 1 为 3,甚至会失败。
我希望这段代码能像帮助我一样帮助其他人。
保罗 :)
关于c++ - 如果我尝试将未压缩的 filtering_istream 复制到 stringstream 会崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4717892/
我需要一个算法,将帧(图片)写入一个文件,该文件可以被一些视频剪辑/制作软件读取以进行处理。 所以我得到了框架,我想给他们一个函数/方法的输入。让我们用 Java 来做吧。 我该怎么做?有没有一种简单
我正致力于为我们的一些系统之间的交互实现 GZIP 压缩。这些系统是用 Java 和 C# 编写的,因此双方都使用了 GZIP 流,因为它们具有标准库支持。 在 C# 方面,一切正常,包括我们最大的测
我的 Assets 没有被压缩。我正在使用 3.2.18, Assets 组具有这些 gems: group :assets do gem "compass-rails" gem 'coffe
这个问题在这里已经有了答案: Externalizing Tomcat webapp config from .war file (4 个答案) 关闭 7 年前。 我的应用程序 WAR 已经内置了一
我想将来自设备的未压缩帧存储为视频,但我需要知道如何选择“全帧(未压缩)”作为 VideoWriter(在 emgu aka openCV 中)的编解码器。 当我像这样传递 -1 时,我可以从下拉菜单
我注意到有些时候“另存为..”,上面写着“XFL 文件”“未压缩的 Flash 文件”。它有什么用?为什么我需要它而不是 FLA? 最佳答案 这是新的文件格式。它只不过是一个包含一个或多个 xml 之
我使用WiX3生成MSI安装包。我已在 中指定了压缩标志和元素: 但是生成的 MSI 根本没有被压缩 - WinZip 将其从 2M 压缩到 600K。 我错过了什么吗? 顺便说一句,我正在使用
有谁知道 Asp.Net 内容交付网络上的 jQuery 文件的缩小版本未进行 gzip 压缩是否有原因?非缩小版本已正确压缩。 示例: http://ajax.aspnetcdn.com/ajax/
当请求的内容长于表中的几行时,我在 Swift 4.2 中执行 HTTP 请求时遇到问题。我正在开发一个应用程序,需要显示 30 - 40 行的概述,每行包含 4-5 个变量。 我使用 HTTPReq
我有一些 .gz 压缩文件,未压缩时大约有 5-7gig。这些是平面文件。 我写了一个程序,它接受一个未压缩的文件,并逐行读取它,效果很好。 现在我希望能够打开内存中的压缩文件并运行我的小程序。 我研
我有一个灰度 TIFF 原始图像。我想在图片框中显示它,然后使用 AForge.Net 进行一些操作。我想知道最好的做法是什么。我无法显示图像 - 我要么得到黑色的“图片框”尝试转换为灰度时出现错误“
我是一名优秀的程序员,十分优秀!