-
Notifications
You must be signed in to change notification settings - Fork 1
/
stream.go
71 lines (60 loc) · 1.63 KB
/
stream.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package cfb
import "fmt"
type Stream struct {
d *DirectoryEntry
r *SectorReader
}
func (d *DirectoryEntry) stream() (*Stream, error) {
if d.Type() != StreamObject {
return nil, ErrWrongObjectType
}
var sr *SectorReader
if d.Size() < uint64(d.f.header.raw.MiniStreamCutoffSize) {
tsr, err := newSectorReader(d.f.r, d.f.header.SectorSize(), d.f.directoryEntries[0].StartingSector(), d.f.fat, func(sector uint32) int64 {
return int64((sector + 1) * d.f.header.SectorSize())
})
if err != nil {
return nil, err
}
sr, err = newSectorReader(tsr, d.f.header.MiniSectorSize(), d.StartingSector(), d.f.minifat, func(sector uint32) int64 {
return int64(sector * d.f.header.MiniSectorSize())
})
if err != nil {
return nil, err
}
} else {
var err error
sr, err = newSectorReader(d.f.r, d.f.header.SectorSize(), d.StartingSector(), d.f.fat, func(sector uint32) int64 {
return int64((sector + 1) * d.f.header.SectorSize())
})
if err != nil {
return nil, err
}
}
sr.maxOffset = int64(d.Size())
return &Stream{d, sr}, nil
}
func (s *Stream) String() string {
return fmt.Sprintf("Stream{Path:%q Size:%d}", s.Path(), s.Size())
}
func (s *Stream) Name() string {
return s.d.Name()
}
func (s *Stream) Path() string {
return s.d.Path()
}
func (s *Stream) Type() ObjectType {
return StreamObject
}
func (s *Stream) Size() uint64 {
return s.d.Size()
}
func (s *Stream) ReadAt(b []byte, offset int64) (int, error) {
return s.r.ReadAt(b, offset)
}
func (s *Stream) Seek(offset int64, whence int) (int64, error) {
return s.r.Seek(offset, whence)
}
func (s *Stream) Read(b []byte) (int, error) {
return s.r.Read(b)
}