-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
48 lines (41 loc) · 778 Bytes
/
util.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
40
41
42
43
44
45
46
47
48
package main
import (
"encoding/binary"
"io"
"os"
)
func pathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return true, err
}
func readByte(r io.Reader) uint32 {
b := []byte{0}
io.ReadFull(r, b)
return uint32(b[0])
}
func read16(r io.Reader) uint32 {
var v uint16
binary.Read(r, binary.BigEndian, &v)
return uint32(v)
}
func read24(r io.Reader) uint32 {
b := []byte{0, 0, 0}
io.ReadFull(r, b)
return (uint32(b[0]) << 16) | (uint32(b[1]) << 8) | uint32(b[2])
}
func read32(r io.Reader) uint32 {
var v uint32
binary.Read(r, binary.BigEndian, &v)
return v
}
func read64(r io.Reader) uint64 {
var v uint64
binary.Read(r, binary.BigEndian, &v)
return v
}