summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nbt/compressed.go37
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)
+}