public static int inflateGetHeader( z_stream strm, gz_header head) { inflate_state state; /* check state */ if (inflateStateCheck(strm) != 0) { return(zlib.Z_STREAM_ERROR); } state = strm.state; if ((state.wrap & 2) == 0) { return(zlib.Z_STREAM_ERROR); } /* save header structure */ state.head = head; head.done = 0; return(zlib.Z_OK); }
// ========================================================================= // deflateSetHeader() provides gzip header information for when a gzip // stream is requested by deflateInit2(). deflateSetHeader() may be called // after deflateInit2() or deflateReset() and before the first call of // deflate(). The text, time, os, extra field, name, and comment information // in the provided gz_header structure are written to the gzip header (xflag is // ignored -- the extra flags are set according to the compression level). The // caller must assure that, if not Z_NULL, name and comment are terminated with // a zero byte, and that if extra is not Z_NULL, that extra_len bytes are // available there. If hcrc is true, a gzip header crc is included. Note that // the current versions of the command-line version of gzip (up through version // 1.3.x) do not support header crc's, and will report that it is a "multi-part // gzip file" and give up. // If deflateSetHeader is not used, the default gzip header has text false, // the time set to zero, and os set to 255, with no extra, name, or comment // fields. The gzip header is returned to the default state by deflateReset(). // deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source // stream state was inconsistent. public static int deflateSetHeader(z_stream strm, gz_header head) { if(strm==null||strm.state==null) return Z_STREAM_ERROR; deflate_state s=(deflate_state)strm.state; if(s.wrap!=2) return Z_STREAM_ERROR; s.gzhead=head; return Z_OK; }
// inflateGetHeader() requests that gzip header information be stored in the // provided gz_header structure. inflateGetHeader() may be called after // inflateInit2() or inflateReset(), and before the first call of inflate(). // As inflate() processes the gzip stream, head.done is zero until the header // is completed, at which time head.done is set to one. If a zlib stream is // being decoded, then head.done is set to -1 to indicate that there will be // no gzip header information forthcoming. Note that Z_BLOCK can be used to // force inflate() to return immediately after header processing is complete // and before any actual data is decompressed. // The text, time, xflags, and os fields are filled in with the gzip header // contents. hcrc is set to true if there is a header CRC. (The header CRC // was valid if done is set to one.) If extra is not Z_NULL, then extra_max // contains the maximum number of bytes to write to extra. Once done is true, // extra_len contains the actual extra field length, and extra contains the // extra field, or that field truncated if extra_max is less than extra_len. // If name is not Z_NULL, then up to name_max characters are written there, // terminated with a zero unless the length is greater than name_max. If // comment is not Z_NULL, then up to comm_max characters are written there, // terminated with a zero unless the length is greater than comm_max. When // any of extra, name, or comment are not Z_NULL and the respective field is // not present in the header, then that field is set to Z_NULL to signal its // absence. This allows the use of deflateSetHeader() with the returned // structure to duplicate the header. However if those fields are set to // allocated memory, then the application will need to save those pointers // elsewhere so that they can be eventually freed. // If inflateGetHeader is not used, then the header information is simply // discarded. The header is always checked for validity, including the header // CRC if present. inflateReset() will reset the process to discard the header // information. The application would need to call inflateGetHeader() again to // retrieve the header from the next gzip stream. // inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source // stream state was inconsistent. public static int inflateGetHeader(z_stream strm, gz_header head) { // check state if(strm==null||strm.state==null) return Z_STREAM_ERROR; inflate_state state=(inflate_state)strm.state; if((state.wrap&2)==0) return Z_STREAM_ERROR; // save header structure state.head=head; head.done=0; return Z_OK; }