| 127 | } |
| 128 | |
| 129 | static bool write_buffer(std::ostream& os, z_stream& z, char* out_buf, void* p, size_t size, bool flush,std::ostream* errorStream) { |
| 130 | z.next_in=(Bytef*)p; |
| 131 | z.avail_in=(uInt)size; |
| 132 | while (z.avail_in!=0 || flush) { |
| 133 | z.next_out = (Bytef*)out_buf; |
| 134 | z.avail_out = OUT_BUFSIZE; |
| 135 | int ret=deflate(&z,flush?Z_FINISH:Z_NO_FLUSH); |
| 136 | if (!(ret!=Z_BUF_ERROR && ret!=Z_STREAM_ERROR)) { |
| 137 | if(errorStream) *errorStream<<"Zlib error "<<z.msg<<std::endl;; |
| 138 | return false; |
| 139 | } |
| 140 | int generated_output=(int)(z.next_out-(Bytef*)out_buf); |
| 141 | os.write((char*)out_buf,generated_output); |
| 142 | if (ret==Z_STREAM_END) break; |
| 143 | } |
| 144 | return true; |
| 145 | } |
| 146 | |
| 147 | |
| 148 | |