|
Boost Users : |
Subject: Re: [Boost-users] Read/write with gzip
From: johann (jgoetz_at_[hidden])
Date: 2011-04-27 12:10:13
I have a feeling this a file descriptor problem. I noticed you didn't close
the FD you opened when writing so I put the write and read blocks in their
own scope (see below). This seems to work now. I'm not sure if you can write
and read from a gzip'd file at the same time, maybe someone else can address
this issue?
compiled with boost 1.45 (gcc)
> g++ test.cpp -otest -lboost_iostreams -lboost_filesystem -lboost_system
> ./test
aaa
aaa
/// BEGIN file: test.cpp
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/filesystem.hpp>
using namespace std;
namespace io = boost::iostreams;
int main()
{
char* memblock_out = (char*) "aaa";
{
io::filtering_ostream out;
out.push(io::gzip_compressor());
out.push(io::file_descriptor_sink("outfile.tmp.gz"));
out.write(memblock_out, size);
}
cout << memblock_out << endl;
char* memblock_in = new char [4];
{
io::filtering_istream in;
in.push(io::gzip_decompressor());
in.push(io::file_descriptor_source("outfile.tmp.gz"));
in.read(memblock_in, size);
}
cout << memblock_in << endl;
}
/// EOF
-- View this message in context: http://boost.2283326.n4.nabble.com/Read-write-with-gzip-tp3478438p3478631.html Sent from the Boost - Users mailing list archive at Nabble.com.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net