4141
4242#define  MAX (a , b )               ((a) > (b) ? (a) : (b))
4343
44+ static  PyObject  * inputError ;
45+ 
4446typedef  int  (* compressor )(const  char  * source , char  * dest , int  isize );
4547
4648static  inline  void  store_le32 (char  * c , uint32_t  x ) {
@@ -55,6 +57,16 @@ static inline uint32_t load_le32(const char *c) {
5557    return  d [0 ] | (d [1 ] << 8 ) | (d [2 ] << 16 ) | (d [3 ] << 24 );
5658}
5759
60+ static  inline  char *  add_extension (char *  input ) {
61+     char *  output ;
62+ 
63+     output  =  (char * )malloc (strlen (input )+ 4 );
64+     strcpy (output , input );
65+     strcat (output , ".lz4" );
66+ 
67+     return  output ;
68+ }
69+ 
5870static  const  int  hdr_size  =  sizeof (uint32_t );
5971
6072static  PyObject  * compress_with (compressor  compress , PyObject  * self , PyObject  * args ) {
@@ -129,25 +141,75 @@ static PyObject *py_lz4_uncompress(PyObject *self, PyObject *args) {
129141    return  result ;
130142}
131143
132- 
133144static  PyObject  * py_lz4_compressFileDefault (PyObject  * self , PyObject  * args ) {
134145    char *  input ;
135146    char *  output ;
136-     int  compLevel ;
147+     int  compLevel   =   0 ;
137148
138149    (void )self ;
139-     if  (!PyArg_ParseTuple (args , "si " , & input , & compLevel )) {
150+     if  (!PyArg_ParseTuple (args , "s|i " , & input , & compLevel )) {
140151        return  NULL ;
141152    }
142153
143-     output  =  (char * )malloc (strlen (input )+ 4 );
144-     strcpy (output , input );
145-     strcat (output , ".lz4" );
154+     output  =  add_extension (input );
146155
147156    LZ4IO_compressFilename (input , output , compLevel );
148157    return  Py_None ;
149158}
150159
160+ static  PyObject  * py_lz4_compressFileAdv (PyObject  * self , PyObject  * args , PyObject  * keywds ) {
161+     char *  input ;
162+     char *  output  =  NULL ;
163+     int  compLevel  =  0 ;
164+     int  overwrite  =  NULL ;
165+     int  blockSizeID  =  NULL ;
166+     int  blockMode  =  1 ;
167+     int  blockCheck  =  NULL ;
168+     int  streamCheck  =  NULL ;
169+     int  verbosity  =  NULL ;
170+ 
171+     static  char  * kwlist [] =  {"input" , "compLevel" , "output" , "overwrite" , 
172+                              "blockSizeID" , "blockMode" , "blockCheck" , 
173+                              "streamCheck" , "verbosity" , NULL };
174+     (void )self ;
175+     if  (!PyArg_ParseTupleAndKeywords (args , keywds , "si|siiiii" , kwlist ,
176+                                      & input , & compLevel , & output , & overwrite , 
177+                                      & blockSizeID , & blockMode , & blockCheck , 
178+                                      & streamCheck , & verbosity )) {
179+         return  NULL ;
180+     }
181+     
182+     if  (!output ) {
183+         output  =  add_extension (input );
184+     }
185+     if  (overwrite ) {
186+         LZ4IO_setOverwrite (overwrite );
187+     }
188+     if  (blockSizeID ) {
189+         if  ((3  <  blockSizeID ) &&  (blockSizeID  <  8 )) {
190+             LZ4IO_setBlockSizeID (blockSizeID );
191+         }
192+         else  {
193+             PyErr_SetString (inputError , "Invalid input for blockSizeID" );
194+         }
195+     }
196+     if  ( (blockMode  ==  0 ) ||  (blockMode  ==  1 )) {
197+         if  (blockMode  ==  0  ) {
198+             printf ("%s" , "Getting this far, 2" );
199+             LZ4IO_setBlockMode (independentBlocks );
200+         } 
201+         printf ("%s" , "Getting this far, 3" );
202+     }
203+     else  {
204+         PyErr_SetString (inputError , "Invalid input for blockMode" );
205+         return  NULL ;
206+     }
207+     if  (blockCheck ) {
208+     }
209+     
210+     LZ4IO_compressFilename (input , output , compLevel );
211+     return  Py_None ;
212+ }
151213
152214static  PyObject  * py_lz4_decompressFileDefault (PyObject  * self , PyObject  * args ) {
153215    char *  input ;
@@ -163,8 +225,6 @@ static PyObject *py_lz4_decompressFileDefault(PyObject *self, PyObject *args) {
163225    output  =  (char * )calloc (outLen , sizeof (char ));
164226    strncpy (output , input , outLen );
165227
166-     printf ("%s \n" , output );
167- 
168228    LZ4IO_decompressFilename (input , output );
169229    return  Py_None ;
170230}
@@ -178,7 +238,8 @@ static PyMethodDef Lz4Methods[] = {
178238    {"uncompress" ,  py_lz4_uncompress , METH_VARARGS , UNCOMPRESS_DOCSTRING },
179239    {"decompress" ,  py_lz4_uncompress , METH_VARARGS , UNCOMPRESS_DOCSTRING },
180240    {"dumps" ,  py_lz4_compress , METH_VARARGS , COMPRESS_DOCSTRING },
181-     {"loads" ,  py_lz4_uncompress , METH_VARARGS , UNCOMPRESS_DOCSTRING },
241+     {"loads" , py_lz4_uncompress , METH_VARARGS , UNCOMPRESS_DOCSTRING },
242+     {"compressFileAdv" , (PyCFunction )py_lz4_compressFileAdv , METH_VARARGS  | METH_KEYWORDS , COMPRESS_FILE_DOCSTRING },
182243    {"compressFileDefault" , py_lz4_compressFileDefault , METH_VARARGS , COMPRESS_FILE_DOCSTRING },
183244    {"decompressFileDefault" , py_lz4_decompressFileDefault , METH_VARARGS , DECOMPRESS_FILE_DOCSTRING },
184245    {NULL , NULL , 0 , NULL }
@@ -190,6 +251,7 @@ struct module_state {
190251    PyObject  * error ;
191252};
192253
254+ 
193255#if  PY_MAJOR_VERSION  >= 3 
194256#define  GETSTATE (m ) ((struct module_state*)PyModule_GetState(m))
195257#else 
@@ -248,7 +310,9 @@ void initlz4(void)
248310        Py_DECREF (module );
249311        INITERROR ;
250312    }
251- 
313+     inputError  =  PyErr_NewException ("input.error" , NULL , NULL );
314+     Py_INCREF (inputError );
315+     PyModule_AddObject (module , "error" , inputError );
252316#if  PY_MAJOR_VERSION  >= 3 
253317    return  module ;
254318#endif 
0 commit comments