Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google_crc32c/cext.py: 70%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Copyright 2020 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
15# NOTE: ``__config__`` **must** be the first import because it (may)
16# modify the search path used to locate shared libraries.
17import google_crc32c.__config__ # noqa: F401
18from google_crc32c._checksum import CommonChecksum
19from google_crc32c._crc32c import ( # type: ignore
20 extend,
21 value,
22)
25class Checksum(CommonChecksum):
26 """Hashlib-alike helper for CRC32C operations.
28 Args:
29 initial_value (Optional[bytes]): the initial chunk of data from
30 which the CRC32C checksum is computed. Defaults to b''.
31 """
33 __slots__ = ("_crc",)
35 def __init__(self, initial_value=b""):
36 self._crc = value(initial_value)
38 def update(self, chunk):
39 """Update the checksum with a new chunk of data.
41 Args:
42 chunk (Optional[bytes]): a chunk of data used to extend
43 the CRC32C checksum.
44 """
45 self._crc = extend(self._crc, chunk)