88 lines
3.0 KiB
C++
88 lines
3.0 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: AuBaseStream.hpp
|
|
Date: 2022-2-14
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
#include "AuIngestableReadBase.hpp"
|
|
#include <Source/IO/Adapters/AuIOAdapterCompression.hpp>
|
|
|
|
namespace Aurora::Compression
|
|
{
|
|
struct BaseStream :
|
|
ICompressionStream,
|
|
protected IngestableReadBase
|
|
{
|
|
inline BaseStream(AuUInt32 bufferSize = 4096 * 64) :
|
|
_outbufferOwned(bufferSize, true),
|
|
uBufferSize_(bufferSize),
|
|
reader_(AuUnsafeRaiiToShared(this)),
|
|
reader2_(AuUnsafeRaiiToShared(this))
|
|
{
|
|
SetBuffer({});
|
|
}
|
|
|
|
inline virtual ~BaseStream()
|
|
{}
|
|
|
|
virtual bool Init(const AuSPtr<IO::IStreamReader> &reader) = 0;
|
|
|
|
virtual AuUInt32 GetAvailableProcessedBytes() override;
|
|
virtual AuStreamReadWrittenPair_t ReadEx(const AuMemoryViewWrite & /*opt*/ destination, bool bIngestUntilEOS) override;
|
|
virtual AuUInt32 Read(const AuMemoryViewWrite & /*opt*/ destination) override;
|
|
|
|
virtual bool GoBackByProcessedN(AuUInt32 dwOffset) override;
|
|
virtual bool GoForwardByProcessedN(AuUInt32 dwOffset) override;
|
|
|
|
virtual AuUInt32 GetInternalBufferSize() override;
|
|
|
|
virtual AuOptional<int> GetLastError() override;
|
|
virtual AuOptional<AuString> GetLastErrorString() override;
|
|
|
|
void SetLastError(int i, const AuString &str);
|
|
void SetLastError(int i);
|
|
|
|
bool Write(const void *pDest, AuUInt32 dwLength);
|
|
bool Write2(const void *pDest, AuUInt32 dwLength);
|
|
|
|
AuPair<char *, AuUInt32> GetDOutPair();
|
|
|
|
virtual AuStreamReadWrittenPair_t Ingest(AuUInt32 bytesFromUnprocessedInputSource) override;
|
|
|
|
virtual bool Flush() override;
|
|
virtual bool Finish() override;
|
|
|
|
virtual IO::IStreamReader *ToStreamReader() override;
|
|
virtual IO::ISeekingReader *ToSeekingStreamReader() override;
|
|
|
|
bool IsValid();
|
|
|
|
AuSPtr<Memory::ByteBuffer> GetBuffer();
|
|
void SetBuffer(const AuSPtr<Memory::ByteBuffer> &pBuffer);
|
|
|
|
AuSPtr<Memory::ByteBuffer> GetWeakBuffer();
|
|
void SetWeakBuffer(const AuSPtr<Memory::ByteBuffer> &pBuffer);
|
|
|
|
void InitByDesc(CompressInfo &info);
|
|
void InitByDesc(DecompressInfo &info);
|
|
|
|
protected:
|
|
virtual AuStreamReadWrittenPair_t Ingest_s(AuUInt32 dwBytesFromUnprocessedInputSource) = 0;
|
|
IO::Adapters::CompressionStreamReader reader_;
|
|
IO::Adapters::CompressionSeekingReader reader2_;
|
|
AuSPtr<Memory::ByteBuffer> pOutputBuffer_;
|
|
AuWPtr<Memory::ByteBuffer> wpInBuffer_;
|
|
AuSPtr<AuIO::IStreamWriter> pOutputBufferInterface_;
|
|
AuSPtr<Memory::ByteBuffer> pFallbackTempBuffer_;
|
|
Memory::ByteBuffer _outbufferOwned;
|
|
AuThreadPrimitives::SpinLock _spinlock;
|
|
AuUInt32 uBufferSize_;
|
|
AuOptional<int> optLastError_;
|
|
AuString optLastErrorString_;
|
|
};
|
|
}
|
|
|
|
#include "AuIngestableReadBase.inl" |