1
0
forked from MTSR/mapserver

working zlib offset

This commit is contained in:
Thomas Rudin 2019-01-06 19:48:13 +01:00
parent 9b4df6099d
commit 730fb15248
2 changed files with 25 additions and 18 deletions

View File

@ -0,0 +1,22 @@
package mapblockparser
import (
"bytes"
)
type CountedReader struct {
Reader *bytes.Reader
Count int
}
func (r *CountedReader) Read(p []byte) (int, error){
i,err := r.Reader.Read(p)
r.Count += i
return i, err
}
func (r *CountedReader) ReadByte() (byte, error){
i,err := r.Reader.ReadByte()
r.Count++
return i, err
}

View File

@ -21,27 +21,12 @@ func readU16(data []byte, offset int){
func readU32(data []byte, offset int){
}
type CountedReader struct {
reader io.Reader
Count int
}
func (r *CountedReader) Read(p []byte) (int, error){
i,err := r.reader.Read(p)
r.Count += i
return i,err
}
func (r *CountedReader) ReadByte() (byte, error){
r.Count++;
return r.reader.ReadByte()
}
func parseMapdata(mapblock *MapBlock, data []byte) (int, error) {
r := bytes.NewReader(data)
cr := new(CountedReader)
cr.reader = r
cr.Reader = r
z, err := zlib.NewReader(cr)
if err != nil {
@ -66,7 +51,7 @@ func parseMetadata(mapblock *MapBlock, data []byte) (int, error) {
r := bytes.NewReader(data)
cr := new(CountedReader)
cr.reader = r
cr.Reader = r
z, err := zlib.NewReader(cr)
if err != nil {
@ -78,7 +63,7 @@ func parseMetadata(mapblock *MapBlock, data []byte) (int, error) {
buf := new(bytes.Buffer)
io.Copy(buf, z)
log.Println("Metadata length ", buf.Len())
log.Println("Metadata length ", buf.Len(), buf.String())
return cr.Count, nil
}