-
Notifications
You must be signed in to change notification settings - Fork 0
/
ID3v2Footer.cs
59 lines (45 loc) · 1.83 KB
/
ID3v2Footer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.IO;
namespace NAudio.Flac
{
public class ID3v2Footer
{
public const int FooterLength = 10;
public static ID3v2Footer FromStream(Stream stream)
{
if (stream == null) throw new ArgumentNullException("stream");
if (!stream.CanRead) throw new ArgumentException("stream not readable");
if (!stream.CanSeek) throw new ArgumentException("stream not seekable");
BinaryReader reader = new BinaryReader(stream);
ID3v2Footer footer;
byte[] buffer = new byte[FooterLength];
int read = stream.Read(buffer, 0, buffer.Length);
if (read < 10)
throw new EndOfStreamException();
if (buffer[0] == 0x49 && //I
buffer[1] == 0x44 && //D
buffer[2] == 0x33)
{
footer = new ID3v2Footer();
footer.Version = (ID3Version)buffer[3];
footer.RawVersion = new byte[] { buffer[3], buffer[4] };
footer.Flags = (ID3v2HeaderFlags)buffer[5];
/*footer.DataLength = buffer[6] * (1 << 21);
footer.DataLength += buffer[7] * (1 << 14);
footer.DataLength += buffer[8] * (1 << 7);
footer.DataLength += buffer[9];*/
footer.DataLength = ID3Utils.ReadInt32(buffer, 6, true);
return footer;
}
stream.Position -= read;
return null;
}
private ID3v2Footer()
{
}
public ID3Version Version { get; private set; }
public byte[] RawVersion { get; private set; }
public long DataLength { get; private set; }
public ID3v2HeaderFlags Flags { get; private set; }
}
}