public void CalculateInt32_Set1_Stream() { using (Stream stream = new MemoryStream(_testByteArray_1)) { uint result = CRC32.CalculateInt32(stream); Assert.AreEqual(_crc32Result_1, result); } }
public void CalculateInt32_Set1_Path() { string path = PathUtils.GetTempFileName(".txt"); File.WriteAllText(path, _testString_1); try { uint result = CRC32.CalculateInt32(new FileInfo(path)); Assert.AreEqual(_crc32Result_1, result); } finally { File.Delete(path); } }
public byte[] GetBytes(int minimumSize) { ID3v2TagVersion version1 = this.m_ID3v2Header.TagVersion; using (MemoryStream stream1 = new MemoryStream()) { byte[] buffer1 = base.GetBytes(version1); int num1 = buffer1.Length; this.m_ID3v2Header.UsesUnsynchronization = false; this.m_ID3v2Header.IsExperimental = true; if (this.m_ID3v2Header.HasExtendedHeader) { num1 += this.m_ID3v2ExtendedHeader.SizeExcludingSizeBytes + 4; } int num2 = minimumSize - (num1 + 10); if (num2 < 0) { num2 = 0x7d0; } num1 += num2; this.m_ID3v2Header.TagSize = num1; byte[] buffer2 = this.m_ID3v2Header.GetBytes(); stream1.Write(buffer2, 0, buffer2.Length); if (this.m_ID3v2Header.HasExtendedHeader) { if (this.m_ID3v2ExtendedHeader.IsCRCDataPresent) { this.m_ID3v2ExtendedHeader.CRC32 = CRC32.CalculateInt32(buffer1); } this.m_ID3v2ExtendedHeader.PaddingSize = num2; byte[] buffer3 = this.m_ID3v2ExtendedHeader.GetBytes(version1); stream1.Write(buffer3, 0, buffer3.Length); } stream1.Write(buffer1, 0, buffer1.Length); byte[] buffer4 = new byte[num2]; stream1.Write(buffer4, 0, num2); stream1.Position = 0; new IdSharp.Tagging.ID3v2.ID3v2().ReadStream(stream1); return(stream1.ToArray()); } }
/// <summary> /// Gets the bytes of the current ID3v2 tag. /// </summary> /// <param name="minimumSize">The minimum size of the new tag, including the header and footer.</param> /// <returns>The bytes of the current ID3v2 tag.</returns> public byte[] GetBytes(int minimumSize) { ID3v2TagVersion tagVersion = _id3v2Header.TagVersion; using (MemoryStream tag = new MemoryStream()) { byte[] framesByteArray = GetBytes(tagVersion); int tagSize = framesByteArray.Length; _id3v2Header.UsesUnsynchronization = false; // hack _id3v2Header.IsExperimental = true; // hack //_id3v2ExtendedHeader.IsCRCDataPresent = true; // hack: for testing //_id3v2Header.HasExtendedHeader = true; // hack: for testing if (_id3v2Header.HasExtendedHeader) { // Add total size of extended header tagSize += _id3v2ExtendedHeader.SizeExcludingSizeBytes + 4; } int paddingSize = minimumSize - (tagSize + 10); if (paddingSize < 0) { paddingSize = 2000; } tagSize += paddingSize; // Set tag size in ID3v2 header _id3v2Header.TagSize = tagSize; byte[] id3v2Header = _id3v2Header.GetBytes(); tag.Write(id3v2Header, 0, id3v2Header.Length); if (_id3v2Header.HasExtendedHeader) { if (_id3v2ExtendedHeader.IsCRCDataPresent) { // TODO: Calculate total frame CRC (before or after unsync? compression? encr?) _id3v2ExtendedHeader.CRC32 = CRC32.CalculateInt32(framesByteArray); } // Set padding size _id3v2ExtendedHeader.PaddingSize = paddingSize; // todo: check byte[] id3v2ExtendedHeader = _id3v2ExtendedHeader.GetBytes(tagVersion); tag.Write(id3v2ExtendedHeader, 0, id3v2ExtendedHeader.Length); } tag.Write(framesByteArray, 0, framesByteArray.Length); byte[] padding = new byte[paddingSize]; tag.Write(padding, 0, paddingSize); // Make sure WE can read it without throwing errors // TODO: Take this out eventually, this is just a precaution. tag.Position = 0; ID3v2Tag newID3v2 = new ID3v2Tag(); newID3v2.Read(tag); return(tag.ToArray()); } }
public void CalculateInt32_Set1_ByteArray() { uint result = CRC32.CalculateInt32(_testByteArray_1); Assert.AreEqual(_crc32Result_1, result); }
public void CalculateInt32_Path_Null() { Assert.Throws <ArgumentNullException>(() => CRC32.CalculateInt32((FileInfo)null)); }
public void CalculateInt32_Stream_Null() { Assert.Throws <ArgumentNullException>(() => CRC32.CalculateInt32((Stream)null)); }
public void CalculateInt32_ByteArray_Null() { Assert.Throws <ArgumentNullException>(() => CRC32.CalculateInt32((byte[])null)); }