mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-14 04:11:37 -06:00
63 lines
1.1 KiB
C++
Executable File
63 lines
1.1 KiB
C++
Executable File
// OutBuffer.h
|
|
|
|
// #pragma once
|
|
|
|
#ifndef __OUTBUFFER_H
|
|
#define __OUTBUFFER_H
|
|
|
|
#include "../IStream.h"
|
|
|
|
class COutBufferException
|
|
{
|
|
public:
|
|
HRESULT ErrorCode;
|
|
COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
|
|
};
|
|
|
|
class COutBuffer
|
|
{
|
|
BYTE *_buffer;
|
|
UINT32 _pos;
|
|
UINT32 _bufferSize;
|
|
ISequentialOutStream *_stream;
|
|
UINT64 _processedSize;
|
|
|
|
void WriteBlock();
|
|
public:
|
|
COutBuffer(UINT32 bufferSize = (1 << 20));
|
|
~COutBuffer();
|
|
|
|
void Init(ISequentialOutStream *stream);
|
|
HRESULT Flush();
|
|
// void ReleaseStream();
|
|
|
|
void *GetBuffer(UINT32 &sizeAvail)
|
|
{
|
|
sizeAvail = _bufferSize - _pos;
|
|
return _buffer + _pos;
|
|
}
|
|
void MovePos(UINT32 num)
|
|
{
|
|
_pos += num;
|
|
if(_pos >= _bufferSize)
|
|
WriteBlock();
|
|
}
|
|
|
|
|
|
void WriteByte(BYTE b)
|
|
{
|
|
_buffer[_pos++] = b;
|
|
if(_pos >= _bufferSize)
|
|
WriteBlock();
|
|
}
|
|
void WriteBytes(const void *data, UINT32 size)
|
|
{
|
|
for (UINT32 i = 0; i < size; i++)
|
|
WriteByte(((const BYTE *)data)[i]);
|
|
}
|
|
|
|
UINT64 GetProcessedSize() const { return _processedSize + _pos; }
|
|
};
|
|
|
|
#endif
|