@@ -310,6 +310,46 @@ pylzma_delta_decode(PyObject *self, PyObject *args)
310
310
return result ;
311
311
}
312
312
313
+ const char
314
+ doc_delta_encode [] =
315
+ "delta_encode(data, delta) -- Encode Delta streams." ;
316
+
317
+ static PyObject *
318
+ pylzma_delta_encode (PyObject * self , PyObject * args )
319
+ {
320
+ char * data ;
321
+ PARSE_LENGTH_TYPE length ;
322
+ unsigned int delta ;
323
+ Byte state [DELTA_STATE_SIZE ];
324
+ Byte * tmp ;
325
+ PyObject * result ;
326
+
327
+ if (!PyArg_ParseTuple (args , "s#I" , & data , & length , & delta )) {
328
+ return NULL ;
329
+ }
330
+
331
+ if (!delta ) {
332
+ PyErr_SetString (PyExc_TypeError , "delta must be non-zero" );
333
+ return NULL ;
334
+ }
335
+
336
+ if (!length ) {
337
+ return PyBytes_FromString ("" );
338
+ }
339
+
340
+ result = PyBytes_FromStringAndSize (data , length );
341
+ if (!result ) {
342
+ return NULL ;
343
+ }
344
+
345
+ Delta_Init (state );
346
+ tmp = (Byte * ) PyBytes_AS_STRING (result );
347
+ Py_BEGIN_ALLOW_THREADS
348
+ Delta_Encode (state , delta , tmp , length );
349
+ Py_END_ALLOW_THREADS
350
+ return result ;
351
+ }
352
+
313
353
PyMethodDef
314
354
methods [] = {
315
355
// exported functions
@@ -331,6 +371,7 @@ methods[] = {
331
371
{"bcj2_decode" , (PyCFunction )pylzma_bcj2_decode , METH_VARARGS , (char * )& doc_bcj2_decode },
332
372
// Delta
333
373
{"delta_decode" , (PyCFunction )pylzma_delta_decode , METH_VARARGS , (char * )& doc_delta_decode },
374
+ {"delta_encode" , (PyCFunction )pylzma_delta_encode , METH_VARARGS , (char * )& doc_delta_encode },
334
375
{NULL , NULL },
335
376
};
336
377
0 commit comments