private static Id3Frame DecodePicture(byte[] data) { var frame = new PictureFrame { EncodingType = (Id3TextEncoding)data[0] }; byte[] mimeType = ByteArrayHelper.GetBytesUptoSequence(data, 1, new byte[] { 0x00 }); if (mimeType == null) { frame.MimeType = "image/"; return(frame); } frame.MimeType = TextEncodingHelper.GetDefaultString(mimeType, 0, mimeType.Length); int currentPos = mimeType.Length + 2; frame.PictureType = (PictureType)data[currentPos]; currentPos++; byte[] description = ByteArrayHelper.GetBytesUptoSequence(data, currentPos, TextEncodingHelper.GetSplitterBytes(frame.EncodingType)); if (description == null) { return(frame); } frame.Description = TextEncodingHelper.GetString(description, 0, description.Length, frame.EncodingType); currentPos += description.Length + TextEncodingHelper.GetSplitterBytes(frame.EncodingType).Length; frame.PictureData = new byte[data.Length - currentPos]; Array.Copy(data, currentPos, frame.PictureData, 0, frame.PictureData.Length); return(frame); }
private static Id3Frame DecodePrivate(byte[] data) { var frame = new PrivateFrame(); byte[] splitterSequence = TextEncodingHelper.GetSplitterBytes(Id3TextEncoding.Iso8859_1); byte[] ownerIdBytes = ByteArrayHelper.GetBytesUptoSequence(data, 0, splitterSequence); frame.OwnerId = TextEncodingHelper.GetString(ownerIdBytes, 0, ownerIdBytes.Length, Id3TextEncoding.Iso8859_1); frame.Data = new byte[data.Length - ownerIdBytes.Length - splitterSequence.Length]; Array.Copy(data, ownerIdBytes.Length + splitterSequence.Length, frame.Data, 0, frame.Data.Length); return(frame); }
public void GetBytesUptoSequenceTests(byte[] source, byte[] sequence, byte[] expectedResult) { Assert.True(ByteArrayHelper.AreEqual(ByteArrayHelper.GetBytesUptoSequence(source, 0, sequence), expectedResult)); }