-
Notifications
You must be signed in to change notification settings - Fork 0
/
hbxml.go
39 lines (31 loc) · 887 Bytes
/
hbxml.go
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
package hbxml
import (
"fmt"
"io"
"os"
"strings"
)
// ParseFromFile parses a beatmap file from the given filepath.
func ParseFromFile(filepath string) (*Beatmap, error) {
if stat, err := os.Stat(filepath); err != nil || stat.IsDir() {
return nil, fmt.Errorf("hbxml: '%s' is not a valid file", filepath)
}
file, err := os.Open(filepath)
if err != nil {
return nil, fmt.Errorf("hbxml: %s", err)
}
defer file.Close()
bytes, err := io.ReadAll(file)
if err != nil {
return nil, fmt.Errorf("hbxml: %s", err)
}
return ParseFromBytes(bytes)
}
// ParseFromBytes parses a beatmap file from the given byte slice.
func ParseFromBytes(bytes []byte) (*Beatmap, error) {
return ParseFromString(string(bytes))
}
// ParseFromString parses a beatmap file from the given string.
func ParseFromString(str string) (*Beatmap, error) {
return NewBeatmap(strings.NewReader(str))
}