• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DomCR / ACadSharp / 12905761471

22 Jan 2025 10:03AM UTC coverage: 2.0% (-74.0%) from 75.963%
12905761471

push

github

DomCR
version 1.0.6

104 of 7676 branches covered (1.35%)

Branch coverage included in aggregate %.

590 of 27024 relevant lines covered (2.18%)

5.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/ACadSharp/IO/DWG/CRC8StreamHandler.cs
1
using System.IO;
2

3
namespace ACadSharp.IO.DWG
4
{
5
        /// <summary>
6
        /// The DWG file format uses a modification of a standard cyclic redundancy check as an error detecting mechanism. <br/>
7
        /// This class checks the integrity of the file using this check.
8
        /// </summary>
9
        /// <remarks>
10
        /// This method is used extensively in pre-R13 files, but seems only to be used in the header for R13 and beyond.
11
        /// </remarks>
12
        internal class CRC8StreamHandler : Stream
13
        {
14
                public override bool CanRead => this._stream.CanRead;
×
15

16
                public override bool CanSeek => this._stream.CanSeek;
×
17

18
                public override bool CanWrite => this._stream.CanWrite;
×
19

20
                public override long Length => this._stream.Length;
×
21

22
                public override long Position
23
                {
24
                        get => this._stream.Position;
×
25
                        set => this._stream.Position = value;
×
26
                }
27

28
                public ushort Seed { get; private set; }
×
29

30
                private Stream _stream;
31

32
                public CRC8StreamHandler(Stream stream, ushort seed)
×
33
                {
×
34
                        this._stream = stream;
×
35
                        this.Seed = seed;
×
36
                }
×
37

38
                public override int Read(byte[] buffer, int offset, int count)
39
                {
×
40
                        int nbytes = this._stream.Read(buffer, offset, count);
×
41
                        int length = offset + count;
×
42

43
                        for (int index = offset; index < length; ++index)
×
44
                                this.Seed = decode(this.Seed, buffer[index]);
×
45

46
                        return nbytes;
×
47
                }
×
48

49
                public override void Flush() => this._stream.Flush();
×
50

51
                public override long Seek(long offset, SeekOrigin origin) => this._stream.Seek(offset, origin);
×
52

53
                public override void SetLength(long value) => this._stream.SetLength(value);
×
54

55
                public override void Write(byte[] buffer, int offset, int count)
56
                {
×
57
                        int length = offset + count;
×
58

59
                        for (int index = offset; index < length; ++index)
×
60
                                this.Seed = decode(this.Seed, buffer[index]);
×
61

62
                        this._stream.Write(buffer, offset, count);
×
63
                }
×
64

65
                public static ushort GetCRCValue(ushort seed, byte[] buffer, long startPos, long endPos)
66
                {
×
67
                        ushort currValue = seed;
×
68
                        int index = (int)startPos;
×
69

70
                        while (endPos-- > 0)
×
71
                        {
×
72
                                currValue = CRC8StreamHandler.decode(currValue, buffer[index]);
×
73
                                index++;
×
74
                        }
×
75

76
                        return currValue;
×
77
                }
×
78

79
                private static ushort decode(ushort key, byte value)
80
                {
×
81
                        int index = value ^ (byte)key;
×
82
                        key = (ushort)((uint)key >> 8 ^ CRC.CrcTable[index]);
×
83
                        return key;
×
84
                }
×
85
        }
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc