diff options
author | Jeremy Evans <code@jeremyevans.net> | 2020-10-28 10:58:28 -0700 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2020-12-04 19:12:20 +0900 |
commit | bc63ec57e7f965796479f68f6f687187c089bd40 (patch) | |
tree | 7d75a8642f27705e9aa6f3adb4bdb30adaf52e85 /test/zlib | |
parent | a60dfff43470583bbb4474594efde8607f889e8b (diff) |
[ruby/zlib] Allow Zlib.crc32 and .adler32 to accept IO instance
This reads from the IO in 8192 byte chunks, so you don't need to
have the entire string in memory.
Fixes #16
https://github.com/ruby/zlib/commit/ba9793c550
Diffstat (limited to 'test/zlib')
-rw-r--r-- | test/zlib/test_zlib.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb index c58eafe112..c72fe76858 100644 --- a/test/zlib/test_zlib.rb +++ b/test/zlib/test_zlib.rb @@ -1145,6 +1145,19 @@ if defined? Zlib assert_equal(0x02820145, Zlib.adler32("foo")) assert_equal(0x02820145, Zlib.adler32("o", Zlib.adler32("fo"))) assert_equal(0x8a62c964, Zlib.adler32("abc\x01\x02\x03" * 10000)) + Tempfile.create("test_zlib_gzip_file_to_io") {|t| + File.binwrite(t.path, "foo") + t.rewind + assert_equal(0x02820145, Zlib.adler32(t)) + + t.rewind + crc = Zlib.adler32(t.read(2)) + assert_equal(0x02820145, Zlib.adler32(t, crc)) + + File.binwrite(t.path, "abc\x01\x02\x03" * 10000) + t.rewind + assert_equal(0x8a62c964, Zlib.adler32(t)) + } end def test_adler32_combine @@ -1167,6 +1180,19 @@ if defined? Zlib assert_equal(0x8c736521, Zlib.crc32("foo")) assert_equal(0x8c736521, Zlib.crc32("o", Zlib.crc32("fo"))) assert_equal(0x07f0d68f, Zlib.crc32("abc\x01\x02\x03" * 10000)) + Tempfile.create("test_zlib_gzip_file_to_io") {|t| + File.binwrite(t.path, "foo") + t.rewind + assert_equal(0x8c736521, Zlib.crc32(t)) + + t.rewind + crc = Zlib.crc32(t.read(2)) + assert_equal(0x8c736521, Zlib.crc32(t, crc)) + + File.binwrite(t.path, "abc\x01\x02\x03" * 10000) + t.rewind + assert_equal(0x07f0d68f, Zlib.crc32(t)) + } end def test_crc32_combine |