File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,14 @@ cpdef uint32_t fletcher32(const uint16_t[::1] data):
2626
2727
2828class Fletcher32 (Codec ):
29+ """ The fletcher checksum with 16-bit words and 32-bit output
30+
31+ With this codec, the checksum is concatenated on the end of the data
32+ bytes when encoded. At decode time, the checksum is performed on
33+ the data portion and compared with the four-byte checksum, raising
34+ ValueError if inconsistent.
35+ """
36+
2937 codec_id = " fletcher32"
3038
3139 def encode (self , buf ):
@@ -49,7 +57,8 @@ class Fletcher32(Codec):
4957 found = b[- 4 :].view(' uint32' )[0 ]
5058 if val != found:
5159 raise ValueError (
52- f" The flecher32 checksum of the data ({found}) did not match the expected checksum ({val}). "
60+ f" The fletcher32 checksum of the data ({found}) did not"
61+ f" match the expected checksum ({val}).\n "
5362 " This could be a sign that the data has been corrupted."
5463 )
5564 if out:
Original file line number Diff line number Diff line change @@ -22,3 +22,15 @@ def test_with_data(dtype):
2222 f = Fletcher32 ()
2323 arr = np .frombuffer (f .decode (f .encode (data )), dtype = dtype )
2424 assert (arr == data ).all ()
25+
26+
27+ def test_error ():
28+ data = np .arange (100 )
29+ f = Fletcher32 ()
30+ enc = f .encode (data )
31+ enc2 = bytearray (enc )
32+ enc2 [0 ] += 1
33+ with pytest .raises (ValueError ) as e :
34+ f .decode (enc2 )
35+ assert "fletcher32 checksum" in str (e .value )
36+
You can’t perform that action at this time.
0 commit comments