mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-09-02 16:22:40 -06:00
plugin/zstd: simple functions
git-svn-id: svn://ultimatepp.org/upp/trunk@10113 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
b54282bdb6
commit
2d1901317a
6 changed files with 223 additions and 45 deletions
107
uppsrc/plugin/zstd/Util.cpp
Normal file
107
uppsrc/plugin/zstd/Util.cpp
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
#include "zstd.h"
|
||||
|
||||
namespace Upp {
|
||||
|
||||
void sCompressStreamCopy_(Stream& out, Stream& in, Function<bool(int64, int64)> progress, Stream& orig_in, int64 insz);
|
||||
|
||||
static int64 sZstdCompress(Stream& out, Stream& in, int64 size, Function<bool(int64, int64)> progress, bool co)
|
||||
{
|
||||
ZstdCompressStream outs(out);
|
||||
#ifdef _MULTITHREADED
|
||||
if(co)
|
||||
outs.Concurrent();
|
||||
#endif
|
||||
sCompressStreamCopy_(outs, in, progress, in, size);
|
||||
outs.Close();
|
||||
if(!out.IsError() && !outs.IsError())
|
||||
return out.GetSize();
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int64 sZstdDecompress(Stream& out, Stream& in, int64 size, Function<bool(int64, int64)> progress, bool co)
|
||||
{
|
||||
ZstdDecompressStream ins(in);
|
||||
#ifdef _MULTITHREADED
|
||||
if(co)
|
||||
ins.Concurrent();
|
||||
#endif
|
||||
sCompressStreamCopy_(out, ins, progress, in, size);
|
||||
ins.Close();
|
||||
if(!out.IsError() && !ins.IsError())
|
||||
return out.GetSize();
|
||||
return -1;
|
||||
}
|
||||
|
||||
int64 ZstdCompress(Stream& out, Stream& in, Function<bool(int64, int64)> progress)
|
||||
{
|
||||
return sZstdCompress(out, in, in.GetLeft(), progress, false);
|
||||
}
|
||||
|
||||
int64 ZstdDecompress(Stream& out, Stream& in, Function<bool(int64, int64)> progress)
|
||||
{
|
||||
return sZstdDecompress(out, in, in.GetLeft(), progress, false);
|
||||
}
|
||||
|
||||
String ZstdCompress(const void *data, int64 len, Function<bool(int64, int64)> progress)
|
||||
{
|
||||
StringStream out;
|
||||
MemReadStream in(data, len);
|
||||
return ZstdCompress(out, in, progress) < 0 ? String::GetVoid() : out.GetResult();
|
||||
}
|
||||
|
||||
String ZstdCompress(const String& s, Function<bool(int64, int64)> progress)
|
||||
{
|
||||
return ZstdCompress(~s, s.GetLength(), progress);
|
||||
}
|
||||
|
||||
String ZstdDecompress(const void *data, int64 len, Function<bool(int64, int64)> progress)
|
||||
{
|
||||
StringStream out;
|
||||
MemReadStream in(data, len);
|
||||
return ZstdDecompress(out, in, progress) < 0 ? String::GetVoid() : out.GetResult();
|
||||
}
|
||||
|
||||
String ZstdDecompress(const String& s, Function<bool(int64, int64)> progress)
|
||||
{
|
||||
return ZstdDecompress(~s, s.GetLength(), progress);
|
||||
}
|
||||
|
||||
#ifdef _MULTITHREADED
|
||||
|
||||
int64 CoZstdCompress(Stream& out, Stream& in, Function<bool(int64, int64)> progress)
|
||||
{
|
||||
return sZstdCompress(out, in, in.GetLeft(), progress, true);
|
||||
}
|
||||
|
||||
int64 CoZstdDecompress(Stream& out, Stream& in, Function<bool(int64, int64)> progress)
|
||||
{
|
||||
return sZstdDecompress(out, in, in.GetLeft(), progress, true);
|
||||
}
|
||||
|
||||
String CoZstdCompress(const void *data, int64 len, Function<bool(int64, int64)> progress)
|
||||
{
|
||||
StringStream out;
|
||||
MemReadStream in(data, len);
|
||||
return CoZstdCompress(out, in, progress) < 0 ? String::GetVoid() : out.GetResult();
|
||||
}
|
||||
|
||||
String CoZstdCompress(const String& s, Function<bool(int64, int64)> progress)
|
||||
{
|
||||
return CoZstdCompress(~s, s.GetLength(), progress);
|
||||
}
|
||||
|
||||
String CoZstdDecompress(const void *data, int64 len, Function<bool(int64, int64)> progress)
|
||||
{
|
||||
StringStream out;
|
||||
MemReadStream in(data, len);
|
||||
return CoZstdDecompress(out, in, progress) < 0 ? String::GetVoid() : out.GetResult();
|
||||
}
|
||||
|
||||
String CoZstdDecompress(const String& s, Function<bool(int64, int64)> progress)
|
||||
{
|
||||
return CoZstdDecompress(~s, s.GetLength(), progress);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue