/
creator.go
46 lines (36 loc) · 1.13 KB
/
creator.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
package vpk
import (
"fmt"
"io"
"os"
)
type Creator interface {
// Main creates the main VPK file (*_dir.vpk or no suffix)
Main() (io.WriteCloser, error)
// Archive creates a data-only VPK file (*_###.vpk where # is a digit)
Archive(index int16) (io.WriteCloser, error)
}
type singleVPKCreator string
// SingleVPKCreator implements a Creator for a single-part VPK on the OS
// filesystem.
func SingleVPKCreator(path string) Creator {
return singleVPKCreator(path)
}
func (o singleVPKCreator) Main() (io.WriteCloser, error) {
return os.Create(string(o))
}
func (o singleVPKCreator) Archive(index int16) (io.WriteCloser, error) {
return nil, os.ErrPermission
}
type multiVPKCreator string
// MultiVPKCreator implements a Creator for a multi-part VPK on the OS
// filesystem. prefix should be the part before "_dir.vpk".
func MultiVPKCreator(prefix string) Creator {
return multiVPKCreator(prefix)
}
func (o multiVPKCreator) Main() (io.WriteCloser, error) {
return os.Create(string(o) + "_dir.vpk")
}
func (o multiVPKCreator) Archive(index int16) (io.WriteCloser, error) {
return os.Create(fmt.Sprintf("%s_%03d.vpk", string(o), index))
}