pr-zlib 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +1 -0
- data.tar.gz.sig +1 -0
- data/CHANGES +23 -13
- data/MANIFEST +20 -18
- data/README +52 -42
- data/Rakefile +116 -119
- data/bin/minizip.rb +173 -173
- data/certs/djberg96_pub.pem +21 -0
- data/examples/example_rbzlib.rb +385 -385
- data/lib/pr-zlib.rb +1 -0
- data/lib/pr/rbzlib.rb +5079 -5060
- data/lib/pr/zlib.rb +1567 -1554
- data/pr-zlib.gemspec +24 -22
- data/profile/bench_pr_zlib.rb +43 -43
- data/profile/bench_zlib.rb +43 -43
- data/profile/profile_pr_zlib_read.rb +28 -28
- data/profile/profile_pr_zlib_write.rb +26 -26
- data/test/test_zlib.rb +168 -160
- data/test/test_zlib_gzip_reader.rb +183 -183
- data/test/test_zlib_gzip_writer.rb +186 -184
- data/test/test_zlib_zstream.rb +146 -146
- metadata +41 -9
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d56ad0750e8a018c49c7a60e69394a17a2726b74
|
4
|
+
data.tar.gz: f5c2ba3691a0a6df44b128e0aecd0fa32dadfd55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7a049e78965461d40e160ebb5481c5c53277c8db3bb88f127f8108fe2059731db06b37c1584064339102a053d76c316689a44eceaee885eaa70ff00dae61a12
|
7
|
+
data.tar.gz: fdba625c358fb736e964b921e0c1b6c1698b4601aae61d3b5ba27df5767f96cbf98b9411c894c0215ef7813870491f85a226c4446e28893f6c04636d6e460b88
|
checksums.yaml.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
��&��b���q�s�[ �'��B�{O��@ʵ?���Rχ�6�^�ǖ&�^�ԮlbX��"�ȏ�^/�3��,�[��m�*ڦ}cD���� ��l���w���T����o���WO&u{`{_Ҭ��dV�����r���Ze���+�ےd���#)����xu�����MS����֟� 3��i�v�Nbu�B{&��U��UDbط���.+wIT��]��FH��`�{�L�m���벞��]
|
data.tar.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
��@�H�5X���ˢm�+b��/3�6��z(H�a���V@�Õ������D�F���%b��l����<��h��)�<�Q��6Iae�Nܪmv����nl�b1��V�[s��(س��Fv �i��ڻ+����B.+�<P"�l�ߺ�d���A���J�2�y���\����,��M./�v�������� F���ם[���ږhE*��o1�Sz�1���)�]�1�0�[Mմ�Ѐ��58
|
data/CHANGES
CHANGED
@@ -1,13 +1,23 @@
|
|
1
|
-
= 1.0.
|
2
|
-
*
|
3
|
-
|
4
|
-
|
5
|
-
*
|
6
|
-
*
|
7
|
-
*
|
8
|
-
*
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
= 1.0.3 - 3-Dec-2015
|
2
|
+
* Added a license. This library is now covered under the zlib license.
|
3
|
+
* Some performance tuning. Reads are 2-3 times faster, while writes are
|
4
|
+
about twenty percent faster.
|
5
|
+
* This gem is now signed.
|
6
|
+
* Added a pr-zlib.rb file for convenience.
|
7
|
+
* Use require_relative internally where appropriate.
|
8
|
+
* More stringent value and limit checking added. Thanks go to
|
9
|
+
Chris Seaton for the patches.
|
10
|
+
|
11
|
+
= 1.0.2 - 24-Jun-2015
|
12
|
+
* Fixed a marshalling issue.
|
13
|
+
|
14
|
+
= 1.0.1 - 16-Oct-2014
|
15
|
+
* Added benchmark and profiler scripts and rake tasks.
|
16
|
+
* Switched profiling scripts to use ruby-prof.
|
17
|
+
* The test-unit and ruby-prof libraries are now development dependencies.
|
18
|
+
* Minor updates to eliminate warnings for Ruby 1.9.3 and 2.1.
|
19
|
+
* Some minor test suite updates, mostly for 1.9.3.
|
20
|
+
* Updated the gemspec, removed Rubyforge references.
|
21
|
+
|
22
|
+
= 1.0.0 - 12-Jun-2009
|
23
|
+
* Initial release
|
data/MANIFEST
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
-
CHANGES
|
2
|
-
MANIFEST
|
3
|
-
README
|
4
|
-
pr-zlib.gemspec
|
5
|
-
bin/minizip.rb
|
6
|
-
|
7
|
-
|
8
|
-
lib/pr
|
9
|
-
|
10
|
-
|
11
|
-
test/
|
12
|
-
test/
|
13
|
-
test/
|
14
|
-
test/
|
15
|
-
test/
|
16
|
-
test/
|
17
|
-
test/
|
18
|
-
test/
|
1
|
+
CHANGES
|
2
|
+
MANIFEST
|
3
|
+
README
|
4
|
+
pr-zlib.gemspec
|
5
|
+
bin/minizip.rb
|
6
|
+
certs/djberg96_pub.pem
|
7
|
+
examples/example_rbzlib.rb
|
8
|
+
lib/pr-zlib.rb
|
9
|
+
lib/pr/rbzlib.rb
|
10
|
+
lib/pr/zlib.rb
|
11
|
+
test/test_rbzlib_bytef.rb
|
12
|
+
test/test_rbzlib_posf.rb
|
13
|
+
test/test_rbzlib.rb
|
14
|
+
test/test_zlib_deflate.rb
|
15
|
+
test/test_zlib_gzip_file.rb
|
16
|
+
test/test_zlib_gzip_reader.rb
|
17
|
+
test/test_zlib_gzip_writer.rb
|
18
|
+
test/test_zlib_inflate.rb
|
19
|
+
test/test_zlib_zstream.rb
|
20
|
+
test/test_zlib.rb
|
data/README
CHANGED
@@ -1,42 +1,52 @@
|
|
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
|
-
=
|
40
|
-
|
41
|
-
|
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
|
+
= Caveats
|
40
|
+
You cannot use both this library and the zlib standard library at the same
|
41
|
+
time. If you try to use both there is a good chance you will get an allocation
|
42
|
+
error of some sort. If you already have zlib, you do not need this library.
|
43
|
+
|
44
|
+
= License
|
45
|
+
|
46
|
+
This library is covered under the same license as zlib itself. For the text
|
47
|
+
of the zlib license, please see http://zlib.net/zlib_license.html.
|
48
|
+
|
49
|
+
= Authors
|
50
|
+
|
51
|
+
* Park Heesob (C translation)
|
52
|
+
* Daniel Berger (Testing, packaging, deployment)
|
data/Rakefile
CHANGED
@@ -1,119 +1,116 @@
|
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
+
require 'rubygems/package'
|
21
|
+
spec = eval(IO.read('pr-zlib.gemspec'))
|
22
|
+
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
|
23
|
+
Gem::Package.build(spec, true)
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'Install the pr-zlib gem'
|
27
|
+
task :install => [:create] do
|
28
|
+
file = Dir["*.gem"].first
|
29
|
+
sh "gem install -l #{file}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
namespace :bench do
|
34
|
+
desc "Run the zlib benchmark"
|
35
|
+
task :zlib do
|
36
|
+
Dir.chdir('profile'){ ruby "bench_zlib.rb" }
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Run the pr-zlib benchmark"
|
40
|
+
task :przlib do
|
41
|
+
sh "ruby -Ilib profile/bench_pr_zlib.rb"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
namespace :profile do
|
46
|
+
desc "Run the profiler on the write operation"
|
47
|
+
task :write do
|
48
|
+
sh "ruby -Ilib profile/profile_pr_zlib_write.rb"
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "Run the profiler on the read operation"
|
52
|
+
task :read do
|
53
|
+
sh "ruby -Ilib profile/profile_pr_zlib_read.rb"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
Rake::TestTask.new do |t|
|
58
|
+
t.warning = true
|
59
|
+
t.verbose = true
|
60
|
+
end
|
61
|
+
|
62
|
+
Rake::TestTask.new('test_zlib') do |t|
|
63
|
+
t.warning = true
|
64
|
+
t.verbose = true
|
65
|
+
t.test_files = FileList['test/test_zlib.rb']
|
66
|
+
end
|
67
|
+
|
68
|
+
Rake::TestTask.new('test_gzip_file') do |t|
|
69
|
+
t.warning = true
|
70
|
+
t.verbose = true
|
71
|
+
t.test_files = FileList['test/test_zlib_gzip_file.rb']
|
72
|
+
end
|
73
|
+
|
74
|
+
Rake::TestTask.new('test_gzip_reader') do |t|
|
75
|
+
t.warning = true
|
76
|
+
t.verbose = true
|
77
|
+
t.test_files = FileList['test/test_zlib_gzip_reader.rb']
|
78
|
+
end
|
79
|
+
|
80
|
+
Rake::TestTask.new('test_gzip_writer') do |t|
|
81
|
+
t.warning = true
|
82
|
+
t.verbose = true
|
83
|
+
t.test_files = FileList['test/test_zlib_gzip_writer.rb']
|
84
|
+
end
|
85
|
+
|
86
|
+
Rake::TestTask.new('test_deflate') do |t|
|
87
|
+
t.warning = true
|
88
|
+
t.verbose = true
|
89
|
+
t.test_files = FileList['test/test_zlib_deflate.rb']
|
90
|
+
end
|
91
|
+
|
92
|
+
Rake::TestTask.new('test_inflate') do |t|
|
93
|
+
t.warning = true
|
94
|
+
t.verbose = true
|
95
|
+
t.test_files = FileList['test/test_zlib_inflate.rb']
|
96
|
+
end
|
97
|
+
|
98
|
+
Rake::TestTask.new('test_rbzlib') do |t|
|
99
|
+
t.warning = true
|
100
|
+
t.verbose = true
|
101
|
+
t.test_files = FileList['test/test_rbzlib.rb']
|
102
|
+
end
|
103
|
+
|
104
|
+
Rake::TestTask.new('test_rbzlib_bytef') do |t|
|
105
|
+
t.warning = true
|
106
|
+
t.verbose = true
|
107
|
+
t.test_files = FileList['test/test_rbzlib_bytef.rb']
|
108
|
+
end
|
109
|
+
|
110
|
+
Rake::TestTask.new('test_rbzlib_posf') do |t|
|
111
|
+
t.warning = true
|
112
|
+
t.verbose = true
|
113
|
+
t.test_files = FileList['test/test_rbzlib_posf.rb']
|
114
|
+
end
|
115
|
+
|
116
|
+
task :default => :test
|
data/bin/minizip.rb
CHANGED
@@ -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
|
+
|