From fb12de6325e26e2ba1e64276aeed3029ab064a24 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Wed, 7 Aug 2013 11:36:27 +0200 Subject: Some helpers for compressed NBT data. --- nbt/compressed.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 nbt/compressed.go (limited to 'nbt') 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) +} -- cgit v1.2.3-70-g09d2