<commit_before>#include "zipper.h"

extern "C"
{
	#include <stdio.h>
	#include <stdlib.h>
	#include <string.h>
	#include <time.h>
	#include <errno.h>
	#include <fcntl.h>

    #if (defined(_WIN32)) || (defined(_WIN64))
	# include <direct.h>
	# include <io.h>
	#else
	# include <unistd.h>
	# include <utime.h>
	#endif

	#include "zip.h"
	#include "unzip.h"
	#include "ioapi_mem.h"
	#define CASESENSITIVITY (0)
	#define WRITEBUFFERSIZE (8192)
	#define MAXFILENAME (256)

	#if (defined(_WIN32)) || (defined(_WIN64))
	#define USEWIN32IOAPI
	#include "iowin32.h"
	#endif
}

#if (defined(_WIN64)) && (!defined(__APPLE__))
        #ifndef __USE_FILE_OFFSET64
                #define __USE_FILE_OFFSET64
        #endif
        #ifndef __USE_LARGEFILE64
                #define __USE_LARGEFILE64
        #endif
        #ifndef _LARGEFILE64_SOURCE
                #define _LARGEFILE64_SOURCE
        #endif
        #ifndef _FILE_OFFSET_BIT
                #define _FILE_OFFSET_BIT 64
        #endif
#endif


/* calculate the CRC32 of a file,
   because to encrypt a file, we need known the CRC32 of the file before */

void getFileCrc(std::istream& input_stream, std::vector<char>& buff, unsigned long& result_crc)
{
    unsigned long calculate_crc=0;
    unsigned long size_read = 0;
    unsigned long total_read = 0;

    do {   
        input_stream.read(buff.data(), buff.size());
	    size_read = input_stream.gcount();

        if (size_read>0)
            calculate_crc = crc32(calculate_crc, (const unsigned char*)buff.data(), size_read);
		
        total_read += size_read;

    } while (size_read>0);

    input_stream.seekg(0);
    result_crc=calculate_crc;
}

bool isLargeFile(std::istream& input_stream)
{
    ZPOS64_T pos = 0;
    input_stream.seekg(0, std::ios::end);
    pos = input_stream.tellg();
	input_stream.seekg(0);
	
    return pos >= 0xffffffff;
}

namespace zipper {

	struct Zipper::Impl
	{
		Zipper& m_outer;
		zipFile m_zf;
		ourmemory_t m_zipmem = ourmemory_t();

		Impl(Zipper& outer) : m_outer(outer)
		{
			m_zf = NULL;
		}

		bool initFile(const std::string& filename)
		{
			int fileExists = 0;// chequear si existe el archivo!
			int mode = 0;
			int flags = Zipper::Overwrite;

			/* open the zip file for output */
			if (fileExists)
				mode = (flags & Zipper::Overwrite) ? APPEND_STATUS_CREATE : APPEND_STATUS_ADDINZIP;
			else
				mode = APPEND_STATUS_CREATE;

			m_zf = zipOpen(filename.c_str(), mode);

			return m_zf != NULL;
		}

		bool initMemory()
		{
			zlib_filefunc_def filefunc = { 0 };
			m_zipmem.grow = 1;

			fill_memory_filefunc (&filefunc, &m_zipmem);

			m_zf = zipOpen3("__notused__", APPEND_STATUS_CREATE, 0, 0, &filefunc);

			return m_zf != NULL;
		}

		bool add(std::istream& input_stream, const std::string& nameInZip, const std::string& password, int flags)
		{
			if (!m_zf) return false;
<commit_msg>changed methods to use 64 version<commit_after>#include "zipper.h"

extern "C"
{
	#include <stdio.h>
	#include <stdlib.h>
	#include <string.h>
	#include <time.h>
	#include <errno.h>
	#include <fcntl.h>

    #if (defined(_WIN32)) || (defined(_WIN64))
	# include <direct.h>
	# include <io.h>
	#else
	# include <unistd.h>
	# include <utime.h>
	#endif

	#include "zip.h"
	#include "unzip.h"
	#include "ioapi_mem.h"
	#define CASESENSITIVITY (0)
	#define WRITEBUFFERSIZE (8192)
	#define MAXFILENAME (256)

	#if (defined(_WIN32)) || (defined(_WIN64))
	#define USEWIN32IOAPI
	#include "iowin32.h"
	#endif
}

#if (defined(_WIN64)) && (!defined(__APPLE__))
        #ifndef __USE_FILE_OFFSET64
                #define __USE_FILE_OFFSET64
        #endif
        #ifndef __USE_LARGEFILE64
                #define __USE_LARGEFILE64
        #endif
        #ifndef _LARGEFILE64_SOURCE
                #define _LARGEFILE64_SOURCE
        #endif
        #ifndef _FILE_OFFSET_BIT
                #define _FILE_OFFSET_BIT 64
        #endif
#endif


/* calculate the CRC32 of a file,
   because to encrypt a file, we need known the CRC32 of the file before */

void getFileCrc(std::istream& input_stream, std::vector<char>& buff, unsigned long& result_crc)
{
    unsigned long calculate_crc=0;
    unsigned long size_read = 0;
    unsigned long total_read = 0;

    do {   
        input_stream.read(buff.data(), buff.size());
	    size_read = input_stream.gcount();

        if (size_read>0)
            calculate_crc = crc32(calculate_crc, (const unsigned char*)buff.data(), size_read);
		
        total_read += size_read;

    } while (size_read>0);

    input_stream.seekg(0);
    result_crc=calculate_crc;
}

bool isLargeFile(std::istream& input_stream)
{
    ZPOS64_T pos = 0;
    input_stream.seekg(0, std::ios::end);
    pos = input_stream.tellg();
	input_stream.seekg(0);
	
    return pos >= 0xffffffff;
}

namespace zipper {

	struct Zipper::Impl
	{
		Zipper& m_outer;
		zipFile m_zf;
		ourmemory_t m_zipmem = ourmemory_t();

		Impl(Zipper& outer) : m_outer(outer)
		{
			m_zf = NULL;
		}

		bool initFile(const std::string& filename)
		{
			int fileExists = 0;// chequear si existe el archivo!
			int mode = 0;
			int flags = Zipper::Overwrite;

			/* open the zip file for output */
			if (fileExists)
				mode = (flags & Zipper::Overwrite) ? APPEND_STATUS_CREATE : APPEND_STATUS_ADDINZIP;
			else
				mode = APPEND_STATUS_CREATE;

			m_zf = zipOpen64(filename.c_str(), mode);

			return m_zf != NULL;
		}

		bool initMemory()
		{
			zlib_filefunc64_def filefunc = { 0 };
			m_zipmem.grow = 1;

			//fill_memory_filefunc (&filefunc, &m_zipmem);
			fill_win32_filefunc64(&filefunc);

			m_zf = zipOpen3_64("__notused__", APPEND_STATUS_CREATE, 0, 0, &filefunc);

			return m_zf != NULL;
		}

		bool add(std::istream& input_stream, const std::string& nameInZip, const std::string& password, int flags)
		{
			if (!m_zf) return false;

{'fraction_non_alphanumeric': 0.12114918656974731, 'fraction_numerical': 0.0231914157147802, 'mean_word_length': 3.1816208393632417, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5855643', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2126, 'n_words': 484}