Skip to content

Instantly share code, notes, and snippets.

@itn3000
Last active October 17, 2023 07:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itn3000/05a1ddf282c13f77ceb458d2bbbc6123 to your computer and use it in GitHub Desktop.
Save itn3000/05a1ddf282c13f77ceb458d2bbbc6123 to your computer and use it in GitHub Desktop.
ZStdSharp.Port compression test code
FROM mono:6.12
COPY zstdtest /zstdtest
CMD ["mono","/zstdtest/zstdtest.exe"]
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