Ejemplo n.º 1
0
 /// <summary>
 /// predict the size of the frames on disk (without any padding)
 /// by streaming the tag to a dummy stream, which updates the stored size.
 /// </summary>
 /// <remarks>
 /// Although the the padding is streamed out,
 /// the size isn't added on to Header.TagSize
 /// </remarks>
 public void UpdateSize()
 {
     if (!IsValid)
     {
         Header.TagSize = 0; // clear the TagSize stored in the tagModel
     }
     // TODO: there must be a better way of obtaining this!!
     using (Stream stream = new MemoryStream())
     {
         FrameManager.Serialize(this, stream);
     }
 }
Ejemplo n.º 2
0
        public int CalculateCrc()
        {
            if (!IsValid)
            {
                return(0);
            }

            using (MemoryStream stream = new MemoryStream())
            {
                // serialise tags to a buffer, without any padding
                FrameManager.Serialize(this, stream);

                // obtain whole buffer as byte array
                byte[] buffer = stream.ToArray();

                // calculate the size of the tag without the padding
                int tagsize = (int)buffer.Length - (int)Header.PaddingSize;

                // create and calculate crc-32 for the tag
                ICSharpCode.SharpZipLib.Checksums.Crc32 crc = new ICSharpCode.SharpZipLib.Checksums.Crc32();
                crc.Update(buffer, 0, tagsize);
                return((int)crc.Value);
            }
        }