File tree Expand file tree Collapse file tree 4 files changed +2084
-1692
lines changed Expand file tree Collapse file tree 4 files changed +2084
-1692
lines changed Original file line number Diff line number Diff line change 3030
3131"""
3232from __future__ import absolute_import , print_function , division
33+ from numcodecs .compat import handle_datetime
3334
3435
3536class Codec (object ):
@@ -39,6 +40,19 @@ class Codec(object):
3940 codec_id = None
4041 """Codec identifier."""
4142
43+ # 2GiB limit by default. Codecs can override this in subclasses if larger
44+ # buffers are supported.
45+ max_buffer_size = 2 ** 31 - 1
46+ """Maximum size of a buffer that can be encoded or decoded."""
47+
48+ def _check_buffer_size (self , buf ):
49+ buf = handle_datetime (buf )
50+ bufsize = memoryview (buf ).nbytes
51+ if bufsize > self .max_buffer_size :
52+ msg = "{} codec does not support buffers of > {} bytes" .format (
53+ self .codec_id , self .max_buffer_size )
54+ raise ValueError (msg )
55+
4256 def encode (self , buf ): # pragma: no cover
4357 """Encode data in `buf`.
4458
You can’t perform that action at this time.
0 commit comments