diff --git a/uppsrc/Core/Stream.h b/uppsrc/Core/Stream.h index 80c532130..c5eaad8ee 100644 --- a/uppsrc/Core/Stream.h +++ b/uppsrc/Core/Stream.h @@ -612,8 +612,7 @@ private: String LoadStream(Stream& in); bool SaveStream(Stream& out, const String& data); -int64 CopyStream(Stream& dest, Stream& src, int64 count); -inline int64 CopyStream(Stream& dest, Stream& src) { return CopyStream(dest, src, src.GetLeft()); } +int64 CopyStream(Stream& dest, Stream& src, int64 count = INT64_MAX); #ifndef PLATFORM_WINCE void CoutUTF8(); diff --git a/uppsrc/Core/src.tpp/StreamFn$en-us.tpp b/uppsrc/Core/src.tpp/StreamFn$en-us.tpp index 5cc598e24..f1ef51a13 100644 --- a/uppsrc/Core/src.tpp/StreamFn$en-us.tpp +++ b/uppsrc/Core/src.tpp/StreamFn$en-us.tpp @@ -9,173 +9,162 @@ topic "Stream utilities"; [l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param] [i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam] [b42;2 $$9,9#13035079074754324216151401829390:normal] -[{_}%EN-US -[s0; [5 Stream helpers]&] -[s0;3%- &] -[ {{10000t/25b/25@1 [s0;%- [* Function List]]}}&] -[s3;%- &] -[s5;:LoadStream`(Stream`&`):%- [_^String^ String]_[* LoadStream]([_^Stream^ Stream][@(0.0.255) `& +[{_} +[s0;%% [5 Stream helpers]&] +[s0;3 &] +[ {{10000t/25b/25@1 [s0; [* Function List]]}}&] +[s3; &] +[s5;:LoadStream`(Stream`&`): [_^String^ String]_[* LoadStream]([_^Stream^ Stream][@(0.0.255) `& ]_[*@3 in])&] -[s2; Reads the stream starting with the current position till the +[s2;%% Reads the stream starting with the current position till the end is reached and returns data in String.&] -[s7; [%-*C@3 in]-|Stream.&] -[s7; [*/ Return value]-|Content of stream.&] -[s3;%- &] -[s4;%- &] -[s5;:SaveStream`(Stream`&`,const String`&`):%- [@(0.0.255) bool]_[* SaveStream]([_^Stream^ S -tream][@(0.0.255) `&]_[*@3 out], [@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 da -ta])&] -[s2; Writes data to stream.&] -[s7; [%-*C@3 out]-|Output stream.&] -[s7; [%-*C@3 data]-|Data to write.&] -[s7; [*/ Return value]-|True if all data were successfully written to -the stream.&] -[s3;%- &] -[s4;%- &] -[s5;:CopyStream`(Stream`&`,Stream`&`,int64`):%- [_^int64^ int64]_[* CopyStream]([_^Stream^ S -tream][@(0.0.255) `&]_[*@3 dest], [_^Stream^ Stream][@(0.0.255) `&]_[*@3 src], -[_^int64^ int64]_[*@3 count])&] -[s2; Copies data from source to destination stream.&] -[s7; [%-*C@3 dest]-|Destination stream.&] -[s7; [%-*C@3 src]-|Source stream.&] -[s7; [%-*C@3 count]-|Number of bytes to copy.&] -[s7; [*/ Return value]-|Number of bytes actually copies.&] -[s3;%- &] -[s4;%- &] -[s5;:CopyStream`(Stream`&`,Stream`&`):%- [_^int64^ int64]_[* CopyStream]([_^Stream^ Stream][@(0.0.255) `& -]_[*@3 dest], [_^Stream^ Stream][@(0.0.255) `&]_[*@3 src])&] -[s2; Copies all data from source stream starting with current position -to the destination stream.&] -[s7; [%-*C@3 dest]-|Destination stream.&] -[s7; [%-*C@3 src]-|Source stream.&] -[s7; [*/ Return value]-|Number of bytes copied.&] -[s3;%- &] -[s4;%- &] -[s5;:CoutUTF8`(`):%- [@(0.0.255) void]_[* CoutUTF8]()&] -[s2; In Win32, setups console output for UTF8. NOP in POSIX.&] -[s3;%- &] -[s4;%- &] -[s5;:Cout`(`):%- [_^Stream^ Stream][@(0.0.255) `&]_[* Cout]()&] -[s2; Returns special output stream representing console output. Data -written to this stream are displayed as characters in console. +[s7;%% [%-*C@3 in]-|Stream.&] +[s7;%% [*/ Return value]-|Content of stream.&] +[s3; &] +[s4; &] +[s5;:SaveStream`(Stream`&`,const String`&`): [@(0.0.255) bool]_[* SaveStream]([_^Stream^ St +ream][@(0.0.255) `&]_[*@3 out], [@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 dat +a])&] +[s2;%% Writes data to stream.&] +[s7;%% [%-*C@3 out]-|Output stream.&] +[s7;%% [%-*C@3 data]-|Data to write.&] +[s7;%% [*/ Return value]-|True if all data were successfully written +to the stream.&] +[s3; &] +[s4; &] +[s5;:CopyStream`(Stream`&`,Stream`&`,int64`): [_^int64^ int64]_[* CopyStream]([_^Stream^ St +ream][@(0.0.255) `&]_[*@3 dest], [_^Stream^ Stream][@(0.0.255) `&]_[*@3 src], +[_^int64^ int64]_[*@3 count] `= INT64`_MAX)&] +[s2;%% Copies at most [%-*@3 count] bytes from source to destination +stream. Returns the actual number of bytes copied. With default +[%-*@3 count] value it copies all data from [%-*@3 src] until EOF.&] +[s3; &] +[s4; &] +[s5;:CoutUTF8`(`): [@(0.0.255) void]_[* CoutUTF8]()&] +[s2;%% In Win32, setups console output for UTF8. NOP in POSIX.&] +[s3; &] +[s4; &] +[s5;:Cout`(`): [_^Stream^ Stream][@(0.0.255) `&]_[* Cout]()&] +[s2;%% Returns special output stream representing console output. +Data written to this stream are displayed as characters in console. In Win32, encoding is converted to default console encoding, or is not convereted at all if CoutUTF8 was called.&] -[s7; [*/ Return value]-|Console stream.&] -[s3;%- &] -[s4;%- &] -[s5;:Cerr`(`):%- [_^Stream^ Stream][@(0.0.255) `&]_[* Cerr]()&] -[s2; Returns special output stream representing console error output. +[s7;%% [*/ Return value]-|Console stream.&] +[s3; &] +[s4; &] +[s5;:Cerr`(`): [_^Stream^ Stream][@(0.0.255) `&]_[* Cerr]()&] +[s2;%% Returns special output stream representing console error output. Data written to this stream are displayed as characters in console.&] -[s3;%- &] -[s4;%- &] -[s5;:ReadStdIn`(`):%- [_^String^ String]_[* ReadStdIn]()&] -[s2; Reads one line of input data from the console.&] -[s7; [*/ Return value]-|Console input.&] -[s3;%- &] -[s4;%- &] -[s5;:NilStream`(`):%- [_^Stream^ Stream][@(0.0.255) `&]_[* NilStream]()&] -[s2; Returns special stream that is always in IsEof state and simply +[s3; &] +[s4; &] +[s5;:ReadStdIn`(`): [_^String^ String]_[* ReadStdIn]()&] +[s2;%% Reads one line of input data from the console.&] +[s7;%% [*/ Return value]-|Console input.&] +[s3; &] +[s4; &] +[s5;:NilStream`(`): [_^Stream^ Stream][@(0.0.255) `&]_[* NilStream]()&] +[s2;%% Returns special stream that is always in IsEof state and simply discards all data written to it.&] -[s7; [*/ Return value]-|`"Black hole`" stream.&] -[s3;%- &] -[s4;%- &] -[s5;:LoadFile`(const char`*`):%- [_^String^ String]_[* LoadFile]([@(0.0.255) const]_[@(0.0.255) c +[s7;%% [*/ Return value]-|`"Black hole`" stream.&] +[s3; &] +[s4; &] +[s5;:LoadFile`(const char`*`): [_^String^ String]_[* LoadFile]([@(0.0.255) const]_[@(0.0.255) c har]_`*[*@3 filename])&] -[s2; Loads the content of specified file.&] -[s7; [%-*C@3 filename]-|File name.&] -[s7; [*/ Return value]-|Content of file.&] -[s3;%- &] -[s4;%- &] -[s5;:SaveFile`(const char`*`,const String`&`):%- [@(0.0.255) bool]_[* SaveFile]([@(0.0.255) c +[s2;%% Loads the content of specified file.&] +[s7;%% [%-*C@3 filename]-|File name.&] +[s7;%% [*/ Return value]-|Content of file.&] +[s3; &] +[s4; &] +[s5;:SaveFile`(const char`*`,const String`&`): [@(0.0.255) bool]_[* SaveFile]([@(0.0.255) c onst]_[@(0.0.255) char]_`*[*@3 filename], [@(0.0.255) const]_[_^String^ String][@(0.0.255) `& ]_[*@3 data])&] -[s2; Saves data as the file (overwrites existing).&] -[s7; [%-*C@3 filename]-|File name.&] -[s7; [%-*C@3 data]-|Data to write.&] -[s7; [*/ Return value]-|true if file was successfully written.&] -[s3;%- &] -[s4;%- &] -[s5;:operator`%`(Stream`&`,T`&`):%- [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 T][@(0.0.255) > +[s2;%% Saves data as the file (overwrites existing).&] +[s7;%% [%-*C@3 filename]-|File name.&] +[s7;%% [%-*C@3 data]-|Data to write.&] +[s7;%% [*/ Return value]-|true if file was successfully written.&] +[s3; &] +[s4; &] +[s5;:operator`%`(Stream`&`,T`&`): [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 T][@(0.0.255) > ]_[_^Stream^ Stream][@(0.0.255) `&]_[* operator%]([_^Stream^ Stream][@(0.0.255) `&]_[*@3 s], [*@4 T][@(0.0.255) `&]_[*@3 x])&] -[s2; Serialization operator. Simply invokes x.Serialize(s);&] -[s7; [*C@4 T]-|Type of variable to be serialized.&] -[s7; [%-*C@3 s]-|Stream.&] -[s7; [%-*C@3 x]-|Variable to be serialized.&] -[s7; [*/ Return value]-|s for chaining.&] -[s3;%- &] -[s4;%- &] -[s5;:operator`<`<`(Stream`&`,const char`*`):%- [_^Stream^ Stream][@(0.0.255) `&]_[* operato -r<<]([_^Stream^ Stream][@(0.0.255) `&]_[*@3 s], [@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 x -])&] -[s2; Overload of stream insertion operator to get simple case work. -Insertion operator uses formatted stream output (Putf).&] -[s7; [%-*C@3 s]-|Output stream.&] -[s7; [%-*C@3 x]-|Data to write `- all characters are written to the -stream.&] -[s7; [*/ Return value]-|s for chaining.&] -[s3;%- &] -[s4;%- &] -[s5;:operator`<`<`(Stream`&`,char`*`):%- [_^Stream^ Stream][@(0.0.255) `&]_[* operator<<]([_^Stream^ S -tream][@(0.0.255) `&]_[*@3 s], [@(0.0.255) char]_`*[*@3 x])&] -[s2; Overload of stream insertion operator to get simple case work. -Insertion operator uses formatted stream output (Putf).&] -[s7; [%-*C@3 s]-|Output stream.&] -[s7; [%-*C@3 x]-|Data to write `- all characters are written to the -stream.&] -[s7; [*/ Return value]-|s for chaining.&] -[s3;%- &] -[s4;%- &] -[s5;:operator`<`<`(Stream`&`,const String`&`):%- [_^Stream^ Stream][@(0.0.255) `&]_[* opera -tor<<]([_^Stream^ Stream][@(0.0.255) `&]_[*@3 s], [@(0.0.255) const]_[_^String^ String]_`&[*@3 x -])&] -[s2; Overload of stream insertion operator to get simple case work. -Insertion operator uses formatted stream output (Putf).&] -[s7; [%-*C@3 s]-|Output stream.&] -[s7; [%-*C@3 x]-|Data to write `- all characters are written to the -stream.&] -[s7; [*/ Return value]-|s for chaining.&] -[s3;%- &] -[s4;%- &] -[s5;:operator`<`<`(Stream`&`,char`):%- [_^Stream^ Stream][@(0.0.255) `&]_[* operator<<]([_^Stream^ S -tream][@(0.0.255) `&]_[*@3 s], [@(0.0.255) char]_[*@3 x])&] -[s2; Overload of stream insertion operator to get simple case work. -Insertion operator uses formatted stream output (Putf).&] -[s7; [%-*C@3 s]-|Output stream.&] -[s7; [%-*C@3 x]-|Data to write `- it is written as single character.&] -[s7; [*/ Return value]-|s for chaining.&] -[s3;%- &] -[s4;%- &] -[s5;:operator`<`<`(Stream`&`,const void`*`):%- [_^Stream^ Stream][@(0.0.255) `&]_[* operato -r<<]([_^Stream^ Stream][@(0.0.255) `&]_[*@3 s], [@(0.0.255) const]_[@(0.0.255) void]_`*[*@3 x -])&] -[s2; Overload of stream insertion operator to get simple case work. -Insertion operator uses formatted stream output (Putf).&] -[s7; [%-*C@3 s]-|Output stream.&] -[s7; [%-*C@3 x]-|Data to write `- pointer is formatted as hexadecimal -value.&] -[s7; [*/ Return value]-|s for chaining.&] -[s3;%- &] -[s4;%- &] -[s5;:operator`<`<`(Stream`&`,void`*`):%- [_^Stream^ Stream][@(0.0.255) `&]_[* operator<<]([_^Stream^ S -tream][@(0.0.255) `&]_[*@3 s], [@(0.0.255) void]_`*[*@3 x])&] -[s2; Overload of stream insertion operator to get simple case work. -Insertion operator uses formatted stream output (Putf).&] -[s7; [%-*C@3 s]-|Output stream.&] -[s7; [%-*C@3 x]-|Data to write `- pointer is formatted as hexadecimal -value.&] -[s7; [*/ Return value]-|s for chaining.&] -[s3;%- &] -[s4;%- &] -[s5;:operator`<`<`(Stream`&`,const T`&`):%- [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 T -][@(0.0.255) >]_[_^Stream^ Stream][@(0.0.255) `&]_[* operator<<]([_^Stream^ Stream][@(0.0.255) `& -]_[*@3 s], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x])&] -[s2; Global stream insertion operator. Calls AsString for x and stores -the result to the stream. Global AsString version in turn calls -ToString method of x.&] -[s7; [*C@4 T]-|Type of data to write to the stream.&] -[s7; [%-*C@3 s]-|Output stream.&] -[s7; [%-*C@3 x]-|Data to write.&] -[s7; [*/ Return value]-|s for chaining.&] +[s2;%% Serialization operator. Simply invokes x.Serialize(s);&] +[s7;%% [*C@4 T]-|Type of variable to be serialized.&] +[s7;%% [%-*C@3 s]-|Stream.&] +[s7;%% [%-*C@3 x]-|Variable to be serialized.&] +[s7;%% [*/ Return value]-|s for chaining.&] [s3; &] -[s0; ]] \ No newline at end of file +[s4; &] +[s5;:operator`<`<`(Stream`&`,const char`*`): [_^Stream^ Stream][@(0.0.255) `&]_[* operator< +<]([_^Stream^ Stream][@(0.0.255) `&]_[*@3 s], [@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 x]) +&] +[s2;%% Overload of stream insertion operator to get simple case work. +Insertion operator uses formatted stream output (Putf).&] +[s7;%% [%-*C@3 s]-|Output stream.&] +[s7;%% [%-*C@3 x]-|Data to write `- all characters are written to the +stream.&] +[s7;%% [*/ Return value]-|s for chaining.&] +[s3; &] +[s4; &] +[s5;:operator`<`<`(Stream`&`,char`*`): [_^Stream^ Stream][@(0.0.255) `&]_[* operator<<]([_^Stream^ S +tream][@(0.0.255) `&]_[*@3 s], [@(0.0.255) char]_`*[*@3 x])&] +[s2;%% Overload of stream insertion operator to get simple case work. +Insertion operator uses formatted stream output (Putf).&] +[s7;%% [%-*C@3 s]-|Output stream.&] +[s7;%% [%-*C@3 x]-|Data to write `- all characters are written to the +stream.&] +[s7;%% [*/ Return value]-|s for chaining.&] +[s3; &] +[s4; &] +[s5;:operator`<`<`(Stream`&`,const String`&`): [_^Stream^ Stream][@(0.0.255) `&]_[* operato +r<<]([_^Stream^ Stream][@(0.0.255) `&]_[*@3 s], [@(0.0.255) const]_[_^String^ String]_`&[*@3 x +])&] +[s2;%% Overload of stream insertion operator to get simple case work. +Insertion operator uses formatted stream output (Putf).&] +[s7;%% [%-*C@3 s]-|Output stream.&] +[s7;%% [%-*C@3 x]-|Data to write `- all characters are written to the +stream.&] +[s7;%% [*/ Return value]-|s for chaining.&] +[s3; &] +[s4; &] +[s5;:operator`<`<`(Stream`&`,char`): [_^Stream^ Stream][@(0.0.255) `&]_[* operator<<]([_^Stream^ S +tream][@(0.0.255) `&]_[*@3 s], [@(0.0.255) char]_[*@3 x])&] +[s2;%% Overload of stream insertion operator to get simple case work. +Insertion operator uses formatted stream output (Putf).&] +[s7;%% [%-*C@3 s]-|Output stream.&] +[s7;%% [%-*C@3 x]-|Data to write `- it is written as single character.&] +[s7;%% [*/ Return value]-|s for chaining.&] +[s3; &] +[s4; &] +[s5;:operator`<`<`(Stream`&`,const void`*`): [_^Stream^ Stream][@(0.0.255) `&]_[* operator< +<]([_^Stream^ Stream][@(0.0.255) `&]_[*@3 s], [@(0.0.255) const]_[@(0.0.255) void]_`*[*@3 x]) +&] +[s2;%% Overload of stream insertion operator to get simple case work. +Insertion operator uses formatted stream output (Putf).&] +[s7;%% [%-*C@3 s]-|Output stream.&] +[s7;%% [%-*C@3 x]-|Data to write `- pointer is formatted as hexadecimal +value.&] +[s7;%% [*/ Return value]-|s for chaining.&] +[s3; &] +[s4; &] +[s5;:operator`<`<`(Stream`&`,void`*`): [_^Stream^ Stream][@(0.0.255) `&]_[* operator<<]([_^Stream^ S +tream][@(0.0.255) `&]_[*@3 s], [@(0.0.255) void]_`*[*@3 x])&] +[s2;%% Overload of stream insertion operator to get simple case work. +Insertion operator uses formatted stream output (Putf).&] +[s7;%% [%-*C@3 s]-|Output stream.&] +[s7;%% [%-*C@3 x]-|Data to write `- pointer is formatted as hexadecimal +value.&] +[s7;%% [*/ Return value]-|s for chaining.&] +[s3; &] +[s4; &] +[s5;:operator`<`<`(Stream`&`,const T`&`): [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 T][@(0.0.255) > +]_[_^Stream^ Stream][@(0.0.255) `&]_[* operator<<]([_^Stream^ Stream][@(0.0.255) `&]_[*@3 s], + [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x])&] +[s2;%% Global stream insertion operator. Calls AsString for x and +stores the result to the stream. Global AsString version in turn +calls ToString method of x.&] +[s7;%% [*C@4 T]-|Type of data to write to the stream.&] +[s7;%% [%-*C@3 s]-|Output stream.&] +[s7;%% [%-*C@3 x]-|Data to write.&] +[s7;%% [*/ Return value]-|s for chaining.&] +[s3;%% &] +[s0;%% ]] \ No newline at end of file diff --git a/uppsrc/Core/z.cpp b/uppsrc/Core/z.cpp index 9b8b69ddb..24104e762 100644 --- a/uppsrc/Core/z.cpp +++ b/uppsrc/Core/z.cpp @@ -501,4 +501,18 @@ String FastDecompress(const String& data) return b; } +// following function is used in both plugin/lz4 and plugin/zstd +void sCompressStreamCopy_(Stream& out, Stream& in, EventGate progress, Stream& orig_in, int64 insz) +{ + const int CHUNK = 32678; + Buffer b(CHUNK); + while(!in.IsEof()) { + if(progress(orig_in.GetPos(), insz)) + break; + int n = in.Get(b, CHUNK); + out.Put(b, n); + } + progress(orig_in.GetPos(), insz); +} + END_UPP_NAMESPACE diff --git a/uppsrc/plugin/lz4/util.cpp b/uppsrc/plugin/lz4/util.cpp index d2dc9767f..5c06d1bbb 100644 --- a/uppsrc/plugin/lz4/util.cpp +++ b/uppsrc/plugin/lz4/util.cpp @@ -2,18 +2,7 @@ namespace Upp { -void sCompressStreamCopy_(Stream& out, Stream& in, EventGate progress, Stream& orig_in, int64 insz) -{ - const int CHUNK = 32678; - Buffer b(CHUNK); - while(!in.IsEof()) { - if(progress(orig_in.GetPos(), insz)) - break; - int n = in.Get(b, CHUNK); - out.Put(b, n); - } - progress(orig_in.GetPos(), insz); -} +void sCompressStreamCopy_(Stream& out, Stream& in, EventGate progress, Stream& orig_in, int64 insz); static int64 sLZ4Compress(Stream& out, Stream& in, int64 size, EventGate progress, bool co) { diff --git a/uppsrc/plugin/zstd/Util.cpp b/uppsrc/plugin/zstd/Util.cpp index 3cf6b2453..bd12024de 100644 --- a/uppsrc/plugin/zstd/Util.cpp +++ b/uppsrc/plugin/zstd/Util.cpp @@ -9,7 +9,7 @@ static int64 sZstdCompress(Stream& out, Stream& in, int64 size, EventGate