5 namespace SharpCompress.IO
7 internal class MarkingBinaryReader : BinaryReader
10 public MarkingBinaryReader(Stream stream)
15 public long CurrentReadByteCount { get; private set; }
19 CurrentReadByteCount = 0;
22 public override int Read()
24 throw new NotImplementedException();
27 public override int Read(byte[] buffer, int index, int count)
29 throw new NotImplementedException();
32 public override int Read(char[] buffer, int index, int count)
34 throw new NotImplementedException();
37 public override bool ReadBoolean()
39 return BitConverter.ToBoolean(ReadBytes(1), 0);
42 public override byte ReadByte()
44 return ReadBytes(1).Single();
47 public override byte[] ReadBytes(int count)
49 CurrentReadByteCount += count;
50 var bytes = base.ReadBytes(count);
51 if (bytes.Length != count)
53 throw new EndOfStreamException(string.Format("Could not read the requested amount of bytes. End of stream reached. Requested: {0} Read: {1}", count, bytes.Length));
58 public override char ReadChar()
60 throw new NotImplementedException();
63 public override char[] ReadChars(int count)
65 throw new NotImplementedException();
69 public override decimal ReadDecimal()
71 return ByteArrayToDecimal(ReadBytes(16), 0);
74 private decimal ByteArrayToDecimal(byte[] src, int offset)
76 //http://stackoverflow.com/a/16984356/385387
77 var i1 = BitConverter.ToInt32(src, offset);
78 var i2 = BitConverter.ToInt32(src, offset + 4);
79 var i3 = BitConverter.ToInt32(src, offset + 8);
80 var i4 = BitConverter.ToInt32(src, offset + 12);
82 return new decimal(new[] { i1, i2, i3, i4 });
86 public override double ReadDouble()
88 return BitConverter.ToDouble(ReadBytes(8), 0);
91 public override short ReadInt16()
93 return BitConverter.ToInt16(ReadBytes(2), 0);
96 public override int ReadInt32()
98 return BitConverter.ToInt32(ReadBytes(4), 0);
101 public override long ReadInt64()
103 return BitConverter.ToInt64(ReadBytes(8), 0);
106 public override sbyte ReadSByte()
108 return (sbyte)ReadByte();
111 public override float ReadSingle()
113 return BitConverter.ToSingle(ReadBytes(4), 0);
116 public override string ReadString()
118 throw new NotImplementedException();
121 public override ushort ReadUInt16()
123 return BitConverter.ToUInt16(ReadBytes(2), 0);
126 public override uint ReadUInt32()
128 return BitConverter.ToUInt32(ReadBytes(4), 0);
131 public override ulong ReadUInt64()
133 return BitConverter.ToUInt64(ReadBytes(8), 0);