private adler32 ( long adler, byte buf, int index, int len ) : long | ||
adler | long | |
buf | byte | |
index | int | |
len | int | |
return | long |
public long CreateChecksum() { Adler32 adler32 = new Adler32(); long a1 = 0, a2 = 0; byte[] header_value = new byte[Header]; content.Seek(0, SeekOrigin.Begin); content.Read(header_value, 0, Header); for (int i = 0; i < Header; i += 6) { int pos = ByteBuffer.ReadInt4(header_value, i); int len = ((int)ByteBuffer.ReadInt2(header_value, i + 4)) & 0x0FFFF; byte[] node = new byte[len]; content.Seek(pos, SeekOrigin.Begin); content.Read(node, 0, len); if ((i & 0x01) == 0) { a1 = adler32.adler32(a1, node, 0, len); } else { a2 = adler32.adler32(a2, node, 0, len); } } // Return the 64 bit value checksum, return (a1 << 32) | a2; }
internal int inflateSetDictionary(ZStream z, byte[] dictionary, int dictLength) { int index = 0; int length = dictLength; if (z == null || z.istate == null || z.istate.mode != DICT0) { return(Z_STREAM_ERROR); } if (Adler32.adler32(1L, dictionary, 0, dictLength) != z.adler) { return(Z_DATA_ERROR); } z.adler = Adler32.adler32(0, null, 0, 0); if (length >= (1 << z.istate.wbits)) { length = (1 << z.istate.wbits) - 1; index = dictLength - length; } z.istate.blocks.set_dictionary(dictionary, index, length); z.istate.mode = BLOCKS; return(Z_OK); }
internal int read_buf(byte[] buf, int start, int size) { int num = avail_in; if (num > size) { num = size; } if (num == 0) { return(0); } avail_in -= num; if (dstate.noheader == 0) { adler = _adler.adler32(adler, next_in, next_in_index, num); } Array.Copy(next_in, next_in_index, buf, start, num); next_in_index += num; total_in += num; return(num); }
// Read a new buffer from the current input stream, update the adler32 // and total number of bytes read. All deflate() input goes through // this function so some applications may wish to modify it to avoid // allocating a large strm->next_in buffer and copying from it. // (See also flush_pending()). internal int read_buf(byte[] buf, int start, int size) { int len = avail_in; if (len > size) { len = size; } if (len == 0) { return(0); } avail_in -= len; if (dstate.noheader == 0) { adler = _adler.adler32(adler, next_in, next_in_index, len); } Array.Copy(next_in, next_in_index, buf, start, len); next_in_index += len; total_in += len; return(len); }
internal void reset(ZStream z, long[] c) { if (c != null) { c[0] = check; } if (mode == BTREE || mode == DTREE) { blens = null; } if (mode == CODES) { codes.free(z); } mode = TYPE; bitk = 0; bitb = 0; read = write = 0; if (checkfn != null) { z.adler = check = Adler32.adler32(0L, null, 0, 0); } }
// copy as much as possible from the sliding window to the output area internal int inflate_flush(ZStream z, int r) { // local copies of source and destination pointers var p = z.next_out_index; var q = read; // compute number of bytes to copy as far as end of window var n = (q <= write ? write : end) - q; if (n > z.avail_out) { n = z.avail_out; } if (n != 0 && r == Z_BUF_ERROR) { r = Z_OK; } // update counters z.avail_out -= n; z.total_out += n; // update check information if (checkfn != null) { z.adler = check = Adler32.adler32(check, window, q, n); } // copy as far as end of window Array.Copy(window, q, z.next_out, p, n); p += n; q += n; // see if more to copy at beginning of window if (q == end) { // wrap pointers q = 0; if (write == end) { write = 0; } // compute bytes to copy n = write - q; if (n > z.avail_out) { n = z.avail_out; } if (n != 0 && r == Z_BUF_ERROR) { r = Z_OK; } // update counters z.avail_out -= n; z.total_out += n; // update check information if (checkfn != null) { z.adler = check = Adler32.adler32(check, window, q, n); } // copy Array.Copy(window, q, z.next_out, p, n); p += n; q += n; } // update pointers z.next_out_index = p; read = q; // done return(r); }