Skip to content

Commit

Permalink
Fixed warning for GZIP
Browse files Browse the repository at this point in the history
  • Loading branch information
SakulFlee committed Dec 10, 2024
1 parent a202e35 commit 5552fd5
Showing 1 changed file with 11 additions and 28 deletions.
39 changes: 11 additions & 28 deletions Godot Project/Demos/VideoCall/GZIP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,23 @@

public class GZIP
{
public static byte[] Decompress(byte[] input)
public static byte[] Decompress(byte[] data)
{
using (var source = new MemoryStream(input))
{
byte[] lengthBytes = new byte[4];
source.Read(lengthBytes, 0, 4);
using var compressedStream = new MemoryStream(data);
using var zipStream = new GZipStream(compressedStream, CompressionMode.Decompress);
using var resultStream = new MemoryStream();

var length = BitConverter.ToInt32(lengthBytes, 0);
using (var decompressionStream = new GZipStream(source,
CompressionMode.Decompress))
{
var result = new byte[length];
decompressionStream.Read(result, 0, length);
return result;
}
}
zipStream.CopyTo(resultStream);
return resultStream.ToArray();
}

public static byte[] Compress(byte[] input)
public static byte[] Compress(byte[] data)
{
using (var result = new MemoryStream())
using var result = new MemoryStream();
using (var compressionStream = new GZipStream(result, CompressionMode.Compress))
{
var lengthBytes = BitConverter.GetBytes(input.Length);
result.Write(lengthBytes, 0, 4);

using (var compressionStream = new GZipStream(result,
CompressionMode.Compress))
{
compressionStream.Write(input, 0, input.Length);
compressionStream.Flush();

}
return result.ToArray();
compressionStream.Write(data, 0, data.Length);
}
return result.ToArray();
}

}

0 comments on commit 5552fd5

Please sign in to comment.