2006-10-28 19:45:02 +00:00
|
|
|
/*
|
|
|
|
* InBuffer.h
|
|
|
|
*
|
|
|
|
* This file is a part of LZMA compression module for NSIS.
|
|
|
|
*
|
|
|
|
* Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
|
2016-03-11 19:16:38 +00:00
|
|
|
* Modifications Copyright (C) 2003-2016 Amir Szekely <kichik@netvision.net.il>
|
2006-10-28 19:45:02 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Common Public License version 1.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty.
|
|
|
|
*/
|
2003-11-24 00:08:58 +00:00
|
|
|
|
|
|
|
#ifndef __INBUFFER_H
|
|
|
|
#define __INBUFFER_H
|
|
|
|
|
|
|
|
#include "../IStream.h"
|
2006-10-16 08:46:36 +00:00
|
|
|
#include "../../Common/MyCom.h"
|
2003-11-24 00:08:58 +00:00
|
|
|
|
2004-08-20 19:17:21 +00:00
|
|
|
#ifndef _NO_EXCEPTIONS
|
2003-11-24 00:08:58 +00:00
|
|
|
class CInBufferException
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HRESULT ErrorCode;
|
|
|
|
CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
|
|
|
|
};
|
2004-08-20 19:17:21 +00:00
|
|
|
#endif
|
2003-11-24 00:08:58 +00:00
|
|
|
|
|
|
|
class CInBuffer
|
|
|
|
{
|
2004-08-20 19:17:21 +00:00
|
|
|
Byte *_buffer;
|
|
|
|
Byte *_bufferLimit;
|
2006-10-16 08:46:36 +00:00
|
|
|
Byte *_bufferBase;
|
|
|
|
CMyComPtr<ISequentialInStream> _stream;
|
|
|
|
UInt64 _processedSize;
|
|
|
|
UInt32 _bufferSize;
|
2004-08-20 19:17:21 +00:00
|
|
|
bool _wasFinished;
|
2003-11-24 00:08:58 +00:00
|
|
|
|
|
|
|
bool ReadBlock();
|
2006-10-16 08:46:36 +00:00
|
|
|
Byte ReadBlock2();
|
2003-11-24 00:08:58 +00:00
|
|
|
|
|
|
|
public:
|
2004-08-20 19:17:21 +00:00
|
|
|
#ifdef _NO_EXCEPTIONS
|
|
|
|
HRESULT ErrorCode;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CInBuffer();
|
|
|
|
~CInBuffer() { Free(); }
|
|
|
|
|
|
|
|
bool Create(UInt32 bufferSize);
|
|
|
|
void Free();
|
2003-11-24 00:08:58 +00:00
|
|
|
|
2006-10-16 08:46:36 +00:00
|
|
|
void SetStream(ISequentialInStream *stream);
|
|
|
|
void Init();
|
|
|
|
void ReleaseStream() { _stream.Release(); }
|
2003-11-24 00:08:58 +00:00
|
|
|
|
2004-08-20 19:17:21 +00:00
|
|
|
bool ReadByte(Byte &b)
|
|
|
|
{
|
|
|
|
if(_buffer >= _bufferLimit)
|
|
|
|
if(!ReadBlock())
|
|
|
|
return false;
|
|
|
|
b = *_buffer++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Byte ReadByte()
|
|
|
|
{
|
|
|
|
if(_buffer >= _bufferLimit)
|
2006-10-16 08:46:36 +00:00
|
|
|
return ReadBlock2();
|
2004-08-20 19:17:21 +00:00
|
|
|
return *_buffer++;
|
|
|
|
}
|
|
|
|
void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
|
|
|
|
{
|
|
|
|
for(processedSize = 0; processedSize < size; processedSize++)
|
|
|
|
if (!ReadByte(((Byte *)data)[processedSize]))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool ReadBytes(void *data, UInt32 size)
|
|
|
|
{
|
|
|
|
UInt32 processedSize;
|
|
|
|
ReadBytes(data, size, processedSize);
|
|
|
|
return (processedSize == size);
|
|
|
|
}
|
|
|
|
UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }
|
|
|
|
bool WasFinished() const { return _wasFinished; }
|
2003-11-24 00:08:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|