From 7dd961d70c075adfb794ec2eedabda1d5893692e Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 1 May 2017 09:26:27 +0000 Subject: [PATCH] BRC now support LZ4, LZMA and Zstd compression git-svn-id: svn://ultimatepp.org/upp/trunk@11043 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/ide/Core/BinObj.cpp | 17 ++++ uppsrc/ide/Core/Core.cpp | 10 +- uppsrc/ide/Core/Core.h | 10 +- uppsrc/ide/Core/Core.upp | 3 +- uppsrc/ide/ide.upp | 3 +- uppsrc/plugin/bz2/bz2.h | 12 ++- uppsrc/plugin/bz2/bz2upp.cpp | 124 +++++++----------------- uppsrc/plugin/lz4/lz4.h | 4 + uppsrc/plugin/lz4/src.tpp/Lz4$en-us.tpp | 86 +++++++++------- uppsrc/plugin/lz4/util.cpp | 30 +++++- 10 files changed, 156 insertions(+), 143 deletions(-) diff --git a/uppsrc/ide/Core/BinObj.cpp b/uppsrc/ide/Core/BinObj.cpp index 2fe2a4a7b..e61d4a938 100644 --- a/uppsrc/ide/Core/BinObj.cpp +++ b/uppsrc/ide/Core/BinObj.cpp @@ -4,6 +4,17 @@ BinObjInfo::BinObjInfo() { } +void BinObjInfo::Block::Compress(String& data) +{ + switch(encoding) { + case BinObjInfo::Block::ENC_BZ2: data = BZ2Compress(data); break; + case BinObjInfo::Block::ENC_ZIP: data = ZCompress(data); break; + case BinObjInfo::Block::ENC_LZ4: data = LZ4Compress(data); break; + case BinObjInfo::Block::ENC_LZMA: data = LZMACompress(data); break; + case BinObjInfo::Block::ENC_ZSTD: data = ZstdCompress(data); break; + } +} + void BinObjInfo::Parse(CParser& binscript, String base_dir) { while(!binscript.IsEof()) { @@ -34,6 +45,12 @@ void BinObjInfo::Parse(CParser& binscript, String base_dir) blk.encoding = Block::ENC_ZIP; else if(binscript.Id("BZ2")) blk.encoding = Block::ENC_BZ2; + else if(binscript.Id("LZ4")) + blk.encoding = Block::ENC_LZ4; + else if(binscript.Id("LZMA")) + blk.encoding = Block::ENC_LZMA; + else if(binscript.Id("ZSTD")) + blk.encoding = Block::ENC_ZSTD; binscript.PassChar(')'); FindFile ff; String searchpath = NormalizePath(file, base_dir); diff --git a/uppsrc/ide/Core/Core.cpp b/uppsrc/ide/Core/Core.cpp index c6a685004..f1ffb2742 100644 --- a/uppsrc/ide/Core/Core.cpp +++ b/uppsrc/ide/Core/Core.cpp @@ -462,10 +462,7 @@ String BrcToC(CParser& binscript, String basedir) if(data.GetLength() != b.length) throw Exc(NFormat("length of file '%s' changed (%d -> %d) during object creation", b.file, b.length, data.GetLength())); - switch(b.encoding) { - case BinObjInfo::Block::ENC_BZ2: data = BZ2Compress(data); break; - case BinObjInfo::Block::ENC_ZIP: data = ZCompress(data); break; - } + b.Compress(data); b.length = data.GetLength(); data.Cat('\0'); WriteByteArray(fo, data); @@ -501,10 +498,7 @@ String BrcToC(CParser& binscript, String basedir) if(data.GetLength() != b.length) throw Exc(NFormat("length of file '%s' changed (%d -> %d) during object creation", b.file, b.length, data.GetLength())); - switch(b.encoding) { - case BinObjInfo::Block::ENC_BZ2: data = BZ2Compress(data); break; - case BinObjInfo::Block::ENC_ZIP: data = ZCompress(data); break; - } + b.Compress(data); int b_length = data.GetLength(); data.Cat('\0'); WriteByteArray(fo, data); diff --git a/uppsrc/ide/Core/Core.h b/uppsrc/ide/Core/Core.h index 93c509837..a87dcc931 100644 --- a/uppsrc/ide/Core/Core.h +++ b/uppsrc/ide/Core/Core.h @@ -2,9 +2,10 @@ #define COMMON_H #include -// #include -//#include #include +#include +#include +#include #include "Logger.h" @@ -506,6 +507,9 @@ public: ENC_PLAIN, ENC_ZIP, ENC_BZ2, + ENC_LZ4, + ENC_LZMA, + ENC_ZSTD, }; int flags; enum { @@ -516,6 +520,8 @@ public: int offset; int off_meta_offset; int len_meta_offset; + + void Compress(String& data); }; VectorMap< String, ArrayMap > blocks; diff --git a/uppsrc/ide/Core/Core.upp b/uppsrc/ide/Core/Core.upp index aeec58de3..7b19a2cdf 100644 --- a/uppsrc/ide/Core/Core.upp +++ b/uppsrc/ide/Core/Core.upp @@ -2,7 +2,8 @@ description "TheIDE - common library\377B"; uses Esc, - plugin/bz2; + plugin/bz2, + plugin/lzma; file Core.h options(BUILDER_OPTION) PCH, diff --git a/uppsrc/ide/ide.upp b/uppsrc/ide/ide.upp index fdaddd4d9..067017220 100644 --- a/uppsrc/ide/ide.upp +++ b/uppsrc/ide/ide.upp @@ -19,7 +19,8 @@ uses TabBar, ide/Designers, ide/Android, - ide/Java; + ide/Java, + plugin/zstd; uses(POSIX) ide\SrcUpdater; diff --git a/uppsrc/plugin/bz2/bz2.h b/uppsrc/plugin/bz2/bz2.h index a981a6656..1322b1f48 100644 --- a/uppsrc/plugin/bz2/bz2.h +++ b/uppsrc/plugin/bz2/bz2.h @@ -3,12 +3,18 @@ namespace Upp { -String BZ2Compress(String s, Gate progress = Null); -String BZ2Decompress(String s, Gate progress = Null); -String BZ2Decompress(Stream& stream, Gate progress = Null); void BZ2Compress(Stream& out, Stream& in, Gate progress = Null); void BZ2Decompress(Stream& out, Stream& in, Gate progress = Null); +String BZ2Compress(Stream& in, Gate progress = Null); +String BZ2Decompress(Stream& in, Gate progress = Null); + +String BZ2Compress(const void *data, int64 len, Gate progress); +String BZ2Decompress(const void *data, int64 len, Gate progress = Null); + +String BZ2Compress(const String& data, Gate progress = Null); +String BZ2Decompress(const String& data, Gate progress = Null); + } #endif//__Plugin_Z__ diff --git a/uppsrc/plugin/bz2/bz2upp.cpp b/uppsrc/plugin/bz2/bz2upp.cpp index 4eab5875f..c3841a46a 100644 --- a/uppsrc/plugin/bz2/bz2upp.cpp +++ b/uppsrc/plugin/bz2/bz2upp.cpp @@ -19,94 +19,6 @@ static void bzfree_new(void *opaque, void *addr) delete[] (byte *)addr; } -String BZ2Decompress(String s, Gate progress) -{ - if(s.IsEmpty()) - return s; - bz_stream z; - Zero(z); - z.bzalloc = bzalloc_new; - z.bzfree = bzfree_new; - z.opaque = 0; - if(BZ2_bzDecompressInit(&z, 0, 0) != BZ_OK) - return String::GetVoid(); - int buf_size = minmax(s.GetLength() / 2, 1024, 65536); - Buffer output(buf_size); - z.next_in = (char *)s.Begin(); - z.avail_in = s.GetLength(); - z.next_out = output; - z.avail_out = buf_size; - - String out; - while(BZ2_bzDecompress(&z) == BZ_OK) - { - if(z.avail_out == (dword)buf_size) - { // no output generated - assume error - BZ2_bzDecompressEnd(&z); - return String::GetVoid(); - } - out.Cat(output, buf_size - z.avail_out); - z.next_out = output; - z.avail_out = buf_size; - if(progress((int)(uintptr_t)((const char *)z.next_in - ~s), s.GetLength())) - { - BZ2_bzDecompressEnd(&z); - return String::GetVoid(); - } - } - if(z.avail_out < (unsigned)buf_size) - out.Cat(output, buf_size - z.avail_out); - - BZ2_bzDecompressEnd(&z); - - return out; -} - -String BZ2Decompress(Stream& strm, Gate progress) -{ - StringStream out; - BZ2Decompress(out, strm, progress); - return out; -} - -String BZ2Compress(String s, Gate progress) -{ - if(s.IsEmpty()) - return s; - bz_stream z; - Zero(z); - z.bzalloc = bzalloc_new; - z.bzfree = bzfree_new; - z.opaque = 0; - if(BZ2_bzCompressInit(&z, 9, 0, 30) != BZ_OK) - return String::GetVoid(); - int buf_size = minmax(s.GetLength(), 1024, 65536); - Buffer output(buf_size); - z.next_in = (char *)s.Begin(); - z.avail_in = s.GetLength(); - z.next_out = output; - z.avail_out = buf_size; - - String out; - int res; - while((res = BZ2_bzCompress(&z, z.avail_in ? BZ_RUN : BZ_FINISH)) == BZ_RUN_OK || res == BZ_FINISH_OK) - { - out.Cat(output, buf_size - z.avail_out); - z.next_out = output; - z.avail_out = buf_size; - if(progress((int)(uintptr_t)((const char *)z.next_in - ~s), s.GetLength())) - { - BZ2_bzCompressEnd(&z); - return String::GetVoid(); - } - } - out.Cat(output, buf_size - z.avail_out); - BZ2_bzCompressEnd(&z); - if(res != BZ_STREAM_END) - out = String::GetVoid(); - return out; -} - void BZ2Decompress(Stream& out, Stream& in, Gate progress) { enum { BUF_SIZE = 65536 }; @@ -217,4 +129,40 @@ void BZ2Compress(Stream& out, Stream& in, Gate progress) out.SetError(); } +String BZ2Compress(Stream& in, Gate progress) +{ + StringStream out; + BZ2Compress(out, in, progress); + return out; +} + +String BZ2Decompress(Stream& in, Gate progress) +{ + StringStream out; + BZ2Decompress(out, in, progress); + return out; +} + +String BZ2Compress(const void *data, int64 len, Gate progress) +{ + MemReadStream in(data, len); + return BZ2Compress(in, progress); +} + +String BZ2Decompress(const void *data, int64 len, Gate progress) +{ + MemReadStream in(data, len); + return BZ2Decompress(in, progress); +} + +String BZ2Compress(const String& data, Gate progress) +{ + return BZ2Compress(~data, data.GetLength(), progress); +} + +String BZ2Decompress(const String& data, Gate progress) +{ + return BZ2Decompress(~data, data.GetLength(), progress); +} + } diff --git a/uppsrc/plugin/lz4/lz4.h b/uppsrc/plugin/lz4/lz4.h index 8f537c683..78726ed83 100644 --- a/uppsrc/plugin/lz4/lz4.h +++ b/uppsrc/plugin/lz4/lz4.h @@ -113,6 +113,8 @@ public: int64 LZ4Compress(Stream& out, Stream& in, Gate progress = Null); int64 LZ4Decompress(Stream& out, Stream& in, Gate progress = Null); +String LZ4Compress(Stream& in, Gate progress = Null); +String LZ4Decompress(Stream& in, Gate progress = Null); String LZ4Compress(const void *data, int64 len, Gate progress = Null); String LZ4Compress(const String& s, Gate progress = Null); String LZ4Decompress(const void *data, int64 len, Gate progress = Null); @@ -121,6 +123,8 @@ String LZ4Decompress(const String& s, Gate progress = Null); #ifdef _MULTITHREADED int64 CoLZ4Compress(Stream& out, Stream& in, Gate progress = Null); int64 CoLZ4Decompress(Stream& out, Stream& in, Gate progress = Null); +String CoLZ4Compress(Stream& in, Gate progress = Null); +String CoLZ4Decompress(Stream& in, Gate progress = Null); String CoLZ4Compress(const void *data, int64 len, Gate progress = Null); String CoLZ4Compress(const String& s, Gate progress = Null); String CoLZ4Decompress(const void *data, int64 len, Gate progress = Null); diff --git a/uppsrc/plugin/lz4/src.tpp/Lz4$en-us.tpp b/uppsrc/plugin/lz4/src.tpp/Lz4$en-us.tpp index a6c5ffabc..ac9af85af 100644 --- a/uppsrc/plugin/lz4/src.tpp/Lz4$en-us.tpp +++ b/uppsrc/plugin/lz4/src.tpp/Lz4$en-us.tpp @@ -59,54 +59,66 @@ ressStream]([_^Upp`:`:Stream^ Stream][@(0.0.255) `&]_[*@3 in])&] [s0;*@7;4%% &] [ {{10000@(113.42.0) [s0;%% [*@7;4 LZ4 Compress/Decompress functions]]}}&] [s3; &] -[s5;:Upp`:`:LZ4Compress`(Upp`:`:Stream`&`,Upp`:`:Stream`&`,Upp`:`:EventGate``): [_^Upp`:`:int64^ i +[s5;:Upp`:`:LZ4Compress`(Upp`:`:Stream`&`,Upp`:`:Stream`&`,Upp`:`:Gate``): [_^Upp`:`:int64^ i nt64]_[* LZ4Compress]([_^Upp`:`:Stream^ Stream][@(0.0.255) `&]_[*@3 out], -[_^Upp`:`:Stream^ Stream][@(0.0.255) `&]_[*@3 in], [_^Upp`:`:EventGate^ EventGate]<[_^Upp`:`:int64^ i -nt64], [_^Upp`:`:int64^ int64]>_[*@3 progress]_`=_[@(0.0.255) false])&] -[s5;:Upp`:`:LZ4Decompress`(Upp`:`:Stream`&`,Upp`:`:Stream`&`,Upp`:`:EventGate``): [_^Upp`:`:int64^ i +[_^Upp`:`:Stream^ Stream][@(0.0.255) `&]_[*@3 in], [_^Upp`:`:Gate^ Gate]<[_^Upp`:`:int64^ i +nt64], [_^Upp`:`:int64^ int64]>_[*@3 progress]_`=_Null)&] +[s5;:Upp`:`:LZ4Decompress`(Upp`:`:Stream`&`,Upp`:`:Stream`&`,Upp`:`:Gate``): [_^Upp`:`:int64^ i nt64]_[* LZ4Decompress]([_^Upp`:`:Stream^ Stream][@(0.0.255) `&]_[*@3 out], -[_^Upp`:`:Stream^ Stream][@(0.0.255) `&]_[*@3 in], [_^Upp`:`:EventGate^ EventGate]<[_^Upp`:`:int64^ i -nt64], [_^Upp`:`:int64^ int64]>_[*@3 progress]_`=_[@(0.0.255) false])&] -[s5;:Upp`:`:LZ4Compress`(const void`*`,Upp`:`:int64`,Upp`:`:EventGate``): [_^Upp`:`:String^ S +[_^Upp`:`:Stream^ Stream][@(0.0.255) `&]_[*@3 in], [_^Upp`:`:Gate^ Gate]<[_^Upp`:`:int64^ i +nt64], [_^Upp`:`:int64^ int64]>_[*@3 progress]_`=_Null)&] +[s5;:Upp`:`:LZ4Compress`(Upp`:`:Stream`&`,Upp`:`:Gate``): [_^Upp`:`:String^ S +tring]_[* LZ4Compress]([_^Upp`:`:Stream^ Stream][@(0.0.255) `&]_[*@3 in], +[_^Upp`:`:Gate^ Gate]<[_^Upp`:`:int64^ int64], [_^Upp`:`:int64^ int64]>_[*@3 progress])&] +[s5;:Upp`:`:LZ4Decompress`(Upp`:`:Stream`&`,Upp`:`:Gate``): [_^Upp`:`:String^ S +tring]_[* LZ4Decompress]([_^Upp`:`:Stream^ Stream][@(0.0.255) `&]_[*@3 in], +[_^Upp`:`:Gate^ Gate]<[_^Upp`:`:int64^ int64], [_^Upp`:`:int64^ int64]>_[*@3 progress])&] +[s5;:Upp`:`:LZ4Compress`(const void`*`,Upp`:`:int64`,Upp`:`:Gate``): [_^Upp`:`:String^ S tring]_[* LZ4Compress]([@(0.0.255) const]_[@(0.0.255) void]_`*[*@3 data], -[_^Upp`:`:int64^ int64]_[*@3 len], [_^Upp`:`:EventGate^ EventGate]<[_^Upp`:`:int64^ int64 -], [_^Upp`:`:int64^ int64]>_[*@3 progress]_`=_[@(0.0.255) false])&] -[s5;:Upp`:`:LZ4Compress`(const Upp`:`:String`&`,Upp`:`:EventGate``): [_^Upp`:`:String^ S +[_^Upp`:`:int64^ int64]_[*@3 len], [_^Upp`:`:Gate^ Gate]<[_^Upp`:`:int64^ int64], +[_^Upp`:`:int64^ int64]>_[*@3 progress]_`=_Null)&] +[s5;:Upp`:`:LZ4Compress`(const Upp`:`:String`&`,Upp`:`:Gate``): [_^Upp`:`:String^ S tring]_[* LZ4Compress]([@(0.0.255) const]_[_^Upp`:`:String^ String][@(0.0.255) `&]_[*@3 s], - [_^Upp`:`:EventGate^ EventGate]<[_^Upp`:`:int64^ int64], [_^Upp`:`:int64^ int64]>_[*@3 p -rogress]_`=_[@(0.0.255) false])&] -[s5;:Upp`:`:LZ4Decompress`(const void`*`,Upp`:`:int64`,Upp`:`:EventGate``): [_^Upp`:`:String^ S + [_^Upp`:`:Gate^ Gate]<[_^Upp`:`:int64^ int64], [_^Upp`:`:int64^ int64]>_[*@3 progress]_`= +_Null)&] +[s5;:Upp`:`:LZ4Decompress`(const void`*`,Upp`:`:int64`,Upp`:`:Gate``): [_^Upp`:`:String^ S tring]_[* LZ4Decompress]([@(0.0.255) const]_[@(0.0.255) void]_`*[*@3 data], -[_^Upp`:`:int64^ int64]_[*@3 len], [_^Upp`:`:EventGate^ EventGate]<[_^Upp`:`:int64^ int64 -], [_^Upp`:`:int64^ int64]>_[*@3 progress]_`=_[@(0.0.255) false])&] -[s5;:Upp`:`:LZ4Decompress`(const Upp`:`:String`&`,Upp`:`:EventGate``): [_^Upp`:`:String^ S +[_^Upp`:`:int64^ int64]_[*@3 len], [_^Upp`:`:Gate^ Gate]<[_^Upp`:`:int64^ int64], +[_^Upp`:`:int64^ int64]>_[*@3 progress]_`=_Null)&] +[s5;:Upp`:`:LZ4Decompress`(const Upp`:`:String`&`,Upp`:`:Gate``): [_^Upp`:`:String^ S tring]_[* LZ4Decompress]([@(0.0.255) const]_[_^Upp`:`:String^ String][@(0.0.255) `&]_[*@3 s -], [_^Upp`:`:EventGate^ EventGate]<[_^Upp`:`:int64^ int64], [_^Upp`:`:int64^ int64]>_[*@3 p -rogress]_`=_[@(0.0.255) false])&] -[s5;:Upp`:`:CoLZ4Compress`(Upp`:`:Stream`&`,Upp`:`:Stream`&`,Upp`:`:EventGate``): [_^Upp`:`:int64^ i +], [_^Upp`:`:Gate^ Gate]<[_^Upp`:`:int64^ int64], [_^Upp`:`:int64^ int64]>_[*@3 progress]_ +`=_Null)&] +[s5;:Upp`:`:CoLZ4Compress`(Upp`:`:Stream`&`,Upp`:`:Stream`&`,Upp`:`:Gate``): [_^Upp`:`:int64^ i nt64]_[* CoLZ4Compress]([_^Upp`:`:Stream^ Stream][@(0.0.255) `&]_[*@3 out], -[_^Upp`:`:Stream^ Stream][@(0.0.255) `&]_[*@3 in], [_^Upp`:`:EventGate^ EventGate]<[_^Upp`:`:int64^ i -nt64], [_^Upp`:`:int64^ int64]>_[*@3 progress]_`=_[@(0.0.255) false])&] -[s5;:Upp`:`:CoLZ4Decompress`(Upp`:`:Stream`&`,Upp`:`:Stream`&`,Upp`:`:EventGate``): [_^Upp`:`:int64^ i +[_^Upp`:`:Stream^ Stream][@(0.0.255) `&]_[*@3 in], [_^Upp`:`:Gate^ Gate]<[_^Upp`:`:int64^ i +nt64], [_^Upp`:`:int64^ int64]>_[*@3 progress]_`=_Null)&] +[s5;:Upp`:`:CoLZ4Decompress`(Upp`:`:Stream`&`,Upp`:`:Stream`&`,Upp`:`:Gate``): [_^Upp`:`:int64^ i nt64]_[* CoLZ4Decompress]([_^Upp`:`:Stream^ Stream][@(0.0.255) `&]_[*@3 out], -[_^Upp`:`:Stream^ Stream][@(0.0.255) `&]_[*@3 in], [_^Upp`:`:EventGate^ EventGate]<[_^Upp`:`:int64^ i -nt64], [_^Upp`:`:int64^ int64]>_[*@3 progress]_`=_[@(0.0.255) false])&] -[s5;:Upp`:`:CoLZ4Compress`(const void`*`,Upp`:`:int64`,Upp`:`:EventGate``): [_^Upp`:`:String^ S +[_^Upp`:`:Stream^ Stream][@(0.0.255) `&]_[*@3 in], [_^Upp`:`:Gate^ Gate]<[_^Upp`:`:int64^ i +nt64], [_^Upp`:`:int64^ int64]>_[*@3 progress]_`=_Null)&] +[s5;:Upp`:`:CoLZ4Compress`(Upp`:`:Stream`&`,Upp`:`:Gate``): [_^Upp`:`:String^ S +tring]_[* CoLZ4Compress]([_^Upp`:`:Stream^ Stream][@(0.0.255) `&]_[*@3 in], +[_^Upp`:`:Gate^ Gate]<[_^Upp`:`:int64^ int64], [_^Upp`:`:int64^ int64]>_[*@3 progress])&] +[s5;:Upp`:`:CoLZ4Decompress`(Upp`:`:Stream`&`,Upp`:`:Gate``): [_^Upp`:`:String^ S +tring]_[* CoLZ4Decompress]([_^Upp`:`:Stream^ Stream][@(0.0.255) `&]_[*@3 in], +[_^Upp`:`:Gate^ Gate]<[_^Upp`:`:int64^ int64], [_^Upp`:`:int64^ int64]>_[*@3 progress])&] +[s5;:Upp`:`:CoLZ4Compress`(const void`*`,Upp`:`:int64`,Upp`:`:Gate``): [_^Upp`:`:String^ S tring]_[* CoLZ4Compress]([@(0.0.255) const]_[@(0.0.255) void]_`*[*@3 data], -[_^Upp`:`:int64^ int64]_[*@3 len], [_^Upp`:`:EventGate^ EventGate]<[_^Upp`:`:int64^ int64 -], [_^Upp`:`:int64^ int64]>_[*@3 progress]_`=_[@(0.0.255) false])&] -[s5;:Upp`:`:CoLZ4Compress`(const Upp`:`:String`&`,Upp`:`:EventGate``): [_^Upp`:`:String^ S +[_^Upp`:`:int64^ int64]_[*@3 len], [_^Upp`:`:Gate^ Gate]<[_^Upp`:`:int64^ int64], +[_^Upp`:`:int64^ int64]>_[*@3 progress]_`=_Null)&] +[s5;:Upp`:`:CoLZ4Compress`(const Upp`:`:String`&`,Upp`:`:Gate``): [_^Upp`:`:String^ S tring]_[* CoLZ4Compress]([@(0.0.255) const]_[_^Upp`:`:String^ String][@(0.0.255) `&]_[*@3 s -], [_^Upp`:`:EventGate^ EventGate]<[_^Upp`:`:int64^ int64], [_^Upp`:`:int64^ int64]>_[*@3 p -rogress]_`=_[@(0.0.255) false])&] -[s5;:Upp`:`:CoLZ4Decompress`(const void`*`,Upp`:`:int64`,Upp`:`:EventGate``): [_^Upp`:`:String^ S +], [_^Upp`:`:Gate^ Gate]<[_^Upp`:`:int64^ int64], [_^Upp`:`:int64^ int64]>_[*@3 progress]_ +`=_Null)&] +[s5;:Upp`:`:CoLZ4Decompress`(const void`*`,Upp`:`:int64`,Upp`:`:Gate``): [_^Upp`:`:String^ S tring]_[* CoLZ4Decompress]([@(0.0.255) const]_[@(0.0.255) void]_`*[*@3 data], -[_^Upp`:`:int64^ int64]_[*@3 len], [_^Upp`:`:EventGate^ EventGate]<[_^Upp`:`:int64^ int64 -], [_^Upp`:`:int64^ int64]>_[*@3 progress]_`=_[@(0.0.255) false])&] -[s5;:Upp`:`:CoLZ4Decompress`(const Upp`:`:String`&`,Upp`:`:EventGate``): [_^Upp`:`:String^ S +[_^Upp`:`:int64^ int64]_[*@3 len], [_^Upp`:`:Gate^ Gate]<[_^Upp`:`:int64^ int64], +[_^Upp`:`:int64^ int64]>_[*@3 progress]_`=_Null)&] +[s5;:Upp`:`:CoLZ4Decompress`(const Upp`:`:String`&`,Upp`:`:Gate``): [_^Upp`:`:String^ S tring]_[* CoLZ4Decompress]([@(0.0.255) const]_[_^Upp`:`:String^ String][@(0.0.255) `&]_[*@3 s -], [_^Upp`:`:EventGate^ EventGate]<[_^Upp`:`:int64^ int64], [_^Upp`:`:int64^ int64]>_[*@3 p -rogress]_`=_[@(0.0.255) false])&] +], [_^Upp`:`:Gate^ Gate]<[_^Upp`:`:int64^ int64], [_^Upp`:`:int64^ int64]>_[*@3 progress]_ +`=_Null)&] [s2;%% Simple LZ4 compression/decompression functions. [%-*@3 out] [%-*@3 in] parameters are input / ouput streams and function returns the number of bytes stored to [%-*@3 out], otherwise input is provided @@ -115,6 +127,7 @@ as memory block [%-*@3 data] of [%-*@3 len] bytes or as input String can be used to to track progress of operation and eventually interrupt it by returning true. Functions with Co prefix run multithreaded.&] +[s2;%% &] [s3;%% &] [s4; &] [s5;:Upp`:`:IsLZ4`(Upp`:`:Stream`&`): [@(0.0.255) bool]_[* IsLZ4]([_^Upp`:`:Stream^ Stream][@(0.0.255) `& @@ -123,4 +136,5 @@ multithreaded.&] Seeks back after the check. Returns true if magic number was detected.&] [s3;%% &] +[s3;%% &] [s0;%% ]] \ No newline at end of file diff --git a/uppsrc/plugin/lz4/util.cpp b/uppsrc/plugin/lz4/util.cpp index a9d62de9b..8ea80df59 100644 --- a/uppsrc/plugin/lz4/util.cpp +++ b/uppsrc/plugin/lz4/util.cpp @@ -42,13 +42,24 @@ int64 LZ4Decompress(Stream& out, Stream& in, Gate progress) return sLZ4Decompress(out, in, in.GetLeft(), progress, false); } -String LZ4Compress(const void *data, int64 len, Gate progress) +String LZ4Compress(Stream& in, Gate progress) { StringStream out; - MemReadStream in(data, len); return LZ4Compress(out, in, progress) < 0 ? String::GetVoid() : out.GetResult(); } +String LZ4Decompress(Stream& in, Gate progress) +{ + StringStream out; + return LZ4Decompress(out, in, progress) < 0 ? String::GetVoid() : out.GetResult(); +} + +String LZ4Compress(const void *data, int64 len, Gate progress) +{ + MemReadStream in(data, len); + return LZ4Compress(in, progress); +} + String LZ4Compress(const String& s, Gate progress) { return LZ4Compress(~s, s.GetLength(), progress); @@ -56,9 +67,8 @@ String LZ4Compress(const String& s, Gate progress) String LZ4Decompress(const void *data, int64 len, Gate progress) { - StringStream out; MemReadStream in(data, len); - return LZ4Decompress(out, in, progress) < 0 ? String::GetVoid() : out.GetResult(); + return LZ4Decompress(in, progress); } String LZ4Decompress(const String& s, Gate progress) @@ -78,6 +88,18 @@ int64 CoLZ4Decompress(Stream& out, Stream& in, Gate progress) return sLZ4Decompress(out, in, in.GetLeft(), progress, true); } +String CoLZ4Compress(Stream& in, Gate progress) +{ + StringStream out; + return CoLZ4Compress(out, in, progress) < 0 ? String::GetVoid() : out.GetResult(); +} + +String CoLZ4Decompress(Stream& in, Gate progress) +{ + StringStream out; + return CoLZ4Decompress(out, in, progress) < 0 ? String::GetVoid() : out.GetResult(); +} + String CoLZ4Compress(const void *data, int64 len, Gate progress) { StringStream out;