Skip to content

Commit

Permalink
[API] Python: Add defaulted index_format argument to ParallelGzipRead…
Browse files Browse the repository at this point in the history
…er.export_index
  • Loading branch information
mxmlnkn committed May 20, 2024
1 parent cb93d82 commit 6e8fb1c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 10 additions & 4 deletions python/rapidgzip/rapidgzip.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ class IndexedBzip2File(io.BufferedReader):
cdef extern from "tools/rapidgzip.cpp":
int rapidgzipCLI(int, char**) except +

cdef extern from "rapidgzip/IndexFileFormat.hpp":
cpdef enum class IndexFormat:
INDEXED_GZIP,
GZTOOL,
GZTOOL_WITH_LINES,

cdef extern from "rapidgzip/ParallelGzipReader.hpp" namespace "rapidgzip":
cpdef enum class IOReadMethod(uint8_t):
SEQUENTIAL,
Expand Down Expand Up @@ -394,7 +400,7 @@ cdef extern from "rapidgzip/ParallelGzipReader.hpp" namespace "rapidgzip":
void setStatisticsEnabled(bool) except +
void setShowProfileOnDestruction(bool) except +
void importIndex(PyObject*) except +
void exportIndex(PyObject*) except +
void exportIndex(PyObject*, IndexFormat) except +
void joinThreads() except +
string fileTypeAsString() except +

Expand Down Expand Up @@ -551,14 +557,14 @@ cdef class _RapidgzipFile():
return self.gzipReader.importIndex(<PyObject*>fileObject)
return self.gzipReader.importIndex(<PyObject*>file)

def export_index(self, file):
def export_index(self, file, index_format = IndexFormat.INDEXED_GZIP):
if not self.gzipReader:
raise Exception("Invalid file object!")

if isinstance(file, str):
with builtins.open(file, "wb") as fileObject:
return self.gzipReader.exportIndex(<PyObject*>fileObject)
return self.gzipReader.exportIndex(<PyObject*>file)
return self.gzipReader.exportIndex(<PyObject*>fileObject, index_format)
return self.gzipReader.exportIndex(<PyObject*>file, index_format)

def join_threads(self):
if self.gzipReader:
Expand Down
5 changes: 3 additions & 2 deletions src/rapidgzip/ParallelGzipReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,8 @@ class ParallelGzipReader final :
}

void
exportIndex( PyObject* pythonObject )
exportIndex( PyObject* pythonObject,
const IndexFormat indexFormat = IndexFormat::INDEXED_GZIP )
{
const auto file = std::make_unique<PythonFileReader>( pythonObject );
const auto checkedWrite =
Expand All @@ -1048,7 +1049,7 @@ class ParallelGzipReader final :
}
};

exportIndex( checkedWrite );
exportIndex( checkedWrite, indexFormat );
}
#endif

Expand Down

0 comments on commit 6e8fb1c

Please sign in to comment.