1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-05 09:47:18 -05:00
OpenDiablo2/d2common/d2fileformats/d2mpq/mpq_data_stream.go

29 lines
782 B
Go
Raw Normal View History

package d2mpq
import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
var _ d2interface.DataStream = &MpqDataStream{} // Static check to confirm struct conforms to interface
2020-06-28 22:32:34 -04:00
// MpqDataStream represents a stream for MPQ data.
type MpqDataStream struct {
stream *Stream
}
2020-06-28 22:32:34 -04:00
// Read reads data from the data stream
func (m *MpqDataStream) Read(p []byte) (n int, err error) {
totalRead, err := m.stream.Read(p, 0, uint32(len(p)))
return int(totalRead), err
}
2020-06-28 22:32:34 -04:00
// Seek sets the position of the data stream
func (m *MpqDataStream) Seek(offset int64, whence int) (int64, error) {
m.stream.Position = uint32(offset + int64(whence))
return int64(m.stream.Position), nil
}
2020-06-28 22:32:34 -04:00
// Close closes the data stream
func (m *MpqDataStream) Close() error {
m.stream = nil
return nil
}