mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-14 02:11:40 -06:00
3.13
This commit is contained in:
66
7zip/Common/InBuffer.h
Executable file
66
7zip/Common/InBuffer.h
Executable file
@@ -0,0 +1,66 @@
|
||||
// InBuffer.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __INBUFFER_H
|
||||
#define __INBUFFER_H
|
||||
|
||||
#include "../IStream.h"
|
||||
|
||||
class CInBufferException
|
||||
{
|
||||
public:
|
||||
HRESULT ErrorCode;
|
||||
CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
|
||||
};
|
||||
|
||||
class CInBuffer
|
||||
{
|
||||
UINT64 _processedSize;
|
||||
BYTE *_bufferBase;
|
||||
UINT32 _bufferSize;
|
||||
BYTE *_buffer;
|
||||
BYTE *_bufferLimit;
|
||||
ISequentialInStream *_stream;
|
||||
bool _streamWasExhausted;
|
||||
|
||||
bool ReadBlock();
|
||||
|
||||
public:
|
||||
CInBuffer(UINT32 bufferSize = 0x100000);
|
||||
~CInBuffer();
|
||||
|
||||
void Init(ISequentialInStream *stream);
|
||||
// void ReleaseStream() { _stream.Release(); }
|
||||
|
||||
bool ReadByte(BYTE &b)
|
||||
{
|
||||
if(_buffer >= _bufferLimit)
|
||||
if(!ReadBlock())
|
||||
return false;
|
||||
b = *_buffer++;
|
||||
return true;
|
||||
}
|
||||
BYTE ReadByte()
|
||||
{
|
||||
if(_buffer >= _bufferLimit)
|
||||
if(!ReadBlock())
|
||||
return 0x0;
|
||||
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); }
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user