@@ -20,6 +20,19 @@ const (
2020 msgHeaderNotParsed = "Tried to parse tick before parsing header"
2121)
2222
23+ // Parsing errors
24+ var (
25+ // ErrCancelled signals that parsing was cancelled via Parser.Cancel()
26+ ErrCancelled = errors .New ("Parsing was cancelled before it finished (ErrCancelled)" )
27+
28+ // ErrUnexpectedEndOfDemo signals that the demo is incomplete / corrupt -
29+ // these demos may still be useful, check the how far the parser got.
30+ ErrUnexpectedEndOfDemo = errors .New ("Demo stream ended unexpectedly (ErrUnexpectedEndOfDemo)" )
31+
32+ // ErrInvalidFileType signals that the input isn't a valid CS:GO demo.
33+ ErrInvalidFileType = errors .New ("Invalid File-Type; expecting HL2DEMO in the first 8 bytes" )
34+ )
35+
2336// ParseHeader attempts to parse the header of the demo.
2437// Returns error if the filestamp (first 8 bytes) doesn't match HL2DEMO.
2538func (p * Parser ) ParseHeader () (common.DemoHeader , error ) {
@@ -37,7 +50,7 @@ func (p *Parser) ParseHeader() (common.DemoHeader, error) {
3750 h .SignonLength = p .bitReader .ReadSignedInt (32 )
3851
3952 if h .Filestamp != "HL2DEMO" {
40- return h , errors . New ( "Invalid File-Type; expecting HL2DEMO in the first 8 bytes" )
53+ return h , ErrInvalidFileType
4154 }
4255
4356 // Initialize queue if the buffer size wasn't specified, the amount of ticks
@@ -52,16 +65,6 @@ func (p *Parser) ParseHeader() (common.DemoHeader, error) {
5265 return h , nil
5366}
5467
55- // Parsing errors
56- var (
57- // ErrCancelled signals that parsing was cancelled via Parser.Cancel()
58- ErrCancelled = errors .New ("Parsing was cancelled before it finished (ErrCancelled)" )
59-
60- // ErrUnexpectedEndOfDemo signals that the demo is incomplete / corrupt -
61- // these demos may still be useful, check the how far the parser got.
62- ErrUnexpectedEndOfDemo = errors .New ("Demo stream ended unexpectedly (ErrUnexpectedEndOfDemo)" )
63- )
64-
6568// ParseToEnd attempts to parse the demo until the end.
6669// Aborts and returns ErrCancelled if Cancel() is called before the end.
6770// May return ErrUnexpectedEndOfDemo for incomplete / corrupt demos.
0 commit comments