[+] ByteBuffer::WriteFromEx

[+] ByteBuffer::WriteFrom
[*] Fix known path resolution quirks and missing compression staged change
[+] ICompressionInterceptor::LimitHasHit
[+] ICompressionInterceptor::LimitReset
[+] ICompressionInterceptor::LimitSet
[+] ICompressionInterceptor::LimitGetIndex
This commit is contained in:
Reece Wilson 2022-11-07 22:46:35 +00:00
parent 07fd9f19f8
commit 745b9f974a
7 changed files with 120 additions and 15 deletions

View File

@ -14,6 +14,13 @@ namespace Aurora::Compression
struct ICompressionInterceptor : IO::Protocol::IProtocolInterceptorEx
{
virtual bool HasFailed() = 0;
// TODO (Reece): interface potential
virtual bool LimitHasHit() = 0;
virtual void LimitReset() = 0;
virtual void LimitSet(AuUInt uLength) = 0;
virtual AuUInt LimitGetIndex() = 0;
};
AUKN_SYM AuSPtr<ICompressionInterceptor> NewDecompressionInterceptor(const DecompressInfo &info);

View File

@ -433,7 +433,9 @@ namespace Aurora::Memory
inline bool ReadString(AuString &string, EStringType type = EStringType::eStringDword, Locale::ECodePage codepage = Locale::ECodePage::eUTF8);
// Copy, concat, etc
inline bool WriteFrom(ByteBuffer &buffer, AuUInt length);
inline AuUInt WriteFromEx(ByteBuffer &buffer,
AuUInt uLength);
inline bool WriteFrom(ByteBuffer &buffer);
// Utilities
inline bool Trim(AuUInt tail);

View File

@ -2,15 +2,42 @@
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ByteBuffer_WriteFrom.inl
Date: 2022-2-15
Date: 2022-11-07
Author: Reece
***/
#pragma once
namespace Aurora::Memory
{
bool ByteBuffer::WriteFrom(ByteBuffer &buffer, AuUInt length)
AuUInt ByteBuffer::WriteFromEx(ByteBuffer &buffer,
AuUInt uLength)
{
return {};
AuUInt uTotal {};
bool bSuccess {};
do
{
auto readView = buffer.GetNextLinearRead();
auto writeView = this->GetNextLinearWrite();
auto uMax = AuMin(readView.length, writeView.length);
uMax = AuMin(uTotal + uMax, uLength);
AuMemcpy(writeView.ptr, readView.ptr, uMax);
this->writePtr += uMax;
buffer.readPtr += uMax;
uTotal += uTotal;
bSuccess = uMax;
}
while (bSuccess);
return uTotal;
}
bool ByteBuffer::WriteFrom(ByteBuffer &buffer)
{
auto readable = buffer.RemainingBytes();
return this->WriteFromEx(buffer, readable) == readable;
}
}

View File

@ -31,13 +31,12 @@ namespace Aurora::Compression
IO::EStreamError CompressionInterceptor::Read(const Memory::MemoryViewStreamWrite &parameters)
{
//if (auto pBuffer = this->pLastBuffer_.lock())
{
parameters.outVariable = pLastBuffer_->Read(parameters.ptr, parameters.length);
return parameters.outVariable == 0 ? IO::EStreamError::eErrorEndOfStream : IO::EStreamError::eErrorNone;
}
auto uRemainingBytes = AuMin(this->uCount_ + parameters.length,
this->uCountMax_);
return IO::EStreamError::eErrorStreamNotOpen;
parameters.outVariable = pLastBuffer_->Read(parameters.ptr, uRemainingBytes);
this->uCount_ += parameters.outVariable;
return parameters.outVariable == 0 ? IO::EStreamError::eErrorEndOfStream : IO::EStreamError::eErrorNone;
}
void CompressionInterceptor::Close()
@ -69,6 +68,11 @@ namespace Aurora::Compression
}
while (bSuccess);
if (this->LimitHasHit())
{
return pWriteOutByteBuffer->WriteFromEx(*pReadInByteBuffer, AuNumericLimits<AuUInt>::max()); // intentionally non-ex.
}
if (!bSuccess)
{
this->bErrorFlag_ = true;
@ -77,7 +81,28 @@ namespace Aurora::Compression
this->pBaseStream_->SetBuffer({});
return true;
}
bool CompressionInterceptor::LimitHasHit()
{
return this->uCount_ >= this->uCountMax_;
}
void CompressionInterceptor::LimitReset()
{
this->uCount_ = 0;
this->uCountMax_ = 0;
}
AuUInt CompressionInterceptor::LimitGetIndex()
{
return this->uCount_;
}
void CompressionInterceptor::LimitSet(AuUInt uLength)
{
this->uCountMax_ = uLength;
}
AUKN_SYM AuSPtr<ICompressionInterceptor> NewDecompressionInterceptor(const DecompressInfo &info)
{
auto pInterceptor = AuMakeShared<CompressionInterceptor>();
@ -117,7 +142,7 @@ namespace Aurora::Compression
SysPushErrorMemory();
return {};
}
pInterceptor->Init(pCompressor,
AuStaticCast<Compression::BaseStream>(pCompressor));

View File

@ -27,6 +27,11 @@ namespace Aurora::Compression
inline virtual void Close() override;
bool LimitHasHit() override;
void LimitReset() override;
void LimitSet(AuUInt uLength) override;
AuUInt LimitGetIndex() override;
bool HasFailed() override;
private:
@ -34,5 +39,7 @@ namespace Aurora::Compression
AuSPtr<ICompressionStream> pStream_;
AuSPtr<BaseStream> pBaseStream_;
AuSPtr<Memory::ByteBuffer> pLastBuffer_;
AuUInt uCountMax_ { AuNumericLimits<AuUInt>::max() };
AuUInt uCount_ {};
};
}

View File

@ -211,8 +211,8 @@ namespace Aurora::Compression
AuSPtr<IO::IStreamReader> pReader_;
ZSTD_CCtx *cctx_ {};
char din_[ZSTD_BLOCKSIZE_MAX + 3];
char dout_[ZSTD_BLOCKSIZE_MAX /*ZSTD_BLOCKHEADERSIZE*/];
char din_[ZSTD_BLOCKSIZE_MAX];
char dout_[ZSTD_COMPRESSBOUND(ZSTD_BLOCKSIZE_MAX) + 3 +/*ZSTD_BLOCKHEADERSIZE*/ + 4 /*32bit hash*/];
char *pIterator_ {};
AuUInt32 uAvailableIn_ {};
ZSTD_inBuffer input_ {};

View File

@ -110,7 +110,7 @@ namespace Aurora::IO::FS
{
if (ch == "..")
{
auto i = result.size() - 1;
auto i = result.size() - 1 - (result[result.size() - 1] == kPathSplitter);
while (i >= 0 && result[i] != kPathSplitter)
{
--i;
@ -119,6 +119,7 @@ namespace Aurora::IO::FS
if (i >= 0)
{
result.resize(i);
result += kPathSplitter;
}
continue;
@ -164,6 +165,42 @@ namespace Aurora::IO::FS
bool requiresMountUpdate = false;
requiresExpanding = str.size() && IsMagicCharacter(str[0]);
if (str.size() == 1)
{
if (str[0] == '.'
// Win32 has no concept of a rootfs
// However, all users expect paths in userspace programs to assume CWD
// Since we are not on a NIX operating system, we can assume these mean CWD
#if defined(AURORA_IS_MODERNNT_DERIVED)
||
str[0] == '/' ||
str[1] == '\\'
#endif
)
{
AuProcess::GetWorkingDirectory(str);
return;
}
if (str[0] == '^')
{
AuProcess::GetProcDirectory(str);
return;
}
if (str[0] == '~')
{
AuFS::GetProfileDomain(str);
return;
}
if (str[0] == '!')
{
AuFS::GetSystemDomain(str);
return;
}
}
// best case -> O(n) wherein we merely check each BYTE with a handful of branch conditions
int doubleDots = 0;