forked from kdomanski/iso9660
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdir.go
57 lines (45 loc) · 1 KB
/
dir.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
55
56
57
package iso9660
import "bytes"
type itemDir struct {
children map[string]Item
buf *bytes.Buffer
m itemMeta
}
func newDir() *itemDir {
res := &itemDir{
children: make(map[string]Item),
buf: &bytes.Buffer{},
}
return res
}
func (d *itemDir) Read(p []byte) (int, error) {
return d.buf.Read(p)
}
func (d *itemDir) sectors() uint32 {
var sectors uint32
var currentSectorOccupied uint32 = 68 // the 0x00 and 0x01 entries
for name := range d.children {
identifierLen := len(name)
idPaddingLen := (identifierLen + 1) % 2
entryLength := uint32(33 + identifierLen + idPaddingLen)
if currentSectorOccupied+entryLength > sectorSize {
sectors += 1
currentSectorOccupied = entryLength
} else {
currentSectorOccupied += entryLength
}
}
if currentSectorOccupied > 0 {
sectors += 1
}
return sectors
}
func (d *itemDir) Size() int64 {
return int64(d.sectors() * sectorSize)
}
func (d *itemDir) Close() error {
return nil
}
func (d *itemDir) meta() *itemMeta {
return &d.m
}