@@ -56,7 +56,7 @@ max_uint(long n)
5656#define MAX_UINT (n ) (uInt)(n)
5757#endif
5858
59- static ID id_dictionaries ;
59+ static ID id_dictionaries , id_read ;
6060
6161/*--------- Prototypes --------*/
6262
@@ -407,6 +407,15 @@ do_checksum(int argc, VALUE *argv, uLong (*func)(uLong, const Bytef*, uInt))
407407 if (NIL_P (str )) {
408408 sum = func (sum , Z_NULL , 0 );
409409 }
410+ else if (rb_obj_is_kind_of (str , rb_cIO )) {
411+ VALUE buf ;
412+ VALUE buflen = INT2NUM (8192 );
413+
414+ while (!NIL_P (buf = rb_funcall (str , id_read , 1 , buflen ))) {
415+ StringValue (buf );
416+ sum = checksum_long (func , sum , (Bytef * )RSTRING_PTR (buf ), RSTRING_LEN (buf ));
417+ }
418+ }
410419 else {
411420 StringValue (str );
412421 sum = checksum_long (func , sum , (Bytef * )RSTRING_PTR (str ), RSTRING_LEN (str ));
@@ -422,6 +431,8 @@ do_checksum(int argc, VALUE *argv, uLong (*func)(uLong, const Bytef*, uInt))
422431 * Calculates Adler-32 checksum for +string+, and returns updated value of
423432 * +adler+. If +string+ is omitted, it returns the Adler-32 initial value. If
424433 * +adler+ is omitted, it assumes that the initial value is given to +adler+.
434+ * If +string+ is an IO instance, reads from the IO until the IO returns nil
435+ * and returns Adler-32 of all read data.
425436 *
426437 * Example usage:
427438 *
@@ -466,7 +477,9 @@ rb_zlib_adler32_combine(VALUE klass, VALUE adler1, VALUE adler2, VALUE len2)
466477 *
467478 * Calculates CRC checksum for +string+, and returns updated value of +crc+. If
468479 * +string+ is omitted, it returns the CRC initial value. If +crc+ is omitted, it
469- * assumes that the initial value is given to +crc+.
480+ * assumes that the initial value is given to +crc+. If +string+ is an IO instance,
481+ * reads from the IO until the IO returns nil and returns CRC checksum of all read
482+ * data.
470483 *
471484 * FIXME: expression.
472485 */
@@ -2198,7 +2211,7 @@ rb_inflate_set_dictionary(VALUE obj, VALUE dic)
21982211#define OS_CODE OS_UNIX
21992212#endif
22002213
2201- static ID id_write , id_read , id_readpartial , id_flush , id_seek , id_close , id_path , id_input ;
2214+ static ID id_write , id_readpartial , id_flush , id_seek , id_close , id_path , id_input ;
22022215static VALUE cGzError , cNoFooter , cCRCError , cLengthError ;
22032216
22042217
0 commit comments