Example #1
0
        /// <summary>
        /// Parses the specified buffer starting at index to load all data for this frame
        /// This function will throw exceptions on parser errors.
        /// </summary>
        /// <param name="reader">FrameReader to read from.</param>
        void ParseVersion4(DataFrameReader reader)
        {
            if ((m_Header.TagHeader.Flags & ID3v2HeaderFlags.Unsynchronisation) == 0)
            {
                // no full unsync done, check if we have to unsync now
                if (m_Header.Flags.Unsynchronisation)
                {
                    m_Content = ID3v2DeUnsync.Buffer(m_Content);
                }
            }
            if (m_Header.Flags.Compression)
            {
                m_Content = Decompress(m_Content);
            }

            if (m_Header.Flags.Encryption)
            {
                m_Content = Decrypt(m_Content);
            }
        }
Example #2
0
        /// <summary>
        /// Reads the header (check <see cref="State"/> before usage).
        /// </summary>
        /// <returns></returns>
        public ID3v2Header ReadHeader(out byte[] tagData)
        {
            if (State != ID3v2ReaderState.ReadHeader)
            {
                throw new InvalidOperationException(string.Format("Cannot read header at state {0}", State));
            }

            var header = new ID3v2Header();

            if (!header.Parse(m_Reader))
            {
                tagData = null;
                return(null);
            }
            m_BodyBytes = header.BodySize;
            if ((header.Flags & ID3v2HeaderFlags.Footer) != 0)
            {
                m_BodyBytes -= 10;
            }
            State++;
            if (header.Version < 2)
            {
                tagData = null;
                return(null);
            }

            tagData = m_Reader.GetBuffer(header.HeaderSize + header.BodySize);
            var bodyData = tagData.GetRange(header.HeaderSize);

            // need to unsync whole tag?
            if ((header.Flags & ID3v2HeaderFlags.Unsynchronisation) != 0)
            {
                bodyData    = ID3v2DeUnsync.Buffer(bodyData);
                m_BodyBytes = bodyData.Length;
            }

            // update reader (use cached data)
            m_Header = header;
            m_Reader = new DataFrameReader(bodyData);
            return(header);
        }