@@ -152,14 +152,17 @@ create_compression_context (PyObject * Py_UNUSED (self))
152
152
" - lz4.frame.CONTENTCHECKSUM_DISABLED or 0: disables checksumming\n" \
153
153
" - lz4.frame.CONTENTCHECKSUM_ENABLED or 1: enables checksumming\n\n" \
154
154
" The default is CONTENTCHECKSUM_DISABLED.\n" \
155
+ " content_size (bool): Specifies whether to include an optional 8-byte header\n" \
156
+ " field that is the uncompressed size of data included within the frame.\n" \
157
+ " Including the content-size header is optional, and is enabled by default.\n" \
155
158
" frame_type (int): Specifies whether user data can be injected between\n" \
156
159
" frames. Options:\n\n" \
157
160
" - lz4.frame.FRAMETYPE_FRAME or 0: disables user data injection\n" \
158
161
" - lz4.frame.FRAMETYPE_SKIPPABLEFRAME or 1: enables user data injection\n\n" \
159
162
" The default is lz4.frame.FRAMETYPE_FRAME.\n" \
160
163
161
164
PyDoc_STRVAR (compress__doc ,
162
- "compress(source, compression_level=0, block_size=0, content_checksum=0, block_mode=0, frame_type=0)\n\n" \
165
+ "compress(source, compression_level=0, block_size=0, content_checksum=0, content_size=1, block_mode=0, frame_type=0)\n\n" \
163
166
"Accepts a string, and compresses the string in one go, returning the\n" \
164
167
"compressed string as a string of bytes. The compressed string includes\n" \
165
168
"a header and endmark and so is suitable for writing to a file.\n\n" \
@@ -178,6 +181,7 @@ compress (PyObject * Py_UNUSED (self), PyObject * args,
178
181
{
179
182
const char * source ;
180
183
int source_size ;
184
+ int content_size_header = 1 ;
181
185
LZ4F_preferences_t preferences ;
182
186
size_t compressed_bound ;
183
187
Py_ssize_t dest_size ;
@@ -188,6 +192,7 @@ compress (PyObject * Py_UNUSED (self), PyObject * args,
188
192
"compression_level" ,
189
193
"block_size" ,
190
194
"content_checksum" ,
195
+ "content_size" ,
191
196
"block_mode" ,
192
197
"frame_type" ,
193
198
NULL
@@ -196,20 +201,28 @@ compress (PyObject * Py_UNUSED (self), PyObject * args,
196
201
197
202
memset (& preferences , 0 , sizeof (preferences ));
198
203
199
- if (!PyArg_ParseTupleAndKeywords (args , keywds , "s#|iiiii " , kwlist ,
204
+ if (!PyArg_ParseTupleAndKeywords (args , keywds , "s#|iiiiii " , kwlist ,
200
205
& source , & source_size ,
201
206
& preferences .compressionLevel ,
202
207
& preferences .frameInfo .blockSizeID ,
203
208
& preferences .
204
209
frameInfo .contentChecksumFlag ,
210
+ & content_size_header ,
205
211
& preferences .frameInfo .blockMode ,
206
212
& preferences .frameInfo .frameType ))
207
213
{
208
214
return NULL ;
209
215
}
210
216
211
217
preferences .autoFlush = 0 ;
212
- preferences .frameInfo .contentSize = source_size ;
218
+ if (content_size_header )
219
+ {
220
+ preferences .frameInfo .contentSize = source_size ;
221
+ }
222
+ else
223
+ {
224
+ preferences .frameInfo .contentSize = 0 ;
225
+ }
213
226
214
227
Py_BEGIN_ALLOW_THREADS
215
228
compressed_bound =
@@ -272,7 +285,7 @@ compress (PyObject * Py_UNUSED (self), PyObject * args,
272
285
******************/
273
286
PyDoc_STRVAR (compress_begin__doc ,
274
287
"compress_begin(cCtx, source_size=0, compression_level=0, block_size=0,\n" \
275
- " content_checksum=0, block_mode=0, frame_type=0, auto_flush=1)\n\n" \
288
+ " content_checksum=0, content_size=1, block_mode=0, frame_type=0, auto_flush=1)\n\n" \
276
289
"Creates a frame header from a compression context.\n\n" \
277
290
"Args:\n" \
278
291
" context (cCtx): A compression context.\n\n" \
@@ -296,6 +309,7 @@ compress_begin (PyObject * Py_UNUSED (self), PyObject * args,
296
309
{
297
310
PyObject * py_context = NULL ;
298
311
unsigned long source_size = 0 ;
312
+ int content_size_header = 1 ;
299
313
LZ4F_preferences_t preferences ;
300
314
/* Only needs to be large enough for a header, which is 15 bytes.
301
315
* Unfortunately, the lz4 library doesn't provide a #define for this.
@@ -308,6 +322,7 @@ compress_begin (PyObject * Py_UNUSED (self), PyObject * args,
308
322
"compression_level" ,
309
323
"block_size" ,
310
324
"content_checksum" ,
325
+ "content_size" ,
311
326
"block_mode" ,
312
327
"frame_type" ,
313
328
"auto_flush" ,
@@ -320,12 +335,13 @@ compress_begin (PyObject * Py_UNUSED (self), PyObject * args,
320
335
argument */
321
336
preferences .autoFlush = 1 ;
322
337
323
- if (!PyArg_ParseTupleAndKeywords (args , keywds , "O|kiiiiii " , kwlist ,
338
+ if (!PyArg_ParseTupleAndKeywords (args , keywds , "O|kiiiiiii " , kwlist ,
324
339
& py_context ,
325
340
& source_size ,
326
341
& preferences .compressionLevel ,
327
342
& preferences .frameInfo .blockSizeID ,
328
343
& preferences .frameInfo .contentChecksumFlag ,
344
+ & content_size_header ,
329
345
& preferences .frameInfo .blockMode ,
330
346
& preferences .frameInfo .frameType ,
331
347
& preferences .autoFlush
@@ -334,7 +350,14 @@ compress_begin (PyObject * Py_UNUSED (self), PyObject * args,
334
350
return NULL ;
335
351
}
336
352
337
- preferences .frameInfo .contentSize = source_size ;
353
+ if (content_size_header )
354
+ {
355
+ preferences .frameInfo .contentSize = source_size ;
356
+ }
357
+ else
358
+ {
359
+ preferences .frameInfo .contentSize = 0 ;
360
+ }
338
361
339
362
context =
340
363
(struct compression_context * ) PyCapsule_GetPointer (py_context , capsule_name );
0 commit comments