File tree Expand file tree Collapse file tree 2 files changed +21
-17
lines changed Expand file tree Collapse file tree 2 files changed +21
-17
lines changed Original file line number Diff line number Diff line change 117117
118118 register_codec (MsgPack )
119119
120- from numcodecs .checksum32 import CRC32 , CRC32C , Adler32 , JenkinsLookup3
120+ from numcodecs .checksum32 import CRC32 , Adler32 , JenkinsLookup3
121121
122122register_codec (CRC32 )
123- register_codec (CRC32C )
124123register_codec (Adler32 )
125124register_codec (JenkinsLookup3 )
126125
126+ with suppress (ImportError ):
127+ from numcodecs .checksum32 import CRC32C
128+
129+ register_codec (CRC32C )
130+
127131from numcodecs .json import JSON
128132
129133register_codec (JSON )
Original file line number Diff line number Diff line change 11import struct
22import zlib
33from collections .abc import Callable
4+ from contextlib import suppress
45from typing import TYPE_CHECKING , Literal
56
67import numpy as np
@@ -76,26 +77,25 @@ class CRC32(Checksum32):
7677 location = 'start'
7778
7879
79- class CRC32C (Checksum32 ):
80- """Codec add a crc32c checksum to the buffer.
80+ _crc32c : Optional [ModuleType ] = None
81+ with suppress (ImportError ):
82+ import crc32c as _crc32c
8183
82- Parameters
83- ----------
84- location : 'start' or 'end'
85- Where to place the checksum in the buffer.
86- """
8784
88- codec_id = 'crc32c'
85+ if _crc32c :
86+ class CRC32C (Checksum32 ):
87+ """Codec add a crc32c checksum to the buffer.
8988
90- def checksum (self , buf ):
91- try :
92- from crc32c import crc32c as crc32c_
89+ Parameters
90+ ----------
91+ location : 'start' or 'end'
92+ Where to place the checksum in the buffer.
93+ """
9394
94- return crc32c_ (buf )
95- except ImportError : # pragma: no cover
96- raise ImportError ("crc32c must be installed to use the CRC32C checksum codec." )
95+ codec_id = 'crc32c'
9796
98- location = 'end'
97+ checksum = _crc32c .crc32c
98+ location = 'end'
9999
100100
101101class Adler32 (Checksum32 ):
You can’t perform that action at this time.
0 commit comments