BitSharper.Store.BoundedOverheadBlockStore.Record.Write C# (CSharp) Method

Write() public static method

public static Write ( Stream channel, StoredBlock block ) : void
channel System.IO.Stream
block StoredBlock
return void
            public static void Write(Stream channel, StoredBlock block)
            {
                using (var buf = ByteBuffer.Allocate(Size))
                {
                    buf.PutInt((int) block.Height);
                    var chainWorkBytes = block.ChainWork.ToByteArray();
                    Debug.Assert(chainWorkBytes.Length <= _chainWorkBytes, "Ran out of space to store chain work!");
                    if (chainWorkBytes.Length < _chainWorkBytes)
                    {
                        // Pad to the right size.
                        buf.Put(_emptyBytes, 0, _chainWorkBytes - chainWorkBytes.Length);
                    }
                    buf.Put(chainWorkBytes);
                    buf.Put(block.Header.BitcoinSerialize());
                    buf.Position = 0;
                    channel.Position = channel.Length;
                    channel.Write(buf.ToArray());
                    channel.Position = channel.Length - Size;
                }
            }