8000 zlib demo · codepongo/utocode@636f2ef · GitHub
[go: up one dir, main page]

Skip to content

Commit 636f2ef

Browse files
committed
zlib demo
1 parent 2f17ebe commit 636f2ef
< 8000 button data-component="IconButton" type="button" data-testid="expand-file-tree-button" aria-expanded="false" aria-controls="diff_file_tree" data-analytics-opt-out="true" class="prc-Button-ButtonBase-c50BI d-md-none position-relative fgColor-muted prc-Button-IconButton-szpyj" data-loading="false" data-no-visuals="true" data-size="medium" data-variant="invisible" aria-describedby=":R2iplab:-loading-announcement" aria-labelledby="expand-button-file-tree-button">

18 files changed

+5849
-0
lines changed

cs/zlib/Adler32.cs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright (c) 2006, ComponentAce
2+
// http://www.componentace.com
3+
// All rights reserved.
4+
5+
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6+
7+
// Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8+
// Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9+
// Neither the name of ComponentAce nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11+
12+
13+
14+
/*
15+
Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
16+
17+
Redistribution and use in source and binary forms, with or without
18+
modification, are permitted provided that the following conditions are met:
19+
20+
1. Redistributions of source code must retain the above copyright notice,
21+
this list of conditions and the following disclaimer.
22+
23+
2. Redistributions in binary form must reproduce the above copyright
24+
notice, this list of conditions and the following disclaimer in
25+
the documentation and/or other materials provided with the distribution.
26+
27+
3. The names of the authors may not be used to endorse or promote products
28+
derived from this software without specific prior written permission.
29+
30+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
31+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
32+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
33+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
34+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
36+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
39+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40+
*/
41+
/*
42+
* This program is based on zlib-1.1.3, so all credit should go authors
43+
* Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
44+
* and contributors of zlib.
45+
*/
46+
using System;
47+
namespace ComponentAce.Compression.Libs.zlib
48+
{
49+
50+
sealed class Adler32
51+
{
52+
53+
// largest prime smaller than 65536
54+
private const int BASE = 65521;
55+
// NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
56+
private const int NMAX = 5552;
57+
58+
internal long adler32(long adler, byte[] buf, int index, int len)
59+
{
60+
if (buf == null)
61+
{
62+
return 1L;
63+
}
64+
65+
long s1 = adler & 0xffff;
66+
long s2 = (adler >> 16) & 0xffff;
67+
int k;
68+
69+
while (len > 0)
70+
{
71+
k = len < NMAX?len:NMAX;
72+
len -= k;
73+
while (k >= 16)
74+
{
75+
s1 += (buf[index++] & 0xff); s2 += s1;
76+
s1 += (buf[index++] & 0xff); s2 += s1;
77+
s1 += (buf[index++] & 0xff); s2 += s1;
78+
s1 += (buf[index++] & 0xff); s2 += s1;
79+
s1 += (buf[index++] & 0xff); s2 += s1;
80+
s1 += (buf[index++] & 0xff); s2 += s1;
81+
s1 += (buf[index++] & 0xff); s2 += s1;
82+
s1 += (buf[index++] & 0xff); s2 += s1;
83+
s1 += (buf[index++] & 0xff); s2 += s1;
84+
s1 += (buf[index++] & 0xff); s2 += s1;
85+
s1 += (buf[index++] & 0xff); s2 += s1;
86+
s1 += (buf[index++] & 0xff); s2 += s1;
87+
s1 += (buf[index++] & 0xff); s2 += s1;
88+
s1 += (buf[index++] & 0xff); s2 += s1;
89+
s1 += (buf[index++] & 0xff); s2 += s1;
90+
s1 += (buf[index++] & 0xff); s2 += s1;
91+
k -= 16;
92+
}
93+
if (k != 0)
94+
{
95+
do
96+
{
97+
s1 += (buf[index++] & 0xff); s2 += s1;
98+
}
99+
while (--k != 0);
100+
}
101+
s1 %= BASE;
102+
s2 %= BASE;
103+
}
104+
return (s2 << 16) | s1;
105+
}
106+
107+
}
108+
}

0 commit comments

Comments
 (0)
0