-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsegment.go
More file actions
27 lines (22 loc) · 789 Bytes
/
Copy pathsegment.go
File metadata and controls
27 lines (22 loc) · 789 Bytes
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
package pego
import "io"
// Segment represents a contiguous region of bytes within a PE file.
type Segment struct {
reader *io.SectionReader
}
// NewSegment creates a Segment of the given size at the current offset and advances the offset.
func NewSegment(reader io.ReaderAt, offset *int64, size int64) *Segment {
r := io.NewSectionReader(reader, *offset, size)
*offset += size
return &Segment{reader: r}
}
// Size returns the size of the segment in bytes.
func (s *Segment) Size() int64 {
return s.reader.Size()
}
// Write copies the segment data to the writer.
func (s *Segment) Write(writer io.Writer) error {
// Make a copy of the section reader so that we don't change the offset.
_, err := io.Copy(writer, io.NewSectionReader(s.reader, 0, s.reader.Size()))
return err
}