comptest.cpp

来自「壓縮程式, VC++ 原始碼及Demo 程式集」· C++ 代码 · 共 60 行

CPP
60
字号
// comptest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "comptest.h"
#include "flate.h"
#include "ByteArrayStream.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	CByteArray ba;
	{
		CFile file;
		VERIFY ( file.Open(_T("flate.cpp"), CFile::modeRead) != FALSE );

		ba.SetSize(file.GetLength());
		file.Read(ba.GetData(), ba.GetSize());
	}

	CByteArray comp;
	CByteArray uncomp;

	Flate compressor;
	{
		CBAStreamReader sr(ba.GetData(), ba.GetSize());
		CBAStreamWriter sw(comp);

		compressor.Deflate(&sw, &sr);
	}

	VERIFY( ba.GetSize() > comp.GetSize() );

	{
		CBAStreamReader sr(comp.GetData(), comp.GetSize());
		CBAStreamWriter sw(uncomp);

		compressor.Inflate(&sw, &sr);
	}
	VERIFY( uncomp.GetSize() > comp.GetSize() );

	VERIFY( memcmp(ba.GetData(), uncomp.GetData(), uncomp.GetSize()) == 0 );

	return 0;
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?