<commit_before>
// GZipFile.cpp

// Implements the cGZipFile class representing a RAII wrapper over zlib's GZip file routines

#include "Globals.h"
#include "GZipFile.h"





cGZipFile::cGZipFile(void) :
	m_File(NULL)
{
}





cGZipFile::~cGZipFile()
{
	Close();
}





bool cGZipFile::Open(const AString & a_FileName, eMode a_Mode)
{
	if (m_File != NULL)
	{
		ASSERT(!"A file is already open in this object");
		return false;
	}
	m_File = gzopen(a_FileName.c_str(), (a_Mode == fmRead) ? "r" : "w");
	m_Mode = a_Mode;
	return (m_File != NULL);
}





void cGZipFile::Close(void)
{
	if (m_File != NULL)
	{
		gzclose(m_File);
		m_File = NULL;
	}
}





int cGZipFile::ReadRestOfFile(AString & a_Contents)
{
	if (m_File == NULL)
	{
		ASSERT(!"No file has been opened");
		return -1;
	}
	
	if (m_Mode != fmRead)
	{
		ASSERT(!"Bad file mode, cannot read");
		return -1;
	}
	
	// Since the gzip format doesn't really support getting the uncompressed length, we need to read incrementally. Yuck!
	int NumBytesRead = 0;
	char Buffer[64 KiB];
	while ((NumBytesRead = gzread(m_File, Buffer, sizeof(Buffer))) > 0)
	{
		a_Contents.append(Buffer, NumBytesRead);
	}
	return NumBytesRead;
}
<commit_msg>Fixed cGZipFile::ReadRestOfFile returning incorrect value.<commit_after>
// GZipFile.cpp

// Implements the cGZipFile class representing a RAII wrapper over zlib's GZip file routines

#include "Globals.h"
#include "GZipFile.h"





cGZipFile::cGZipFile(void) :
	m_File(NULL)
{
}





cGZipFile::~cGZipFile()
{
	Close();
}





bool cGZipFile::Open(const AString & a_FileName, eMode a_Mode)
{
	if (m_File != NULL)
	{
		ASSERT(!"A file is already open in this object");
		return false;
	}
	m_File = gzopen(a_FileName.c_str(), (a_Mode == fmRead) ? "r" : "w");
	m_Mode = a_Mode;
	return (m_File != NULL);
}





void cGZipFile::Close(void)
{
	if (m_File != NULL)
	{
		gzclose(m_File);
		m_File = NULL;
	}
}





int cGZipFile::ReadRestOfFile(AString & a_Contents)
{
	if (m_File == NULL)
	{
		ASSERT(!"No file has been opened");
		return -1;
	}
	
	if (m_Mode != fmRead)
	{
		ASSERT(!"Bad file mode, cannot read");
		return -1;
	}
	
	// Since the gzip format doesn't really support getting the uncompressed length, we need to read incrementally. Yuck!
	int NumBytesRead = 0;
	int TotalBytes = 0;
	char Buffer[64 KiB];
	while ((NumBytesRead = gzread(m_File, Buffer, sizeof(Buffer))) > 0)
	{
		TotalBytes += NumBytesRead;
		a_Contents.append(Buffer, NumBytesRead);
	}
	// NumBytesRead is < 0 on error
	return (NumBytesRead >= 0) ? TotalBytes : NumBytesRead;
}

{'fraction_non_alphanumeric': 0.1374015748031496, 'fraction_numerical': 0.005905511811023622, 'mean_word_length': 3.8865384615384615, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '7456730', 'n_tokens_mistral': 1093, 'n_tokens_neox': 981, 'n_words': 253}