summaryrefslogtreecommitdiff
path: root/test/zlib
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-10-28 10:58:28 -0700
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-12-04 19:12:20 +0900
commitbc63ec57e7f965796479f68f6f687187c089bd40 (patch)
tree7d75a8642f27705e9aa6f3adb4bdb30adaf52e85 /test/zlib
parenta60dfff43470583bbb4474594efde8607f889e8b (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.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb
index c58eafe..c72fe76 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