@@ -56,7 +56,7 @@ max_uint(long n)
56
56
#define MAX_UINT (n ) (uInt)(n)
57
57
#endif
58
58
59
- static ID id_dictionaries ;
59
+ static ID id_dictionaries , id_read ;
60
60
61
61
/*--------- Prototypes --------*/
62
62
@@ -407,6 +407,15 @@ do_checksum(int argc, VALUE *argv, uLong (*func)(uLong, const Bytef*, uInt))
407
407
if (NIL_P (str )) {
408
408
sum = func (sum , Z_NULL , 0 );
409
409
}
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
+ }
410
419
else {
411
420
StringValue (str );
412
421
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))
422
431
* Calculates Adler-32 checksum for +string+, and returns updated value of
423
432
* +adler+. If +string+ is omitted, it returns the Adler-32 initial value. If
424
433
* +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.
425
436
*
426
437
* Example usage:
427
438
*
@@ -466,7 +477,9 @@ rb_zlib_adler32_combine(VALUE klass, VALUE adler1, VALUE adler2, VALUE len2)
466
477
*
467
478
* Calculates CRC checksum for +string+, and returns updated value of +crc+. If
468
479
* +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.
470
483
*
471
484
* FIXME: expression.
472
485
*/
@@ -2198,7 +2211,7 @@ rb_inflate_set_dictionary(VALUE obj, VALUE dic)
2198
2211
#define OS_CODE OS_UNIX
2199
2212
#endif
2200
2213
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 ;
2202
2215
static VALUE cGzError , cNoFooter , cCRCError , cLengthError ;
2203
2216
2204
2217
0 commit comments