/// <summary> /// Looks for a tag ending at a specified position and moves /// the cursor to its start position. /// </summary> /// <param name="position"> /// A <see cref="long" /> value reference specifying at what /// position the potential tag ends. If a tag is found, /// this value will be updated to the position at which the /// found tag starts. /// </param> /// <returns> /// A <see cref="TagLib.TagTypes" /> value specifying the /// type of tag found at the specified position, or <see /// cref="TagTypes.None" /> if no tag was found. /// </returns> private TagTypes ReadTagInfo(ref long position) { if (position - read_size < 0) { return(TagTypes.None); } file.Seek(position - read_size); ByteVector data = file.ReadBlock(read_size); try { int offset = (int)(data.Count - TagLib.Ape.Footer.Size); if (data.ContainsAt(TagLib.Ape.Footer.FileIdentifier, offset)) { TagLib.Ape.Footer footer = new TagLib.Ape.Footer( data.Mid(offset)); // If the complete tag size is zero or // the tag is a header, this indicates // some sort of corruption. if (footer.CompleteTagSize == 0 || (footer.Flags & TagLib.Ape.FooterFlags.IsHeader) != 0) { return(TagTypes.None); } position -= footer.CompleteTagSize; return(TagTypes.Ape); } offset = (int)(data.Count - TagLib.Id3v2.Footer.Size); if (data.ContainsAt(TagLib.Id3v2.Footer.FileIdentifier, offset)) { TagLib.Id3v2.Footer footer = new TagLib.Id3v2.Footer( data.Mid(offset)); position -= footer.CompleteTagSize; return(TagTypes.Id3v2); } if (data.StartsWith( TagLib.Id3v1.Tag.FileIdentifier)) { position -= TagLib.Id3v1.Tag.Size; return(TagTypes.Id3v1); } } catch (CorruptFileException) { } return(TagTypes.None); }
public void ContainsAt() { Assert.IsTrue(TestVector.ContainsAt("JKLMNO", 9)); Assert.IsFalse(TestVector.ContainsAt("NOOP", 30)); }