diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..9b86b2c
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,178 @@
+cmake_minimum_required(VERSION 3.11...3.16)
+
+project(icf VERSION 1.0 LANGUAGES CXX)
+option(PYTHON_SETUP "If invoked by setup.py" OFF)
+set(LIBTARGET ${PROJECT_NAME})
+set(PYTARGET ${PROJECT_NAME}_py)
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF)
+
+if(EXISTS $ENV{CONDA_PREFIX})
+ set(CMAKE_INSTALL_PREFIX $ENV{CONDA_PREFIX})
+
+endif()
+
+
+if((APPLE) OR (EXISTS $ENV{CONDA_PREFIX}))
+ # The following settings were copied from
+ # https://cmake.org/Wiki/CMake_RPATH_handling
+ # to avoid the rpath issue (issue #11998) that appears on OS X El Capitan
+ # https://forge.in2p3.fr/issues/11998
+
+ # use, i.e. don't skip the full RPATH for the build tree
+ set(CMAKE_SKIP_BUILD_RPATH FALSE)
+
+ # when building, don't use the install RPATH already
+ # (but later on when installing)
+ if(PYTHON_SETUP)
+ set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
+ else()
+ set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
+ endif()
+
+ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
+
+ # add the automatically determined parts of the RPATH
+ # which point to directories outside the build tree to the install RPATH
+ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+endif()
+
+find_package(Git QUIET)
+# find_package(Python3 COMPONENTS Interpreter)
+find_package(pybind11 QUIET)
+
+set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+include(CTest)
+include(ExternalProject)
+
+# Save executables to bin directory
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+
+# Dependencies
+include(FetchContent)
+
+if(NOT pybind11_FOUND)
+ FetchContent_Declare(
+ pybind11
+ GIT_REPOSITORY https://github.com/pybind/pybind11
+ GIT_TAG v2.4.3
+ GIT_SHALLOW TRUE
+ )
+
+ FetchContent_GetProperties(pybind11)
+ if(NOT pybind11_POPULATED)
+ FetchContent_Populate(pybind11)
+ add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
+ endif()
+endif()
+
+if(NOT PYTHON_SETUP)
+ message(STATUS "${Cyan}doctest${ColourReset}")
+ FetchContent_Declare(
+ doctest
+ GIT_REPOSITORY https://github.com/onqtam/doctest
+ GIT_TAG 2.3.6
+ GIT_SHALLOW TRUE
+ )
+ FetchContent_GetProperties(doctest)
+ if(NOT doctest_POPULATED)
+ FetchContent_Populate(doctest)
+ set(DOCTEST_WITH_TESTS OFF CACHE BOOL "No tests of doctests")
+ set(DOCTEST_NO_INSTALL ON CACHE BOOL "No doctest install")
+ add_subdirectory(${doctest_SOURCE_DIR} ${doctest_BINARY_DIR})
+ endif()
+ set(DOCTEST_INCLUDE_DIR ${doctest_SOURCE_DIR}/doctest CACHE INTERNAL "Path to include folder for doctest")
+endif()
+
+
+# src
+add_library(${LIBTARGET} SHARED src/icfFile.cc)
+target_include_directories(${LIBTARGET} PUBLIC
+ $
+ $
+ )
+target_compile_features(${LIBTARGET} PUBLIC cxx_std_11)
+
+if(PYTHON_SETUP AND NOT EXISTS $ENV{CONDA_PREFIX})
+ set_target_properties(${LIBTARGET}
+ PROPERTIES
+ PREFIX ""
+ LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/icf/_ext/"
+ )
+else()
+ install (TARGETS ${LIBTARGET} EXPORT icf-file-targets LIBRARY DESTINATION lib)
+ install (DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include)
+endif()
+# Makes it easier for IDEs to find all headers
+source_group(TREE "${PROJECT_SOURCE_DIR}/include" PREFIX "Header Files" FILES ${HEADER_LIST})
+
+#Get git version number
+execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=7
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+ OUTPUT_VARIABLE VERSION
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+set(ICF_VERSION_LONG ${VERSION})
+#parse the version information into pieces.
+string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
+string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
+string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")
+string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+(.*)" "\\1" VERSION_SHA1 "${VERSION}")
+set(ICF_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
+message(STATUS ICF_VERSION)
+configure_file( version_config.h.in ${CMAKE_BINARY_DIR}/generated/version_config.h )
+include_directories( ${CMAKE_BINARY_DIR}/generated/)
+
+
+# pybind
+# set(PỲTARGET_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/icf/_ext/")
+# message(${PYTARGET_OUTPUT_DIR})
+pybind11_add_module(${PYTARGET} pybind/module.cc pybind/icfFile.cc)
+target_link_libraries(${PYTARGET} PRIVATE ${LIBTARGET})
+set_target_properties(${PYTARGET}
+ PROPERTIES
+ PREFIX ""
+ LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/icf/_ext/"
+)
+if(NOT PYTHON_SETUP)
+# Python stuff
+# Creating a symlink to the python package
+add_custom_command(TARGET ${PYTARGET} POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E create_symlink "${PROJECT_SOURCE_DIR}/icf/" "${CMAKE_CURRENT_BINARY_DIR}/icf/_icf")
+# Python stuff
+# Creating a symlink to the python tests
+add_custom_command(TARGET ${PYTARGET} POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E create_symlink "${PROJECT_SOURCE_DIR}/pytest/" "${CMAKE_CURRENT_BINARY_DIR}/pytest")
+
+
+if(Python3_Interpreter_FOUND)
+ add_test(NAME PythonTests COMMAND python3 -m pytest -r a -v WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/pytest")
+endif()
+
+
+configure_file(setup.py.in "${PROJECT_BINARY_DIR}/setup.py")
+
+
+# Place the initialization file in the output directory for the Python
+# bindings. This will simplify the installation.
+CONFIGURE_FILE(__init__.py
+ ${CMAKE_CURRENT_BINARY_DIR}/icf/__init__.py
+)
+
+
+add_executable(test_icf ctests/test_icf.cc)# $)
+target_link_libraries(test_icf ${LIBTARGET})
+
+
+# ctests
+add_library(test_main OBJECT ctests/test_main.cc)
+target_include_directories(test_main PUBLIC ${DOCTEST_INCLUDE_DIR})
+
+add_executable(test_ICFFile ctests/ICFFile.cc $ )
+add_test(NAME test_ICFFile COMMAND test_ICFFile)
+target_link_libraries(test_ICFFile ${LIBTARGET})
+target_include_directories(test_ICFFile PUBLIC ctests ${DOCTEST_INCLUDE_DIR})
+target_compile_features(test_ICFFile PRIVATE cxx_std_11)
+
+endif()
\ No newline at end of file
diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..9de4b72
--- /dev/null
+++ b/__init__.py
@@ -0,0 +1,5 @@
+from ._icf import *
+from ._ext.icf_py import *
+from ._ext.icf_py import _get_version
+
+__version__ = _get_version()
diff --git a/ctests/ICFFile.cc b/ctests/ICFFile.cc
new file mode 100644
index 0000000..25193c9
--- /dev/null
+++ b/ctests/ICFFile.cc
@@ -0,0 +1,50 @@
+
+#include "icf/icfFile.h"
+#include "doctest.h"
+#include
+#include
+#include
+#include
+
+namespace icf {
+
+
+TEST_CASE("ICFFile") {
+ icf::ICFFile icf_file(std::string("/tmp/test.icf"),ICFFile::trunc);
+ std::vector data = {1,2,3,4,2,3,4};
+ auto n =3;
+ for(uint16_t i = 0; idata();
+ for(uint16_t i =0; idata();
+ for(uint16_t i =0; i
+
+#include "icf/icfFile.h"
+#include
+
+
+
+int main(){
+
+ icf::ICFFile icf_file(std::string("test.icf"));
+ // std::cout<= pos_start and curr_bunch > 0:
+
# read bunch trailer
bt = self._read_bunch_trailer()
@@ -251,6 +258,7 @@ def _scan_sub_file(self, pos_start, pos_end, file_index=0):
current_bt_fp -= bt.bunchoff
self._file.seek(current_bt_fp)
+
return rawindex
def _construct_file_index(self, rawindex):
@@ -267,7 +275,8 @@ def _get_bunch(self, bunch_id):
if bunch_id in self._bunch_buffer:
return self._bunch_buffer[bunch_id]
else:
- self._file.seek(self._file_index[bunch_id[0]] +self._bunch_index[bunch_id][0])
+
+ self._file.seek(self._file_index[bunch_id[0]] + self._bunch_index[bunch_id][0])
# bunch = self._compressor.decompress(
bunch = self._file.read(
self._bunch_index[bunch_id][1]
@@ -315,6 +324,7 @@ def read(self) -> bytes:
def __str__(self):
s = "{}:\n".format(self.__class__.__name__)
+
# s += "filename: {}\n".format(self.filename)
s += "timestamp: {}\n".format(datetime.fromtimestamp(self.timestamp))
s += "n_entries: {}\n".format(self.n_entries)
@@ -322,6 +332,7 @@ def __str__(self):
s += "number of sub files: {}\n".format(len(self._file_index))
# for k, v in self.metadata.items():
# s += "{}: {}\n".format(k, v)
+
s += "file format version: {}".format(self.version)
return s
diff --git a/include/icf/archive.h b/include/icf/archive.h
new file mode 100644
index 0000000..6a2c978
--- /dev/null
+++ b/include/icf/archive.h
@@ -0,0 +1,381 @@
+/*
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to
+*/
+
+#ifndef ARCHIVE_H__
+#define ARCHIVE_H__
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include