33
44from os import PathLike
55
6- from _zstd import ZstdCompressor , ZstdDecompressor , _ZSTD_DStreamSizes , ZstdError
6+ from _zstd import (ZstdCompressor , ZstdDecompressor , _ZSTD_DStreamSizes ,
7+ ZstdError )
78from compression ._common import _streams
89
910__all__ = ("ZstdFile" , "open" )
@@ -50,13 +51,15 @@ def __init__(
5051 creating exclusively, or "a" for appending. These can equivalently be
5152 given as "rb", "wb", "xb" and "ab" respectively.
5253
53- Parameters
54- level: The compression level to use, defaults to ZSTD_CLEVEL_DEFAULT. Note,
55- in read mode (decompression), compression level is not supported.
56- options: A dict object, containing advanced compression
57- parameters.
58- zstd_dict: A ZstdDict object, pre-trained dictionary for compression /
59- decompression.
54+
55+ *level* is an int specifying the compression level to use, defaulting to
56+ COMPRESSION_LEVEL_DEFAULT
57+
58+ *options* is a dict object that contains advanced compression
59+ parameters. See CParameter or DParameter for more on options.
60+
61+ *zstd_dict* is a ZstdDict object, a pre-trained Zstandard dictionary.
62+ See the function train_dict for how to train a ZstdDict on sample data.
6063 """
6164 self ._fp = None
6265 self ._closefp = False
@@ -68,12 +71,13 @@ def __init__(
6871 raise TypeError (
6972 (
7073 "In read mode (decompression), options argument "
71- "should be a dict object, that represents decompression "
72- "options."
74+ "should be a dict object, that represents "
75+ "decompression options."
7376 )
7477 )
7578 if level is not None :
76- raise TypeError ("level argument should only be passed when writing." )
79+ raise TypeError ("level argument should only be passed when "
80+ "writing." )
7781 mode_code = _MODE_READ
7882 elif mode in ("w" , "wb" , "a" , "ab" , "x" , "xb" ):
7983 if not isinstance (level , (type (None ), int )):
@@ -97,7 +101,8 @@ def __init__(
97101 elif hasattr (filename , "read" ) or hasattr (filename , "write" ):
98102 self ._fp = filename
99103 else :
100- raise TypeError ("filename must be a str, bytes, file or PathLike object" )
104+ raise TypeError ("filename must be a str, bytes, file or PathLike "
105+ "object" )
101106 self ._mode = mode_code
102107
103108 if self ._mode == _MODE_READ :
@@ -137,7 +142,7 @@ def close(self):
137142 self ._closefp = False
138143
139144 def write (self , data ):
140- """Write a bytes-like object to the file.
145+ """Write a bytes-like object *data* to the file.
141146
142147 Returns the number of uncompressed bytes written, which is
143148 always the length of data in bytes. Note that due to buffering,
@@ -160,7 +165,7 @@ def write(self, data):
160165 def flush (self , mode = FLUSH_BLOCK ):
161166 """Flush remaining data to the underlying stream.
162167
163- The mode argument can be ZstdFile.FLUSH_BLOCK, ZstdFile.FLUSH_FRAME.
168+ The mode argument can be ZstdFile.FLUSH_BLOCK or ZstdFile.FLUSH_FRAME.
164169 Abuse of this method will reduce compression ratio, use it only when
165170 necessary.
166171
0 commit comments