Skip to content

Commit

Permalink
修复 XxcodeToStream 中 stream.Position != 0 时的 Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lc6464 committed Aug 23, 2023
1 parent 2491db0 commit 3cefd33
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static long EncodeToStream(Stream stream, Stream output) {
return writeCount;
}
{
Span<byte> data = new(new byte[stream.Length]);
Span<byte> data = new(new byte[stream.Length - stream.Position]);
_ = stream.Read(data);
var encodedData = Encode(data.ToArray());
output.Write(encodedData);
Expand All @@ -111,6 +111,9 @@ public static long EncodeToStream(Stream stream, Stream output) {
/// <returns>已写入的数据长度</returns>
public static long DecodeToStream(Stream stream, Stream output) {
if (stream.Length > Buffer1Length) {
#if !DEBUG
throw new Exception("暂不支持超过 " + Buffer1Length + " 字节的数据流。");
#endif
var buffer1 = new byte[Buffer1Length];

byte end; // skipcq: CS-W1022 赋值的确是不必要的
Expand All @@ -129,7 +132,7 @@ public static long DecodeToStream(Stream stream, Stream output) {
return writeCount;
}
{
Span<byte> data = new(new byte[stream.Length]);
Span<byte> data = new(new byte[stream.Length - stream.Position]);
_ = stream.Read(data);
var decodedData = Decode(data.ToArray());
output.Write(decodedData);
Expand Down

0 comments on commit 3cefd33

Please sign in to comment.