@@ -247,6 +247,25 @@ Compressing and decompressing data in memory
247247 The *mode * argument is a :class: `ZstdCompressor ` attribute, either
248248 :attr: `~.FLUSH_BLOCK `, or :attr: `~.FLUSH_FRAME `.
249249
250+ .. method :: set_pledged_input_size(size)
251+
252+ Specify the amount of uncompressed data *size * that will be provided for
253+ the next frame. *size * will be written into the frame header of the next
254+ frame unless :attr: `CompressionParameter.content_size_flag ` is ``False ``
255+ or ``0 ``. A size of ``0 `` means that the frame is empty. If *size * is
256+ ``None ``, the frame header will record the size as unknown.
257+
258+ If :attr: `~.last_mode ` is not :attr: `~.FLUSH_FRAME `, a
259+ :exc: `RuntimeError ` is raised as the compressor is not at the start of
260+ a frame. If the pledged size does not match the actual size of data
261+ provided to :meth: `~.compress `, future calls to :meth: `~.compress ` or
262+ :meth: `~.flush ` may raise :exc: `ZstdError ` and the last chunk of data may
263+ be lost.
264+
265+ After :meth: `~.flush ` or :meth: `~.compress ` are called with mode
266+ :attr: `~.FLUSH_FRAME `, the next frame will default to have an unknown
267+ size unless :meth: `!set_pledged_input_size ` is called again.
268+
250269 .. attribute :: CONTINUE
251270
252271 Collect more data for compression, which may or may not generate output
@@ -620,12 +639,17 @@ Advanced parameter control
620639 Write the size of the data to be compressed into the Zstandard frame
621640 header when known prior to compressing.
622641
623- This flag only takes effect under the following two scenarios:
642+ This flag only takes effect under the following three scenarios:
624643
625644 * Calling :func: `compress ` for one-shot compression
626645 * Providing all of the data to be compressed in the frame in a single
627646 :meth: `ZstdCompressor.compress ` call, with the
628647 :attr: `ZstdCompressor.FLUSH_FRAME ` mode.
648+ * Calling :meth: `ZstdCompressor.set_pledged_input_size ` with the exact
649+ amount of data that will be provided to the compressor prior to any
650+ calls to :meth: `ZstdCompressor.compress ` for the current frame.
651+ :meth: `!ZstdCompressor.set_pledged_input_size ` must be called for each
652+ new frame.
629653
630654 All other compression calls may not write the size information into the
631655 frame header.
0 commit comments