// CodeGear C++Builder
// Copyright (c) 1995, 2021 by Embarcadero Technologies, Inc.
// All rights reserved

// (DO NOT EDIT: machine generated header) 'ABSCompression.pas' rev: 35.00 (Windows)

#ifndef AbscompressionHPP
#define AbscompressionHPP

#pragma delphiheader begin
#pragma option push
#pragma option -w-      // All warnings off
#pragma option -Vx      // Zero-length empty class member 
#pragma pack(push,8)
#include <System.hpp>
#include <SysInit.hpp>
#include <System.SysUtils.hpp>
#include <System.Classes.hpp>
#include <Winapi.Windows.hpp>
#include <ABSTypes.hpp>
#include <ABSMemory.hpp>
#include <ABSConst.hpp>
#include <ABSExcept.hpp>
#include <ABSZlib.hpp>
#include <ABSBZip2.hpp>
#include <ABSPPM.hpp>

//-- user supplied -----------------------------------------------------------

namespace Abscompression
{
//-- forward type declarations -----------------------------------------------
struct TABSCompression;
class DELPHICLASS TABSStream;
class DELPHICLASS TABSMemoryStream;
class DELPHICLASS TABSFileStream;
class DELPHICLASS TABSTemporaryStream;
class DELPHICLASS TABSCompressedBLOBStream;
//-- type declarations -------------------------------------------------------
enum DECLSPEC_DENUM TABSCompressionAlgorithm : unsigned char { acaNone, acaZLIB, acaBZIP, acaPPM };

typedef System::StaticArray<System::UnicodeString, 4> Abscompression__1;

typedef System::Byte TABSCompressionMode;

enum DECLSPEC_DENUM TABSCompressionLevel : unsigned char { aclNone, aclFastest, aclNormal, aclMaximum };

#pragma pack(push,1)
struct DECLSPEC_DRECORD TABSCompression
{
public:
	TABSCompressionAlgorithm CompressionAlgorithm;
	System::Byte CompressionMode;
	TABSCompressionLevel CompressionLevel;
};
#pragma pack(pop)


typedef void __fastcall (__closure *TABSNoCancelProgressEvent)(System::TObject* Sender, double PercentDone);

class PASCALIMPLEMENTATION TABSStream : public System::Classes::TStream
{
	typedef System::Classes::TStream inherited;
	
private:
	_RTL_CRITICAL_SECTION FCSect;
	int FBlockSize;
	TABSNoCancelProgressEvent FOnProgress;
	bool FModified;
	
protected:
	void __fastcall DoOnProgress(double Progress);
	
public:
	virtual void __fastcall Lock();
	virtual void __fastcall Unlock();
	__fastcall TABSStream();
	void __fastcall SaveToStream(TABSStream* Stream);
	void __fastcall LoadFromStreamWithPosition(TABSStream* Stream, __int64 FromPosition, __int64 StreamSize);
	void __fastcall LoadFromStream(TABSStream* Stream);
	void __fastcall LoadFromFile(const System::UnicodeString FileName);
	void __fastcall SaveToFile(const System::UnicodeString FileName);
	__property int BlockSize = {read=FBlockSize, write=FBlockSize, nodefault};
	__property TABSNoCancelProgressEvent OnProgress = {read=FOnProgress, write=FOnProgress};
	__property bool Modified = {read=FModified, write=FModified, nodefault};
public:
	/* TObject.Destroy */ inline __fastcall virtual ~TABSStream() { }
	
};


class PASCALIMPLEMENTATION TABSMemoryStream : public TABSStream
{
	typedef TABSStream inherited;
	
private:
	System::Byte *FBuffer;
	int FBufferSize;
	int FAllocatedBufferSize;
	int FPosition;
	
protected:
	void __fastcall InternalSetSize(const __int64 NewSize);
	int __fastcall InternalSeek(int NewPosition);
	virtual void __fastcall SetSize(int NewSize)/* overload */;
	virtual void __fastcall SetSize(const __int64 NewSize)/* overload */;
	
public:
	virtual int __fastcall Read(void *Buffer, int Count)/* overload */;
	virtual int __fastcall Write(const void *Buffer, int Count)/* overload */;
	virtual int __fastcall Seek(int Offset, System::Word Origin)/* overload */;
	virtual __int64 __fastcall Seek(const __int64 Offset, System::Classes::TSeekOrigin Origin)/* overload */;
	__fastcall TABSMemoryStream(System::PByte Buffer, int DefaultAllocatedSize);
	__fastcall virtual ~TABSMemoryStream();
	__property System::PByte Buffer = {read=FBuffer};
	/* Hoisted overloads: */
	
public:
	inline int __fastcall  Read(System::DynamicArray<System::Byte> Buffer, int Offset, int Count){ return System::Classes::TStream::Read(Buffer, Offset, Count); }
	inline int __fastcall  Read(System::DynamicArray<System::Byte> &Buffer, int Count){ return System::Classes::TStream::Read(Buffer, Count); }
	inline int __fastcall  Write(const System::DynamicArray<System::Byte> Buffer, int Offset, int Count){ return System::Classes::TStream::Write(Buffer, Offset, Count); }
	inline int __fastcall  Write(const System::DynamicArray<System::Byte> Buffer, int Count){ return System::Classes::TStream::Write(Buffer, Count); }
	inline __int64 __fastcall  Seek(const __int64 Offset, System::Word Origin){ return System::Classes::TStream::Seek(Offset, Origin); }
	
};


class PASCALIMPLEMENTATION TABSFileStream : public TABSStream
{
	typedef TABSStream inherited;
	
private:
	int FHandle;
	System::UnicodeString FFileName;
	System::Word FMode;
	bool FIsTemporary;
	
protected:
	int __fastcall InternalFileCreate(const System::UnicodeString FileName);
	void __fastcall InternalSetSize(const __int64 NewSize);
	virtual void __fastcall SetSize(int NewSize)/* overload */;
	virtual void __fastcall SetSize(const __int64 NewSize)/* overload */;
	
public:
	virtual int __fastcall Read(void *Buffer, int Count)/* overload */;
	virtual int __fastcall Write(const void *Buffer, int Count)/* overload */;
	virtual int __fastcall Seek(int Offset, System::Word Origin)/* overload */;
	virtual __int64 __fastcall Seek(const __int64 Offset, System::Classes::TSeekOrigin Origin)/* overload */;
	__fastcall TABSFileStream(const System::UnicodeString FileName, System::Word Mode, bool IsTemporary);
	__fastcall virtual ~TABSFileStream();
	__property int Handle = {read=FHandle, nodefault};
	__property System::UnicodeString FileName = {read=FFileName};
	__property System::Word Mode = {read=FMode, nodefault};
	__property bool IsTemporary = {read=FIsTemporary, nodefault};
	/* Hoisted overloads: */
	
public:
	inline int __fastcall  Read(System::DynamicArray<System::Byte> Buffer, int Offset, int Count){ return System::Classes::TStream::Read(Buffer, Offset, Count); }
	inline int __fastcall  Read(System::DynamicArray<System::Byte> &Buffer, int Count){ return System::Classes::TStream::Read(Buffer, Count); }
	inline int __fastcall  Write(const System::DynamicArray<System::Byte> Buffer, int Offset, int Count){ return System::Classes::TStream::Write(Buffer, Offset, Count); }
	inline int __fastcall  Write(const System::DynamicArray<System::Byte> Buffer, int Count){ return System::Classes::TStream::Write(Buffer, Count); }
	inline __int64 __fastcall  Seek(const __int64 Offset, System::Word Origin){ return System::Classes::TStream::Seek(Offset, Origin); }
	
};


class PASCALIMPLEMENTATION TABSTemporaryStream : public TABSStream
{
	typedef TABSStream inherited;
	
private:
	int FMemoryLimit;
	TABSMemoryStream* FMemoryStream;
	TABSFileStream* FFileStream;
	System::UnicodeString FFileName;
	bool FInMemory;
	bool FDisableTempFiles;
	
protected:
	void __fastcall InternalSetSize(const __int64 NewSize);
	virtual void __fastcall SetSize(int NewSize)/* overload */;
	virtual void __fastcall SetSize(const __int64 NewSize)/* overload */;
	
public:
	virtual int __fastcall Read(void *Buffer, int Count)/* overload */;
	virtual int __fastcall Write(const void *Buffer, int Count)/* overload */;
	virtual int __fastcall Seek(int Offset, System::Word Origin)/* overload */;
	virtual __int64 __fastcall Seek(const __int64 Offset, System::Classes::TSeekOrigin Origin)/* overload */;
	__fastcall TABSTemporaryStream(bool DisableTempFiles);
	__fastcall virtual ~TABSTemporaryStream();
	__property TABSFileStream* FileStream = {read=FFileStream};
	__property TABSMemoryStream* MemoryStream = {read=FMemoryStream};
	__property System::UnicodeString FileName = {read=FFileName};
	__property bool InMemory = {read=FInMemory, nodefault};
	__property int MemoryLimit = {read=FMemoryLimit, write=FMemoryLimit, nodefault};
	/* Hoisted overloads: */
	
public:
	inline int __fastcall  Read(System::DynamicArray<System::Byte> Buffer, int Offset, int Count){ return System::Classes::TStream::Read(Buffer, Offset, Count); }
	inline int __fastcall  Read(System::DynamicArray<System::Byte> &Buffer, int Count){ return System::Classes::TStream::Read(Buffer, Count); }
	inline int __fastcall  Write(const System::DynamicArray<System::Byte> Buffer, int Offset, int Count){ return System::Classes::TStream::Write(Buffer, Offset, Count); }
	inline int __fastcall  Write(const System::DynamicArray<System::Byte> Buffer, int Count){ return System::Classes::TStream::Write(Buffer, Count); }
	inline __int64 __fastcall  Seek(const __int64 Offset, System::Word Origin){ return System::Classes::TStream::Seek(Offset, Origin); }
	
};


class PASCALIMPLEMENTATION TABSCompressedBLOBStream : public TABSStream
{
	typedef TABSStream inherited;
	
private:
	bool FRepair;
	Abstypes::TABSCompressedStreamBlockHeadersArray* FHeaders;
	__int64 FUncompressedSize;
	__int64 FCompressedSize;
	__int64 FStartPosition;
	int FCurrentHeader;
	__int64 FPosition;
	System::Byte FCompressionMode;
	TABSCompressionAlgorithm FCompressionAlgorithm;
	double FCompressionRate;
	System::Classes::TStream* FCompressedStream;
	Abstypes::TABSBLOBDescriptor FBLOBDescriptor;
	int __fastcall InternalGetBlockSize(System::Byte CompressionMode);
	void __fastcall CalculateRate();
	void __fastcall InternalCreate(bool ToCreate);
	void __fastcall LoadHeaders();
	void __fastcall PrepareBufferForWriting(System::PByte InBuf, int InSize, System::PByte &OutBuf, Abstypes::TABSCompressedStreamBlockHeader &Header);
	void __fastcall LoadBlock(__int64 CurHeader, System::PByte &OutBuf);
	void __fastcall InternalIncreaseSize(__int64 NewSize);
	void __fastcall InternalDecreaseSize(__int64 NewSize);
	void __fastcall InternalSetSize(__int64 NewSize);
	__int64 __fastcall InternalSeek(__int64 NewPosition);
	
protected:
	virtual void __fastcall SetSize(int NewSize)/* overload */;
	virtual void __fastcall SetSize(const __int64 NewSize)/* overload */;
	__int64 __fastcall GetCompressedSize();
	double __fastcall GetCompressionRate();
	
public:
	__fastcall TABSCompressedBLOBStream(System::Classes::TStream* Stream, const Abstypes::TABSBLOBDescriptor &BLOBDescriptor, bool ToCreate, bool ToRepair);
	__fastcall virtual ~TABSCompressedBLOBStream();
	virtual int __fastcall Read(void *Buffer, int Count)/* overload */;
	
private:
	void __fastcall InternalWriteBeyondEOF();
	void __fastcall InternalWriteBlock(System::PByte InBuf, int InSize);
	void __fastcall InternalWritePrepare(int Count, int Result);
	
public:
	virtual int __fastcall Write(const void *Buffer, int Count)/* overload */;
	virtual int __fastcall Seek(int Offset, System::Word Origin)/* overload */;
	virtual __int64 __fastcall Seek(const __int64 Offset, System::Classes::TSeekOrigin Origin)/* overload */;
	__property System::Classes::TStream* CompressedStream = {read=FCompressedStream};
	__property double CompressionRate = {read=GetCompressionRate};
	__property TABSCompressionAlgorithm CompressionAlgorithm = {read=FCompressionAlgorithm, nodefault};
	__property System::Byte CompressionMode = {read=FCompressionMode, nodefault};
	__property __int64 CompressedSize = {read=GetCompressedSize};
	__property Abstypes::TABSBLOBDescriptor BLOBDescriptor = {read=FBLOBDescriptor};
	/* Hoisted overloads: */
	
public:
	inline int __fastcall  Read(System::DynamicArray<System::Byte> Buffer, int Offset, int Count){ return System::Classes::TStream::Read(Buffer, Offset, Count); }
	inline int __fastcall  Read(System::DynamicArray<System::Byte> &Buffer, int Count){ return System::Classes::TStream::Read(Buffer, Count); }
	inline int __fastcall  Write(const System::DynamicArray<System::Byte> Buffer, int Offset, int Count){ return System::Classes::TStream::Write(Buffer, Offset, Count); }
	inline int __fastcall  Write(const System::DynamicArray<System::Byte> Buffer, int Count){ return System::Classes::TStream::Write(Buffer, Count); }
	inline __int64 __fastcall  Seek(const __int64 Offset, System::Word Origin){ return System::Classes::TStream::Seek(Offset, Origin); }
	
};


//-- var, const, procedure ---------------------------------------------------
extern DELPHI_PACKAGE Abscompression__1 ABSCompressionAlgorithmNames;
extern DELPHI_PACKAGE int DefaultTemporaryBlockSize;
extern DELPHI_PACKAGE int DefaultTemporaryLimit;
extern DELPHI_PACKAGE int DefaultMemoryBlockSize;
extern DELPHI_PACKAGE int DefaultFileBlockSize;
extern DELPHI_PACKAGE int DefaultBLOBBlockSize;
extern DELPHI_PACKAGE int BlockSizeForFastest;
extern DELPHI_PACKAGE int BlockSizeForNormal;
extern DELPHI_PACKAGE int BlockSizeForMax;
extern DELPHI_PACKAGE System::UnicodeString AsbCompressionLastError;
extern DELPHI_PACKAGE bool __fastcall ABSInternalCompressBuffer(TABSCompressionAlgorithm CompressionAlgorithm, System::Byte CompressionMode, System::PByte InBuf, int InSize, /* out */ System::PByte &OutBuf, /* out */ int &OutSize);
extern DELPHI_PACKAGE bool __fastcall ABSInternalDecompressBuffer(TABSCompressionAlgorithm CompressionAlgorithm, System::PByte InBuf, int InSize, /* out */ System::PByte &OutBuf, /* out */ int &OutSize);
extern DELPHI_PACKAGE unsigned __fastcall CRC32(unsigned CRC, void * Data, unsigned DataSize);
extern DELPHI_PACKAGE System::UnicodeString __fastcall GetTempFileName(void);
extern DELPHI_PACKAGE void __fastcall SaveDataToStream(void *Data, int DataSize, System::Classes::TStream* Stream, int ErrorCode);
extern DELPHI_PACKAGE void __fastcall LoadDataFromStream(void *Data, int DataSize, System::Classes::TStream* Stream, int ErrorCode);
extern DELPHI_PACKAGE void __fastcall SetStreamPosition(System::Classes::TStream* Stream, __int64 NewPosition, int ErrorCode);
extern DELPHI_PACKAGE TABSCompressionAlgorithm __fastcall GetCompressionAlgorithm(System::UnicodeString Name);
extern DELPHI_PACKAGE System::UnicodeString __fastcall ABSCompressionGetLastError(void);
}	/* namespace Abscompression */
#if !defined(DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE) && !defined(NO_USING_NAMESPACE_ABSCOMPRESSION)
using namespace Abscompression;
#endif
#pragma pack(pop)
#pragma option pop

#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif	// AbscompressionHPP
