forked from quag/mcobj
-
Notifications
You must be signed in to change notification settings - Fork 1
/
world.go
54 lines (44 loc) · 855 Bytes
/
world.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
49
50
51
52
53
54
package main
import (
"io"
"os"
"path"
)
type ChunkOpener interface {
OpenChunk(x, z int) (io.ReadCloser, os.Error)
}
type ChunkPooler interface {
ChunkPool() (ChunkPool, os.Error)
}
type World interface {
ChunkOpener
ChunkPooler
}
type ChunkPool interface {
Pop(x, z int) bool
Remaining() int
}
func OpenWorld(worldDir string, mask ChunkMask) World {
var _, err = os.Stat(path.Join(worldDir, "region"))
if err != nil {
return &AlphaWorld{worldDir, mask}
}
return &BetaWorld{worldDir, mask}
}
type ReadCloserPair struct {
reader io.ReadCloser
closer io.Closer
}
func (r *ReadCloserPair) Read(p []byte) (int, os.Error) {
return r.reader.Read(p)
}
func (r *ReadCloserPair) Close() os.Error {
var (
readerErr = r.reader.Close()
closerErr = r.closer.Close()
)
if closerErr != nil {
return closerErr
}
return readerErr
}