Hi Guys,

I am working with protocol buffers and I have come across this weird
problem:

Objective : The objective was to write a few thousand messages after
zipping them in a file. I do it like this:

 void write() {
    int fd = open("myfile", O_WRONLY), O_APPEND);
    google::protobuf::io::ZeroCopyOutputStream *out = new
google::protobuf::io::FileOutputStream(fd);
    google::protobuf::io::GzipOutputStream *gzipOut = new
google::protobuf::io::GzipOutputStream(out, options);
    google::protobuf::io::CodedOutputStream *codedOut = new
google::protobuf::io::CodedOutputStream(gzipOut);
    codedOut->WriteVarint32(message.ByteSize());
    message.SerializeToCodedStream(codedOut);
    close(fd);
 }

This gives me a file of size 54k but when I don't use gzipstream and
directly write the encoded message in the file like below it gives me
a file of size 38k (<54k)

   google::protobuf::io::ZeroCopyOutputStream *out = new
google::protobuf::io::FileOutputStream(fd);
   google::protobuf::io::CodedOutputStream *codedOut = new
google::protobuf::io::CodedOutputStream(out);
   codedOut->WriteVarint32(message.ByteSize());
   message.SerializeToCodedStream(codedOut);


The gzip'd file can be unzipped from command line using 'gzip -d
<filename> which indicates that it is a valid file and after unzipping
the file its size comes down to 38k
Also I tried using ZLIB format for the gzipoutputstream it gives me a
file of 42k again greater than 38k(size of uncompressed file). I also
tried gzipping the uncompressed file from command line and it gave me
a file of size 2.3 kB which was what I was expecting for gzip stream
too.

I am completely stumped here, instead of compressing the file it has
increased the size of the file.

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to