MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / gz_write

Function gz_write

extlibs/minizip/src/gzwrite.c:197–273  ·  view source on GitHub ↗

Write len bytes from buf to file. Return the number of bytes written. If the returned value is less than len, then there was an error. */

(state, buf, len)

Source from the content-addressed store, hash-verified

195/* Write len bytes from buf to file. Return the number of bytes written. If
196 the returned value is less than len, then there was an error. */
197local z_size_t gz_write(state, buf, len)
198gz_statep state;
199voidpc buf;
200
201z_size_t len;
202{
203 z_size_t put = len;
204
205 /* if len is zero, avoid unnecessary operations */
206 if (len == 0)
207 return 0;
208
209 /* allocate memory if this is the first time through */
210 if (state->size == 0 && gz_init(state) == -1)
211 return 0;
212
213 /* check for seek request */
214 if (state->seek)
215 {
216 state->seek = 0;
217 if (gz_zero(state, state->skip) == -1)
218 return 0;
219 }
220
221 /* for small len, copy to input buffer, otherwise compress directly */
222 if (len < state->size)
223 {
224 /* copy to input buffer, compress when full */
225 do
226 {
227 unsigned have, copy;
228
229 if (state->strm.avail_in == 0)
230 state->strm.next_in = state->in;
231 have = (unsigned)((state->strm.next_in + state->strm.avail_in) -
232 state->in);
233 copy = state->size - have;
234 if (copy > len)
235 copy = len;
236 memcpy(state->in + have, buf, copy);
237 state->strm.avail_in += copy;
238 state->x.pos += copy;
239 buf = (const char *)buf + copy;
240 len -= copy;
241 if (len&& gz_comp(state, Z_NO_FLUSH)
242 ==
243 -1
244 )
245 return 0;
246 }
247 while (len);
248 }
249 else
250 {
251 /* consume whatever's left in the input buffer */
252 if (state->strm.avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
253 return 0;
254

Callers 4

gzwriteFunction · 0.85
gzfwriteFunction · 0.85
gzputcFunction · 0.85
gzputsFunction · 0.85

Calls 3

gz_initFunction · 0.85
gz_zeroFunction · 0.85
gz_compFunction · 0.85

Tested by

no test coverage detected