J Reece Wilson
fd0c5b51b2
[+] Begin work on IO futexes for io release on process/thread exit [+] Linux ::readdir iteration [+] AuConsole buffering API [*] Fix sleep as to not get interrupted by signals [*] Switch the type of FS lock used under Linux [*] Linux: Use new IPCHandle encoding scheme [*] Fix undefined behaviour: unintialized timeout values (AuLoop/Linux) [*] Fix undefined behaviour: ConsoleTTY clear line was called of a color of a random value on stack [-] Remainings of std dir iterator [*] Fix pthread_kill (aka send signal to pthread handle) always kills process. This is what you expect bc signal handler inheritance. [*] Reformat the build Aurora.json file [+] Added clang warning ignores to the build file [*] Fix: UNIX need to use STDOUT_FILENO. Was using CRT handle in place of fd by mistake. [+] Linux implementation for IO yield (AuIO::IOYield() - UNIX::LinuxOverlappedYield()) [*] Fix: Linux async end of stream processing. res 0 = zero bytes consumed. <= was detecting this as an error of code 0. Should succeed with zero bytes. [+] Linux LoopQueue missing epilogue hook for the IO processor [*] Various refactors and minor bug fixes [*] Linux fix: Handle pipe EOS as zero [*] Linux fix: thread termination via a user signal of 77. Need a force terminate. [*] IPC handle: fix improper int to bool cast in the header setup within ToString [*] Linux fix: HWInfo CPU topology regression [-] Linux fix: remove SIGABRT handler [*] Missing override in compression, exit, and consoletty headers. [+] Unix Syslog logger backend
124 lines
3.4 KiB
C++
124 lines
3.4 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: LZ4Decompressor.hpp
|
|
Date: 2022-2-15
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
#include "lz4.h"
|
|
#include "lz4frame.h"
|
|
|
|
namespace Aurora::Compression
|
|
{
|
|
class LZ4Inflate : public BaseStream
|
|
{
|
|
AuSPtr<char> bufferIn_;
|
|
AuSPtr<char> bufferOut_;
|
|
char *readPtr_;
|
|
AuUInt32 bufferInAvail {};
|
|
|
|
public:
|
|
|
|
DecompressInfo meta;
|
|
|
|
LZ4Inflate(const DecompressInfo &meta) : meta(meta), BaseStream(meta.internalStreamSize)
|
|
{}
|
|
|
|
~LZ4Inflate()
|
|
{
|
|
if (this->lz4Stream_)
|
|
{
|
|
LZ4F_freeDecompressionContext(this->lz4Stream_);
|
|
}
|
|
}
|
|
|
|
bool Init(const AuSPtr<IO::IStreamReader> &reader) override
|
|
{
|
|
this->reader_ = reader;
|
|
|
|
auto err = LZ4F_createDecompressionContext(&this->lz4Stream_, LZ4F_getVersion());
|
|
if (LZ4F_isError(err))
|
|
{
|
|
return {};
|
|
}
|
|
|
|
auto bufferSize = meta.internalStreamSize;
|
|
|
|
this->bufferIn_ = AuSPtr<char>(new char[bufferSize], AuDefaultDeleter<char[]>());
|
|
|
|
if (!this->bufferIn_)
|
|
{
|
|
return {};
|
|
}
|
|
|
|
this->bufferOut_ = AuSPtr<char>(new char[bufferSize], AuDefaultDeleter<char[]>());
|
|
if (!this->bufferOut_)
|
|
{
|
|
return {};
|
|
}
|
|
|
|
this->readPtr_ = this->bufferIn_.get();
|
|
SetPointer(this->readPtr_, bufferSize);
|
|
return true;
|
|
}
|
|
|
|
AuStreamReadWrittenPair_t Ingest_s(AuUInt32 input) override
|
|
{
|
|
bool ret = true;
|
|
AuUInt32 inputStat = 0, outputStat = 0;
|
|
size_t bytesRemInFrame {};
|
|
LZ4F_decompressOptions_t opts {};
|
|
|
|
auto bufferSize = meta.internalStreamSize;
|
|
|
|
while (inputStat < input)
|
|
{
|
|
inputStat += IngestForInPointer<char, uInt>(this->reader_, this->readPtr_, this->bufferInAvail, input - inputStat);
|
|
|
|
if (!this->bufferInAvail)
|
|
{
|
|
return {inputStat, outputStat};
|
|
}
|
|
|
|
auto frameSize = bytesRemInFrame ? bytesRemInFrame : LZ4F_MIN_SIZE_TO_KNOW_HEADER_LENGTH;
|
|
frameSize = LZ4F_MIN_SIZE_TO_KNOW_HEADER_LENGTH;
|
|
|
|
if (this->bufferInAvail < frameSize)
|
|
{
|
|
return {inputStat, outputStat};
|
|
}
|
|
|
|
size_t frameSPtr = this->bufferInAvail;
|
|
size_t frameS2Ptr = bufferSize;
|
|
|
|
bytesRemInFrame = LZ4F_decompress(this->lz4Stream_, this->bufferOut_.get(), &frameS2Ptr, this->readPtr_, &frameSPtr, &opts);
|
|
if (LZ4F_isError(bytesRemInFrame))
|
|
{
|
|
return {};
|
|
}
|
|
|
|
this->readPtr_ += frameSPtr;
|
|
outputStat += bytesRemInFrame;
|
|
this->bufferInAvail -= frameSPtr;
|
|
|
|
if (frameS2Ptr)
|
|
{
|
|
if (!Write(this->bufferOut_.get(), frameS2Ptr))
|
|
{
|
|
return {};
|
|
}
|
|
}
|
|
|
|
inputStat += frameS2Ptr;
|
|
}
|
|
|
|
return AuMakePair(inputStat, outputStat);
|
|
}
|
|
|
|
private:
|
|
AuSPtr<IO::IStreamReader> reader_;
|
|
LZ4F_dctx* lz4Stream_ {};
|
|
};
|
|
} |