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