pr-zlib 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 942c045dcb34136c2bbf3b77d92f77735482350d
4
- data.tar.gz: 0c2682879c45ee2f5aee7dce9d5fde4b20a00402
3
+ metadata.gz: 88d128ae1c931bb6ef46ce5f8297eb30df761110
4
+ data.tar.gz: 81753965d8afa5125a8be8004f018ead59da4b41
5
5
  SHA512:
6
- metadata.gz: 231ab3d027b37a370fc865d304f2f5a6d6779c829829d3c1d73ad65f635505aba3c7b6a436c8b7acd67f674645f5538ee23daf7e8d33472f4d89e31dc2c14102
7
- data.tar.gz: adebebe6431c37c4705f7a94c86c2b67578a53a9885ab314001c07f2b7f18eecbd9829e9ddb35e9051a8610da15067d2a5c3af99e59ba91fb8d88b3897f73f9a
6
+ metadata.gz: 5478156a77e2ae8c392eda03e8e9d29dd167a8ea76baff7ca8ae5265d70853808f7c668cd931c6267fe78f3756f78ab7702329d0544519b74fb2c27336a3f82c
7
+ data.tar.gz: 10e53487be0b62aadae3ca75ce32a71ecb05fba79b248e5a9e81193458ffd22855a68d7e4e5257aa091d3a3d7034eb74511f4aa65cec7d14d73d9b5148ca4a6c
data/CHANGES CHANGED
@@ -1,10 +1,13 @@
1
- = 1.0.1 - 16-Oct-2014
2
- * Added benchmark and profiler scripts and rake tasks.
3
- * Switched profiling scripts to use ruby-prof.
4
- * The test-unit and ruby-prof libraries are now development dependencies.
5
- * Minor updates to eliminate warnings for Ruby 1.9.3 and 2.1.
6
- * Some minor test suite updates, mostly for 1.9.3.
7
- * Updated the gemspec, removed Rubyforge references.
8
-
9
- = 1.0.0 - 12-Jun-2009
10
- * Initial release
1
+ = 1.0.2 - 24-Jun-2015
2
+ * Fixed a marshalling issue.
3
+
4
+ = 1.0.1 - 16-Oct-2014
5
+ * Added benchmark and profiler scripts and rake tasks.
6
+ * Switched profiling scripts to use ruby-prof.
7
+ * The test-unit and ruby-prof libraries are now development dependencies.
8
+ * Minor updates to eliminate warnings for Ruby 1.9.3 and 2.1.
9
+ * Some minor test suite updates, mostly for 1.9.3.
10
+ * Updated the gemspec, removed Rubyforge references.
11
+
12
+ = 1.0.0 - 12-Jun-2009
13
+ * Initial release
data/MANIFEST CHANGED
@@ -1,18 +1,18 @@
1
- CHANGES
2
- MANIFEST
3
- README
4
- pr-zlib.gemspec
5
- bin/minizip.rb
6
- examples/example_rbzlib.rb
7
- lib/pr/rbzlib.rb
8
- lib/pr/zlib.rb
9
- test/test_rbzlib_bytef.rb
10
- test/test_rbzlib_posf.rb
11
- test/test_rbzlib.rb
12
- test/test_zlib_deflate.rb
13
- test/test_zlib_gzip_file.rb
14
- test/test_zlib_gzip_reader.rb
15
- test/test_zlib_gzip_writer.rb
16
- test/test_zlib_inflate.rb
17
- test/test_zlib_zstream.rb
1
+ CHANGES
2
+ MANIFEST
3
+ README
4
+ pr-zlib.gemspec
5
+ bin/minizip.rb
6
+ examples/example_rbzlib.rb
7
+ lib/pr/rbzlib.rb
8
+ lib/pr/zlib.rb
9
+ test/test_rbzlib_bytef.rb
10
+ test/test_rbzlib_posf.rb
11
+ test/test_rbzlib.rb
12
+ test/test_zlib_deflate.rb
13
+ test/test_zlib_gzip_file.rb
14
+ test/test_zlib_gzip_reader.rb
15
+ test/test_zlib_gzip_writer.rb
16
+ test/test_zlib_inflate.rb
17
+ test/test_zlib_zstream.rb
18
18
  test/test_zlib.rb
data/README CHANGED
@@ -1,42 +1,42 @@
1
- = Description
2
- The pr-zlib library is a pure Ruby version of the zlib compression library.
3
- It consists of both a port of zlib.h and the Ruby zlib library that ships as
4
- part of the standard library.
5
-
6
- = Synopsis
7
-
8
- # Imitating a bit of code used in rubygems
9
- require 'pr/zlib'
10
- require 'stringio'
11
-
12
- data = StringIO.new(data)
13
- Zlib::GzipReader.new(data).read
14
-
15
- = Motivation
16
-
17
- First, building the zlib C library on MS Windows with Visual C++ is very
18
- difficult. However, certain libraries depend on zlib, most notably rubygems.
19
- By providing a pure Ruby version we eliminate any compiler or platform
20
- compatability issues.
21
-
22
- Second, even some Unix distributions, such as Debian, do not ship with
23
- the zlib library by default. By creating a pure Ruby version of the zlib
24
- library we eliminate the need to install a 3rd party C library, and
25
- eliminate a potential weak link in the dependency chain.
26
-
27
- Third, by creating pure Ruby versions of the library and the interface we
28
- are more likely to receive patches, feature requests, documentation updates,
29
- etc, from the Ruby community since not everyone who knows Ruby also knows C.
30
-
31
- Last, the zlib interface that ships as part of the stdlib is a little on the
32
- clunky side. By providing a pure Ruby version, authors can create their own
33
- interface as they see fit.
34
-
35
- = TODO
36
-
37
- More tests, and better tests, are needed for both Rbzlib and Zlib.
38
-
39
- = Authors
40
-
41
- * Park Heesob (C translation)
42
- * Daniel Berger (Testing, packaging, deployment)
1
+ = Description
2
+ The pr-zlib library is a pure Ruby version of the zlib compression library.
3
+ It consists of both a port of zlib.h and the Ruby zlib library that ships as
4
+ part of the standard library.
5
+
6
+ = Synopsis
7
+
8
+ # Imitating a bit of code used in rubygems
9
+ require 'pr/zlib'
10
+ require 'stringio'
11
+
12
+ data = StringIO.new(data)
13
+ Zlib::GzipReader.new(data).read
14
+
15
+ = Motivation
16
+
17
+ First, building the zlib C library on MS Windows with Visual C++ is very
18
+ difficult. However, certain libraries depend on zlib, most notably rubygems.
19
+ By providing a pure Ruby version we eliminate any compiler or platform
20
+ compatability issues.
21
+
22
+ Second, even some Unix distributions, such as Debian, do not ship with
23
+ the zlib library by default. By creating a pure Ruby version of the zlib
24
+ library we eliminate the need to install a 3rd party C library, and
25
+ eliminate a potential weak link in the dependency chain.
26
+
27
+ Third, by creating pure Ruby versions of the library and the interface we
28
+ are more likely to receive patches, feature requests, documentation updates,
29
+ etc, from the Ruby community since not everyone who knows Ruby also knows C.
30
+
31
+ Last, the zlib interface that ships as part of the stdlib is a little on the
32
+ clunky side. By providing a pure Ruby version, authors can create their own
33
+ interface as they see fit.
34
+
35
+ = TODO
36
+
37
+ More tests, and better tests, are needed for both Rbzlib and Zlib.
38
+
39
+ = Authors
40
+
41
+ * Park Heesob (C translation)
42
+ * Daniel Berger (Testing, packaging, deployment)
data/Rakefile CHANGED
@@ -1,119 +1,119 @@
1
- require 'rake'
2
- require 'rake/clean'
3
- require 'rake/testtask'
4
- require 'rbconfig'
5
-
6
- CLEAN.include("**/*.rbc", "**/*.gem", "**/*.txt", "**/*.gz")
7
-
8
- desc 'Install the pr-zlib library as zlib'
9
- task :install_as_zlib do
10
- install_dir = File.join(Config::CONFIG['sitelibdir'], 'pr')
11
- Dir.mkdir(install_dir) unless File.exists?(install_dir)
12
-
13
- cp('lib/pr/zlib.rb', Config::CONFIG['sitelibdir'], :verbose => true)
14
- cp('lib/pr/rbzlib.rb', install_dir, :verbose => true)
15
- end
16
-
17
- namespace :gem do
18
- desc 'Create the pr-zlib gem'
19
- task :create do
20
- spec = eval(IO.read('pr-zlib.gemspec'))
21
- if Gem::VERSION < "2.0"
22
- Gem::Builder.new(spec).build
23
- else
24
- require 'rubygems/package'
25
- Gem::Package.build(spec)
26
- end
27
- end
28
-
29
- desc 'Install the pr-zlib gem'
30
- task :install => [:create] do
31
- file = Dir["*.gem"].first
32
- sh "gem install -l #{file}"
33
- end
34
- end
35
-
36
- namespace :bench do
37
- desc "Run the zlib benchmark"
38
- task :zlib do
39
- Dir.chdir('profile'){ ruby "bench_zlib.rb" }
40
- end
41
-
42
- desc "Run the pr-zlib benchmark"
43
- task :przlib do
44
- sh "ruby -Ilib profile/bench_pr_zlib.rb"
45
- end
46
- end
47
-
48
- namespace :profile do
49
- desc "Run the profiler on the write operation"
50
- task :write do
51
- sh "ruby -Ilib profile/profile_pr_zlib_write.rb"
52
- end
53
-
54
- desc "Run the profiler on the read operation"
55
- task :read do
56
- sh "ruby -Ilib profile/profile_pr_zlib_read.rb"
57
- end
58
- end
59
-
60
- Rake::TestTask.new do |t|
61
- t.warning = true
62
- t.verbose = true
63
- end
64
-
65
- Rake::TestTask.new('test_zlib') do |t|
66
- t.warning = true
67
- t.verbose = true
68
- t.test_files = FileList['test/test_zlib.rb']
69
- end
70
-
71
- Rake::TestTask.new('test_gzip_file') do |t|
72
- t.warning = true
73
- t.verbose = true
74
- t.test_files = FileList['test/test_zlib_gzip_file.rb']
75
- end
76
-
77
- Rake::TestTask.new('test_gzip_reader') do |t|
78
- t.warning = true
79
- t.verbose = true
80
- t.test_files = FileList['test/test_zlib_gzip_reader.rb']
81
- end
82
-
83
- Rake::TestTask.new('test_gzip_writer') do |t|
84
- t.warning = true
85
- t.verbose = true
86
- t.test_files = FileList['test/test_zlib_gzip_writer.rb']
87
- end
88
-
89
- Rake::TestTask.new('test_deflate') do |t|
90
- t.warning = true
91
- t.verbose = true
92
- t.test_files = FileList['test/test_zlib_deflate.rb']
93
- end
94
-
95
- Rake::TestTask.new('test_inflate') do |t|
96
- t.warning = true
97
- t.verbose = true
98
- t.test_files = FileList['test/test_zlib_inflate.rb']
99
- end
100
-
101
- Rake::TestTask.new('test_rbzlib') do |t|
102
- t.warning = true
103
- t.verbose = true
104
- t.test_files = FileList['test/test_rbzlib.rb']
105
- end
106
-
107
- Rake::TestTask.new('test_rbzlib_bytef') do |t|
108
- t.warning = true
109
- t.verbose = true
110
- t.test_files = FileList['test/test_rbzlib_bytef.rb']
111
- end
112
-
113
- Rake::TestTask.new('test_rbzlib_posf') do |t|
114
- t.warning = true
115
- t.verbose = true
116
- t.test_files = FileList['test/test_rbzlib_posf.rb']
117
- end
118
-
119
- task :default => :test
1
+ require 'rake'
2
+ require 'rake/clean'
3
+ require 'rake/testtask'
4
+ require 'rbconfig'
5
+
6
+ CLEAN.include("**/*.rbc", "**/*.gem", "**/*.txt", "**/*.gz")
7
+
8
+ desc 'Install the pr-zlib library as zlib'
9
+ task :install_as_zlib do
10
+ install_dir = File.join(RbConfig::CONFIG['sitelibdir'], 'pr')
11
+ Dir.mkdir(install_dir) unless File.exists?(install_dir)
12
+
13
+ cp('lib/pr/zlib.rb', RbConfig::CONFIG['sitelibdir'], :verbose => true)
14
+ cp('lib/pr/rbzlib.rb', install_dir, :verbose => true)
15
+ end
16
+
17
+ namespace :gem do
18
+ desc 'Create the pr-zlib gem'
19
+ task :create do
20
+ spec = eval(IO.read('pr-zlib.gemspec'))
21
+ if Gem::VERSION < "2.0"
22
+ Gem::Builder.new(spec).build
23
+ else
24
+ require 'rubygems/package'
25
+ Gem::Package.build(spec)
26
+ end
27
+ end
28
+
29
+ desc 'Install the pr-zlib gem'
30
+ task :install => [:create] do
31
+ file = Dir["*.gem"].first
32
+ sh "gem install -l #{file}"
33
+ end
34
+ end
35
+
36
+ namespace :bench do
37
+ desc "Run the zlib benchmark"
38
+ task :zlib do
39
+ Dir.chdir('profile'){ ruby "bench_zlib.rb" }
40
+ end
41
+
42
+ desc "Run the pr-zlib benchmark"
43
+ task :przlib do
44
+ sh "ruby -Ilib profile/bench_pr_zlib.rb"
45
+ end
46
+ end
47
+
48
+ namespace :profile do
49
+ desc "Run the profiler on the write operation"
50
+ task :write do
51
+ sh "ruby -Ilib profile/profile_pr_zlib_write.rb"
52
+ end
53
+
54
+ desc "Run the profiler on the read operation"
55
+ task :read do
56
+ sh "ruby -Ilib profile/profile_pr_zlib_read.rb"
57
+ end
58
+ end
59
+
60
+ Rake::TestTask.new do |t|
61
+ t.warning = true
62
+ t.verbose = true
63
+ end
64
+
65
+ Rake::TestTask.new('test_zlib') do |t|
66
+ t.warning = true
67
+ t.verbose = true
68
+ t.test_files = FileList['test/test_zlib.rb']
69
+ end
70
+
71
+ Rake::TestTask.new('test_gzip_file') do |t|
72
+ t.warning = true
73
+ t.verbose = true
74
+ t.test_files = FileList['test/test_zlib_gzip_file.rb']
75
+ end
76
+
77
+ Rake::TestTask.new('test_gzip_reader') do |t|
78
+ t.warning = true
79
+ t.verbose = true
80
+ t.test_files = FileList['test/test_zlib_gzip_reader.rb']
81
+ end
82
+
83
+ Rake::TestTask.new('test_gzip_writer') do |t|
84
+ t.warning = true
85
+ t.verbose = true
86
+ t.test_files = FileList['test/test_zlib_gzip_writer.rb']
87
+ end
88
+
89
+ Rake::TestTask.new('test_deflate') do |t|
90
+ t.warning = true
91
+ t.verbose = true
92
+ t.test_files = FileList['test/test_zlib_deflate.rb']
93
+ end
94
+
95
+ Rake::TestTask.new('test_inflate') do |t|
96
+ t.warning = true
97
+ t.verbose = true
98
+ t.test_files = FileList['test/test_zlib_inflate.rb']
99
+ end
100
+
101
+ Rake::TestTask.new('test_rbzlib') do |t|
102
+ t.warning = true
103
+ t.verbose = true
104
+ t.test_files = FileList['test/test_rbzlib.rb']
105
+ end
106
+
107
+ Rake::TestTask.new('test_rbzlib_bytef') do |t|
108
+ t.warning = true
109
+ t.verbose = true
110
+ t.test_files = FileList['test/test_rbzlib_bytef.rb']
111
+ end
112
+
113
+ Rake::TestTask.new('test_rbzlib_posf') do |t|
114
+ t.warning = true
115
+ t.verbose = true
116
+ t.test_files = FileList['test/test_rbzlib_posf.rb']
117
+ end
118
+
119
+ task :default => :test
@@ -1,173 +1,173 @@
1
- # minigzip.rb -- simulate gzip using the zlib compression library
2
- # Copyright (C) 1995-2005 Jean-loup Gailly.
3
- # For conditions of distribution and use, see copyright notice in rbzlib.rb
4
- #
5
- #
6
- #
7
- # minigzip is a minimal implementation of the gzip utility. This is
8
- # only an example of using zlib and isn't meant to replace the
9
- # full-featured gzip. No attempt is made to deal with file systems
10
- # limiting names to 14 or 8+3 characters, etc... Error checking is
11
- # very limited. So use minigzip only for testing; use gzip for the
12
- # real thing. On MSDOS, use only on file names without extension
13
- # or in pipe mode.
14
- #
15
- # Ruby tralnslation By Park Heesob.
16
-
17
- require 'rbzlib'
18
- include Rbzlib
19
-
20
- GZ_SUFFIX = ".gz"
21
- SUFFIX_LEN = GZ_SUFFIX.length
22
-
23
- BUFLEN = 16384
24
- MAX_NAME_LEN = 1024
25
-
26
-
27
- def error(msg)
28
- puts("#{__FILE__}: #{msg}")
29
- exit(1)
30
- end
31
-
32
- def gz_compress(_in, out)
33
- while(true)
34
- begin
35
- buf = _in.read(BUFLEN)
36
- rescue
37
- raise RuntimeError,"read"
38
- end
39
- break if buf.nil?
40
- err = 0
41
- len = buf.length
42
- if (gzwrite(out, buf, len) != len)
43
- error(gzerror(out, err))
44
- end
45
- end
46
- _in.close
47
- error("failed gzclose") if (gzclose(out) != Z_OK)
48
- end
49
-
50
-
51
- def gz_uncompress(_in, out)
52
- buf = 0.chr * BUFLEN
53
- while true
54
- len = gzread(_in, buf, buf.length)
55
- err = 0
56
- error(gzerror(_in, err)) if (len < 0)
57
- break if len.zero?
58
- if(out.write(buf[0,len]) != len)
59
- error("failed write")
60
- end
61
- end
62
- begin
63
- out.close
64
- rescue
65
- error("failed fclose")
66
- end
67
-
68
- error("failed gzclose") if (gzclose(_in) != Z_OK)
69
- end
70
-
71
-
72
- def file_compress(file, mode)
73
- outfile = file + GZ_SUFFIX
74
-
75
- _in = File.open(file, "rb")
76
- if _in.nil?
77
- raise RuntimeError,file
78
- end
79
- out = gzopen(outfile, mode)
80
- if out.nil?
81
- puts("#{__FILE__}: can't gzopen #{outfile}")
82
- exit(1)
83
- end
84
- gz_compress(_in, out)
85
-
86
- File.unlink(file)
87
- end
88
-
89
-
90
- def file_uncompress(file)
91
- len = file.length
92
- buf = file.dup
93
-
94
- if (file[-SUFFIX_LEN..-1] == GZ_SUFFIX)
95
- infile = file.dup
96
- outfile = buf[0..(-SUFFIX_LEN-1)]
97
- else
98
- outfile = file.dup
99
- infile = buf + GZ_SUFFIX
100
- end
101
- _in = gzopen(infile, "rb")
102
- if _in.nil?
103
- puts("#{__FILE__}: can't gzopen #{infile}")
104
- exit(1)
105
- end
106
- out = File.open(outfile, "wb")
107
- if out.nil?
108
- raise RuntimeError,file
109
- exit(1)
110
- end
111
-
112
- gz_uncompress(_in, out)
113
-
114
- File.unlink(infile)
115
- end
116
-
117
-
118
- #===========================================================================
119
- # Usage: minigzip [-d] [-f] [-h] [-r] [-1 to -9] [files...]
120
- # -d : decompress
121
- # -f : compress with Z_FILTERED
122
- # -h : compress with Z_HUFFMAN_ONLY
123
- # -r : compress with Z_RLE
124
- # -1 to -9 : compression level
125
- #
126
-
127
- uncompr = false
128
-
129
- outmode = "wb6 "
130
-
131
- while !ARGV.empty?
132
- argv = ARGV.shift
133
- case argv
134
- when "-d"
135
- uncompr = true
136
- when "-f"
137
- outmode[3] = 'f'
138
- when "-h"
139
- outmode[3] = 'h'
140
- when "-r"
141
- outmode[3] = 'R'
142
- when "-1".."-9"
143
- outmode[2] = argv[1]
144
- else
145
- ARGV.unshift(argv)
146
- break
147
- end
148
- end
149
- if (outmode[3].chr == ' ')
150
- outmode = outmode[0,3]
151
- end
152
- if (ARGV.empty?)
153
- $stdin.binmode
154
- $stdout.binmode
155
- if (uncompr)
156
- file = gzdopen($stdin.fileno, "rb")
157
- error("can't gzdopen stdin") if file.nil?
158
- gz_uncompress(file, $stdout)
159
- else
160
- file = gzdopen($stdout.fileno, outmode)
161
- error("can't gzdopen stdout") if file.nil?
162
- gz_compress($stdin, file)
163
- end
164
- else
165
- while !ARGV.empty?
166
- if (uncompr)
167
- file_uncompress(ARGV.shift)
168
- else
169
- file_compress(ARGV.shift, outmode)
170
- end
171
- end
172
- end
173
-
1
+ # minigzip.rb -- simulate gzip using the zlib compression library
2
+ # Copyright (C) 1995-2005 Jean-loup Gailly.
3
+ # For conditions of distribution and use, see copyright notice in rbzlib.rb
4
+ #
5
+ #
6
+ #
7
+ # minigzip is a minimal implementation of the gzip utility. This is
8
+ # only an example of using zlib and isn't meant to replace the
9
+ # full-featured gzip. No attempt is made to deal with file systems
10
+ # limiting names to 14 or 8+3 characters, etc... Error checking is
11
+ # very limited. So use minigzip only for testing; use gzip for the
12
+ # real thing. On MSDOS, use only on file names without extension
13
+ # or in pipe mode.
14
+ #
15
+ # Ruby tralnslation By Park Heesob.
16
+
17
+ require 'rbzlib'
18
+ include Rbzlib
19
+
20
+ GZ_SUFFIX = ".gz"
21
+ SUFFIX_LEN = GZ_SUFFIX.length
22
+
23
+ BUFLEN = 16384
24
+ MAX_NAME_LEN = 1024
25
+
26
+
27
+ def error(msg)
28
+ puts("#{__FILE__}: #{msg}")
29
+ exit(1)
30
+ end
31
+
32
+ def gz_compress(_in, out)
33
+ while(true)
34
+ begin
35
+ buf = _in.read(BUFLEN)
36
+ rescue
37
+ raise RuntimeError,"read"
38
+ end
39
+ break if buf.nil?
40
+ err = 0
41
+ len = buf.length
42
+ if (gzwrite(out, buf, len) != len)
43
+ error(gzerror(out, err))
44
+ end
45
+ end
46
+ _in.close
47
+ error("failed gzclose") if (gzclose(out) != Z_OK)
48
+ end
49
+
50
+
51
+ def gz_uncompress(_in, out)
52
+ buf = 0.chr * BUFLEN
53
+ while true
54
+ len = gzread(_in, buf, buf.length)
55
+ err = 0
56
+ error(gzerror(_in, err)) if (len < 0)
57
+ break if len.zero?
58
+ if(out.write(buf[0,len]) != len)
59
+ error("failed write")
60
+ end
61
+ end
62
+ begin
63
+ out.close
64
+ rescue
65
+ error("failed fclose")
66
+ end
67
+
68
+ error("failed gzclose") if (gzclose(_in) != Z_OK)
69
+ end
70
+
71
+
72
+ def file_compress(file, mode)
73
+ outfile = file + GZ_SUFFIX
74
+
75
+ _in = File.open(file, "rb")
76
+ if _in.nil?
77
+ raise RuntimeError,file
78
+ end
79
+ out = gzopen(outfile, mode)
80
+ if out.nil?
81
+ puts("#{__FILE__}: can't gzopen #{outfile}")
82
+ exit(1)
83
+ end
84
+ gz_compress(_in, out)
85
+
86
+ File.unlink(file)
87
+ end
88
+
89
+
90
+ def file_uncompress(file)
91
+ len = file.length
92
+ buf = file.dup
93
+
94
+ if (file[-SUFFIX_LEN..-1] == GZ_SUFFIX)
95
+ infile = file.dup
96
+ outfile = buf[0..(-SUFFIX_LEN-1)]
97
+ else
98
+ outfile = file.dup
99
+ infile = buf + GZ_SUFFIX
100
+ end
101
+ _in = gzopen(infile, "rb")
102
+ if _in.nil?
103
+ puts("#{__FILE__}: can't gzopen #{infile}")
104
+ exit(1)
105
+ end
106
+ out = File.open(outfile, "wb")
107
+ if out.nil?
108
+ raise RuntimeError,file
109
+ exit(1)
110
+ end
111
+
112
+ gz_uncompress(_in, out)
113
+
114
+ File.unlink(infile)
115
+ end
116
+
117
+
118
+ #===========================================================================
119
+ # Usage: minigzip [-d] [-f] [-h] [-r] [-1 to -9] [files...]
120
+ # -d : decompress
121
+ # -f : compress with Z_FILTERED
122
+ # -h : compress with Z_HUFFMAN_ONLY
123
+ # -r : compress with Z_RLE
124
+ # -1 to -9 : compression level
125
+ #
126
+
127
+ uncompr = false
128
+
129
+ outmode = "wb6 "
130
+
131
+ while !ARGV.empty?
132
+ argv = ARGV.shift
133
+ case argv
134
+ when "-d"
135
+ uncompr = true
136
+ when "-f"
137
+ outmode[3] = 'f'
138
+ when "-h"
139
+ outmode[3] = 'h'
140
+ when "-r"
141
+ outmode[3] = 'R'
142
+ when "-1".."-9"
143
+ outmode[2] = argv[1]
144
+ else
145
+ ARGV.unshift(argv)
146
+ break
147
+ end
148
+ end
149
+ if (outmode[3].chr == ' ')
150
+ outmode = outmode[0,3]
151
+ end
152
+ if (ARGV.empty?)
153
+ $stdin.binmode
154
+ $stdout.binmode
155
+ if (uncompr)
156
+ file = gzdopen($stdin.fileno, "rb")
157
+ error("can't gzdopen stdin") if file.nil?
158
+ gz_uncompress(file, $stdout)
159
+ else
160
+ file = gzdopen($stdout.fileno, outmode)
161
+ error("can't gzdopen stdout") if file.nil?
162
+ gz_compress($stdin, file)
163
+ end
164
+ else
165
+ while !ARGV.empty?
166
+ if (uncompr)
167
+ file_uncompress(ARGV.shift)
168
+ else
169
+ file_compress(ARGV.shift, outmode)
170
+ end
171
+ end
172
+ end
173
+