summaryrefslogtreecommitdiff
path: root/ext/zlib
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-01-19 00:06:04 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-01-19 00:06:04 +0000
commit439575890301d6649797002bc5e0739b1be25328 (patch)
tree94c96defdf0ffcc4fbf700b7e5f0cc5f439736b9 /ext/zlib
parent77f3fc305491dab95b02d9d60c5f883f9e5b05df (diff)
* ext/zlib/zlib.c: added Zlib.crc32_combine and Zlib.adler32_combine
* test/zlib/test_zlib.rb: corresponding tests [ruby-core:27551] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26352 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/zlib')
-rw-r--r--ext/zlib/zlib.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index a865cf384f..4de4594df9 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -319,6 +319,21 @@ rb_zlib_adler32(int argc, VALUE *argv, VALUE klass)
}
/*
+ * call-seq: Zlib.adler32_combine(adler1, adler2, len2)
+ *
+ * Combine two Adler-32 check values in to one. +alder1+ is the first Adler-32
+ * value, +adler2+ is the second Adler-32 value. +len2+ is the length of the
+ * string used to generate +adler2+.
+ *
+ */
+static VALUE
+rb_zlib_adler32_combine(VALUE klass, VALUE adler1, VALUE adler2, VALUE len2)
+{
+ return ULONG2NUM(
+ adler32_combine(NUM2ULONG(adler1), NUM2ULONG(adler2), NUM2LONG(len2)));
+}
+
+/*
* call-seq: Zlib.crc32(string, adler)
*
* Calculates CRC checksum for +string+, and returns updated value of +crc+. If
@@ -334,6 +349,21 @@ rb_zlib_crc32(int argc, VALUE *argv, VALUE klass)
}
/*
+ * call-seq: Zlib.crc32_combine(crc1, crc2, len2)
+ *
+ * Combine two CRC-32 check values in to one. +crc1+ is the first CRC-32
+ * value, +crc2+ is the second CRC-32 value. +len2+ is the length of the
+ * string used to generate +crc2+.
+ *
+ */
+static VALUE
+rb_zlib_crc32_combine(VALUE klass, VALUE crc1, VALUE crc2, VALUE len2)
+{
+ return ULONG2NUM(
+ crc32_combine(NUM2ULONG(crc1), NUM2ULONG(crc2), NUM2LONG(len2)));
+}
+
+/*
* Returns the table for calculating CRC checksum as an array.
*/
static VALUE
@@ -3468,7 +3498,9 @@ Init_zlib()
rb_define_module_function(mZlib, "zlib_version", rb_zlib_version, 0);
rb_define_module_function(mZlib, "adler32", rb_zlib_adler32, -1);
+ rb_define_module_function(mZlib, "adler32_combine", rb_zlib_adler32_combine, 3);
rb_define_module_function(mZlib, "crc32", rb_zlib_crc32, -1);
+ rb_define_module_function(mZlib, "crc32_combine", rb_zlib_crc32_combine, 3);
rb_define_module_function(mZlib, "crc_table", rb_zlib_crc_table, 0);
rb_define_const(mZlib, "VERSION", rb_str_new2(RUBY_ZLIB_VERSION));