lib/avro/data_file.rb in avro-1.9.2 vs lib/avro/data_file.rb in avro-1.10.0
- old
+ new
@@ -370,12 +370,35 @@
rescue LoadError
raise LoadError, "Snappy compression is not available, please install the `snappy` gem."
end
end
+ class ZstandardCodec
+ def codec_name; 'zstandard'; end
+
+ def decompress(data)
+ load_zstandard!
+ Zstd.decompress(data)
+ end
+
+ def compress(data)
+ load_zstandard!
+ Zstd.compress(data)
+ end
+
+ private
+
+ def load_zstandard!
+ require 'zstd-ruby' unless defined?(Zstd)
+ rescue LoadError
+ raise LoadError, "Zstandard compression is not available, please install the `zstd-ruby` gem."
+ end
+ end
+
DataFile.register_codec NullCodec
DataFile.register_codec DeflateCodec
DataFile.register_codec SnappyCodec
+ DataFile.register_codec ZstandardCodec
# TODO this constant won't be updated if you register another codec.
# Deprecated in favor of Avro::DataFile::codecs
VALID_CODECS = DataFile.codecs.keys
end