1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
package nbt
import (
"compress/gzip"
"compress/zlib"
"io"
)
// Some helpers for reading / writing compressed NBT data, since NBT data is often compressed.
// ReadGzipdNamedTag reads a gzip compressed named tag. See ReadNamedTags for more info.
func ReadGzipdNamedTag(r io.Reader) (Tag, string, error) {
decomp, err := gzip.NewReader(r)
if err != nil {
return Tag{}, "", err
}
return ReadNamedTag(decomp)
}
// WriteGzipdNamedTag writes a gzip compressed named tag. See WriteNamedTag for more info.
func WriteGzipdNamedTag(w io.Writer, name string, tag Tag) (outerr error) {
comp := gzip.NewWriter(w)
defer func(){
err := comp.Close()
if outerr != nil {
outerr = err
}
}()
outerr = WriteNamedTag(comp, name, tag)
return
}
// ReadZlibdNamedTag reads a zlib compressed named tag. See ReadNamedTags for more info.
func ReadZlibdNamedTag(r io.Reader) (Tag, string, error) {
decomp, err := zlib.NewReader(r)
if err != nil {
return Tag{}, "", err
}
return ReadNamedTag(decomp)
}
// WriteZlibdNamedTag writes a zlib compressed named tag. See WriteNamedTag for more info.
func WriteZlibdNamedTag(w io.Writer, name string, tag Tag) (outerr error) {
comp := zlib.NewWriter(w)
defer func(){
err := comp.Close()
if outerr != nil {
outerr = err
}
}()
return WriteNamedTag(comp, name, tag)
}
|