Last active
October 17, 2023 07:47
-
-
Save itn3000/05a1ddf282c13f77ceb458d2bbbc6123 to your computer and use it in GitHub Desktop.
ZStdSharp.Port compression test code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM mono:6.12 | |
COPY zstdtest /zstdtest | |
CMD ["mono","/zstdtest/zstdtest.exe"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Linq; | |
using Microsoft.VisualBasic; | |
using ZstdSharp; | |
namespace zstdtest; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
byte[] data = Enumerable.Range(0, 1024*1024).Select(i => (byte)(i & 0xff)).ToArray(); | |
var compressed = GetCompressed(data); | |
Console.WriteLine($"compressed size={compressed.Count}, original size={data.Length}"); | |
Console.WriteLine(Convert.ToBase64String(compressed.Array, compressed.Offset, compressed.Count, Base64FormattingOptions.InsertLineBreaks)); | |
} | |
static ArraySegment<byte> GetCompressed(byte[] data) | |
{ | |
using var compressor = new Compressor(1); | |
var compressed = new byte[Compressor.GetCompressBound(data.Length)]; | |
var byteswritten = compressor.Wrap(data, compressed, 0); | |
return new ArraySegment<byte>(compressed, 0, byteswritten); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment