Skip to content

Instantly share code, notes, and snippets.

@nayato
Created May 26, 2017 20:53
Show Gist options
  • Save nayato/87859c9306d12277d27eefb98315c4d9 to your computer and use it in GitHub Desktop.
Save nayato/87859c9306d12277d27eefb98315c4d9 to your computer and use it in GitHub Desktop.
internal class Program
{
private static void Main(string[] args)
{
var s = new Mock<Stream>();
s.SetupGet(x => x.CanWrite).Returns(true);
s.Setup(x => x.Write(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>()))
.Callback((byte[] buf, int ofs, int cnt) => Console.WriteLine(
$"under : len: {cnt} content:" + Environment.NewLine + ByteBufferUtil.PrettyHexDump(Unpooled
.WrappedBuffer(buf, ofs, cnt).Slice(0, Math.Min(cnt, 10)))));
var cs = new GZipStream(s.Object, CompressionMode.Compress, false);
var bs = Encoding.UTF8.GetBytes("Hello, World");
cs.Write(bs, 0, bs.Length);
var rnd = new Random(Environment.TickCount);
bs = new byte[80 * 1024];
rnd.NextBytes(bs);
cs.Write(bs, 0, bs.Length);
Console.WriteLine("closing now");
cs.Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment