Skip to content

Instantly share code, notes, and snippets.

@AlexMooney
Last active January 25, 2019 17:52
Show Gist options
  • Save AlexMooney/2e933a0c89ed905669c066c2e78f082f to your computer and use it in GitHub Desktop.
Save AlexMooney/2e933a0c89ed905669c066c2e78f082f to your computer and use it in GitHub Desktop.
GzipReader test

Test GzipReader

Clone the gist and execute gzip_reader_test.rb.

Ruby tested:

  1. ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin18]

Gzip tested:

  1. Apple gzip 272.220.1
  2. gzip 1.10
$ ./gzip_reader.rb
Traceback (most recent call last):
	6: from ./gzip_reader.rb:17:in `<main>'
	5: from ./gzip_reader.rb:17:in `open'
	4: from ./gzip_reader.rb:18:in `block in <main>'
	3: from /Users/amooney/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/test-unit-3.2.9/lib/test/unit/assertions.rb:240:in `assert_equal'
	2: from /Users/amooney/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/test-unit-3.2.9/lib/test/unit/assertions.rb:53:in `assert_block'
	1: from /Users/amooney/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/test-unit-3.2.9/lib/test/unit/assertions.rb:1636:in `_wrap_assertion'
/Users/amooney/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/test-unit-3.2.9/lib/test/unit/assertions.rb:55:in `block in assert_block': <"hello world\n"> expected but was (Test::Unit::AssertionFailedError)
<"hello ">.
#!/usr/bin/env ruby
require 'zlib'
require 'test/unit/assertions'
include Test::Unit::Assertions
system('./make_zips.sh')
Zlib::GzipReader.open('hello.txt.gz') do |gz|
assert_equal(`gzip -dc hello.txt.gz`, gz.read)
end
Zlib::GzipReader.open('world.txt.gz') do |gz|
assert_equal(`gzip -dc world.txt.gz`, gz.read)
end
Zlib::GzipReader.open('hello_world.txt.gz') do |gz|
assert_equal(`gzip -dc hello_world.txt.gz`, gz.read)
end
#!/usr/bin/env bash
set -euo pipefail
echo -n 'hello ' | gzip -c - > hello.txt.gz
echo 'world' | gzip -c - > world.txt.gz
cat hello.txt.gz world.txt.gz > hello_world.txt.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment