lib/ruby/truffle/pr-zlib/lib/pr/rbzlib.rb
# Compute the Adler-32 checksum of a data stream
Compute the Adler-32 checksum of a data stream
Compute the Adler - 32 checksum of a data stream
def adler32(adler, buf, len=0)
    return 1 if buf.nil?
    len = buf.length if len == 0
    sum2 = (adler >> 16) & 0xFFFF
    adler &= 0xffff
    if len == 1
      adler += buf[0].ord
      if adler >= BASE
        adler -= BASE
      end
      sum2 += adler
      if sum2 >= BASE
        sum2 -= BASE
      end
      return adler | (sum2 << 16)
    end
    if len < 16
      i = 0
      while len > 0
        len -= 1
        adler += buf[i].ord
        i += 1
        sum2 += adler
      end
      if adler >= BASE
        adler -= BASE
      end
      sum2 %= BASE
      return adler | (sum2 << 16)
    end
    i = 0
    while len >= NMAX
      len -= NMAX
      n = NMAX / 16
      loop do
        for j in 0 .. 15
          adler += buf[i+j].ord
          sum2 += adler
        end
        i += 16
        n -= 1
        break if n == 0
      end
      adler %= BASE
      sum2 %= BASE
    end
    if len != 0
      while (len >= 16)
        len -= 16
        for j in 0 .. 15
          adler += buf[i+j].ord
          sum2 += adler
        end
        i += 16
      end
      while len != 0
        len -= 1
        adler += buf[i].ord
        i += 1
        sum2 += adler
      end
      adler %= BASE
      sum2 %= BASE
    end
    return adler | (sum2 << 16)
  end
def adler32 ( adler , buf , len = 0 ) return 1 if buf . nil? len = buf . length if len == 0 sum2 = ( adler >> 16 ) & 0xFFFF adler &= 0xffff if len == 1 adler += buf [ 0 ] . ord if adler >= BASE adler -= BASE end sum2 += adler if sum2 >= BASE sum2 -= BASE end return adler | ( sum2 << 16 ) end if len < 16 i = 0 while len > 0 len -= 1 adler += buf [ i ] . ord i += 1 sum2 += adler end if adler >= BASE adler -= BASE end sum2 %= BASE return adler | ( sum2 << 16 ) end i = 0 while len >= NMAX len -= NMAX n = NMAX / 16 loop do for j in 0 .. 15 adler += buf [ i + j ] . ord sum2 += adler end i += 16 n -= 1 break if n == 0 end adler %= BASE sum2 %= BASE end if len != 0 while ( len >= 16 ) len -= 16 for j in 0 .. 15 adler += buf [ i + j ] . ord sum2 += adler end i += 16 end while len != 0 len -= 1 adler += buf [ i ] . ord i += 1 sum2 += adler end adler %= BASE sum2 %= BASE end return adler | ( sum2 << 16 ) end
Compute the Adler-32 checksum of a data stream
Compute the Adler - 32 checksum of a data stream
adler
<not_specific>
buf
<not_specific>
len
<not_specific>