From ec17fcf3e6caa181172d145eb26fdf7a59c06456 Mon Sep 17 00:00:00 2001 From: Intyre Date: Mon, 22 Jun 2020 00:43:30 +0200 Subject: [PATCH] Replaced bufio.NewReader with File.Read (#375) --- d2common/d2fileformats/d2mpq/mpq_stream.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/d2common/d2fileformats/d2mpq/mpq_stream.go b/d2common/d2fileformats/d2mpq/mpq_stream.go index 1868e5f7..fca933b2 100644 --- a/d2common/d2fileformats/d2mpq/mpq_stream.go +++ b/d2common/d2fileformats/d2mpq/mpq_stream.go @@ -1,7 +1,6 @@ package d2mpq import ( - "bufio" "bytes" "compress/zlib" "encoding/binary" @@ -58,9 +57,8 @@ func (v *Stream) loadBlockOffsets() error { blockPositionCount := ((v.BlockTableEntry.UncompressedFileSize + v.BlockSize - 1) / v.BlockSize) + 1 v.BlockPositions = make([]uint32, blockPositionCount) v.MPQData.File.Seek(int64(v.BlockTableEntry.FilePosition), 0) - reader := bufio.NewReader(v.MPQData.File) mpqBytes := make([]byte, blockPositionCount*4) - reader.Read(mpqBytes) + v.MPQData.File.Read(mpqBytes) for i := range v.BlockPositions { idx := i * 4 v.BlockPositions[i] = binary.LittleEndian.Uint32(mpqBytes[idx : idx+4]) @@ -135,9 +133,7 @@ func (v *Stream) bufferData() { func (v *Stream) loadSingleUnit() { fileData := make([]byte, v.BlockSize) v.MPQData.File.Seek(int64(v.MPQData.Data.HeaderSize), 0) - //binary.Read(v.MPQData.File, binary.LittleEndian, &fileData) - reader := bufio.NewReader(v.MPQData.File) - reader.Read(fileData) + v.MPQData.File.Read(fileData) if v.BlockSize == v.BlockTableEntry.UncompressedFileSize { v.CurrentData = fileData return @@ -160,9 +156,7 @@ func (v *Stream) loadBlock(blockIndex, expectedLength uint32) []byte { offset += v.BlockTableEntry.FilePosition data := make([]byte, toRead) v.MPQData.File.Seek(int64(offset), 0) - //binary.Read(v.MPQData.File, binary.LittleEndian, &data) - reader := bufio.NewReader(v.MPQData.File) - reader.Read(data) + v.MPQData.File.Read(data) if v.BlockTableEntry.HasFlag(FileEncrypted) && v.BlockTableEntry.UncompressedFileSize > 3 { if v.EncryptionSeed == 0 { panic("Unable to determine encryption key")