diff options
author | Kevin Chabowski <kevin@kch42.de> | 2013-08-07 11:36:27 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2013-08-07 11:36:27 +0200 |
commit | fb12de6325e26e2ba1e64276aeed3029ab064a24 (patch) | |
tree | 23a47a79c300f12b99650fa2840807320dd61a47 /nbt | |
parent | e9436211924b03993c6272069d10a917578b1a52 (diff) | |
download | gonbt-fb12de6325e26e2ba1e64276aeed3029ab064a24.tar.gz gonbt-fb12de6325e26e2ba1e64276aeed3029ab064a24.tar.bz2 gonbt-fb12de6325e26e2ba1e64276aeed3029ab064a24.zip |
Some helpers for compressed NBT data.
Diffstat (limited to 'nbt')
-rw-r--r-- | nbt/compressed.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/nbt/compressed.go b/nbt/compressed.go new file mode 100644 index 0000000..3ca31f5 --- /dev/null +++ b/nbt/compressed.go @@ -0,0 +1,37 @@ +package nbt + +import ( + "compress/gzip" + "compress/zlib" + "io" +) + +// Some helpers for reading / writing compressed NBT data, since NBT data is often compressed. + +func ReadGzipdNamedTag(r io.Reader) (Tag, string, error) { + decomp, err := gzip.NewReader(r) + if err != nil { + return Tag{}, "", err + } + + return ReadNamedTag(decomp) +} + +func WriteGzipdNamedTag(w io.Writer, name string, tag Tag) error { + comp := gzip.NewWriter(w) + return WriteNamedTag(comp, name, tag) +} + +func ReadZlibdNamedTag(r io.Reader) (Tag, string, error) { + decomp, err := zlib.NewReader(r) + if err != nil { + return Tag{}, "", err + } + + return ReadNamedTag(decomp) +} + +func WriteZlibdNamedTag(w io.Writer, name string, tag Tag) error { + comp := zlib.NewWriter(w) + return WriteNamedTag(comp, name, tag) +} |