-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
75 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
//go:build cgo | ||
// +build cgo | ||
|
||
package osmpbf | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"fmt" | ||
|
||
"github.com/datadog/czlib" | ||
deflate "github.com/4kills/go-libdeflate/v2" | ||
) | ||
|
||
func zlibReader(data []byte) (io.ReadCloser, error) { | ||
return czlib.NewReader(bytes.NewReader(data)) | ||
func decompress(in []byte, size int, data []byte) ([]byte, error) { | ||
if cap(data) > (int)(size) { | ||
data = data[0:size] | ||
} else { | ||
data = nil | ||
} | ||
|
||
_, buf, err := deflate.DecompressZlib(in, data) | ||
if len(buf) != int(size) { | ||
return nil, fmt.Errorf("raw blob data size %d but expected %d", len(buf), size) | ||
} | ||
|
||
return buf, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,34 @@ | ||
//go:build !cgo | ||
// +build !cgo | ||
|
||
package osmpbf | ||
|
||
import ( | ||
"bytes" | ||
"compress/zlib" | ||
"io" | ||
"fmt" | ||
) | ||
|
||
func zlibReader(data []byte) (io.ReadCloser, error) { | ||
return zlib.NewReader(bytes.NewReader(data)) | ||
func decompress(in []byte, size int, data []byte) ([]byte, error) { | ||
r, err := zlib.NewReader(bytes.NewReader(in)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// using the bytes.Buffer allows for the preallocation of the necessary space. | ||
l := size + bytes.MinRead | ||
if cap(data) < int(l) { | ||
data = make([]byte, 0, l+l/10) | ||
} else { | ||
data = data[:0] | ||
} | ||
buf := bytes.NewBuffer(data) | ||
if _, err = buf.ReadFrom(r); err != nil { | ||
return nil, err | ||
} | ||
|
||
if buf.Len() != int(size) { | ||
return nil, fmt.Errorf("raw blob data size %d but expected %d", buf.Len(), size) | ||
} | ||
return buf.Bytes(), nil | ||
} |