rubyzip 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubyzip might be problematic. Click here for more details.

Files changed (45) hide show
  1. data/{README → README.md} +16 -17
  2. data/Rakefile +6 -104
  3. data/lib/zip/compressor.rb +10 -0
  4. data/lib/zip/constants.rb +10 -0
  5. data/lib/zip/decompressor.rb +13 -0
  6. data/lib/zip/deflater.rb +30 -0
  7. data/lib/zip/inflater.rb +65 -0
  8. data/lib/zip/ioextras.rb +35 -36
  9. data/lib/zip/null_compressor.rb +15 -0
  10. data/lib/zip/null_decompressor.rb +25 -0
  11. data/lib/zip/null_input_stream.rb +9 -0
  12. data/lib/zip/pass_thru_compressor.rb +23 -0
  13. data/lib/zip/pass_thru_decompressor.rb +40 -0
  14. data/lib/zip/stdrubyext.rb +10 -44
  15. data/lib/zip/zip.rb +22 -1848
  16. data/lib/zip/zip_central_directory.rb +139 -0
  17. data/lib/zip/zip_entry.rb +639 -0
  18. data/lib/zip/zip_entry_set.rb +66 -0
  19. data/lib/zip/zip_extra_field.rb +213 -0
  20. data/lib/zip/zip_file.rb +318 -0
  21. data/lib/zip/zip_input_stream.rb +134 -0
  22. data/lib/zip/zip_output_stream.rb +172 -0
  23. data/lib/zip/zip_streamable_directory.rb +15 -0
  24. data/lib/zip/zip_streamable_stream.rb +47 -0
  25. data/lib/zip/zipfilesystem.rb +90 -88
  26. data/samples/example_recursive.rb +49 -0
  27. metadata +54 -60
  28. data/ChangeLog +0 -1146
  29. data/install.rb +0 -23
  30. data/lib/zip/ziprequire.rb +0 -90
  31. data/test/alltests.rb +0 -9
  32. data/test/data/file1.txt +0 -46
  33. data/test/data/file1.txt.deflatedData +0 -0
  34. data/test/data/file2.txt +0 -1504
  35. data/test/data/notzippedruby.rb +0 -7
  36. data/test/data/rubycode.zip +0 -0
  37. data/test/data/rubycode2.zip +0 -0
  38. data/test/data/testDirectory.bin +0 -0
  39. data/test/data/zipWithDirs.zip +0 -0
  40. data/test/gentestfiles.rb +0 -157
  41. data/test/ioextrastest.rb +0 -208
  42. data/test/stdrubyexttest.rb +0 -52
  43. data/test/zipfilesystemtest.rb +0 -841
  44. data/test/ziprequiretest.rb +0 -43
  45. data/test/ziptest.rb +0 -1620
@@ -1,24 +1,22 @@
1
- = rubyzip
1
+ rubyzip
2
+ =======
2
3
 
3
4
  rubyzip is a ruby library for reading and writing zip files.
4
5
 
5
- = Install
6
-
7
- If you have rubygems you can install rubyzip directly from the gem
8
- repository
6
+ Install
7
+ -------
9
8
 
10
9
  gem install rubyzip
11
10
 
12
- Otherwise obtain the source (see below) and run
13
-
14
- ruby install.rb
15
11
 
16
12
  To run the unit tests you need to have test::unit installed
17
13
 
18
14
  rake test
15
+ [![Build Status](https://secure.travis-ci.org/aussiegeek/rubyzip.png)](http://travis-ci.org/aussiegeek/rubyzip)
19
16
 
17
+ Documentation
18
+ -------------
20
19
 
21
- = Documentation
22
20
 
23
21
  There is more than one way to access or create a zip archive with
24
22
  rubyzip. The basic API is modeled after the classes in
@@ -47,23 +45,24 @@ For details about the specific behaviour of classes and methods refer
47
45
  to the test suite. Finally you can generate the rdoc documentation or
48
46
  visit http://rubyzip.sourceforge.net.
49
47
 
50
- = License
48
+ License
49
+ -------
51
50
 
52
51
  rubyzip is distributed under the same license as ruby. See
53
52
  http://www.ruby-lang.org/en/LICENSE.txt
54
53
 
55
54
 
56
- = Website and Project Home
57
-
58
- http://rubyzip.sourceforge.net
55
+ Website and Project Home
56
+ ------------------------
59
57
 
60
- http://sourceforge.net/projects/rubyzip
58
+ http://github.com/aussiegeek/rubyzip
61
59
 
62
- == Download (tarballs and gems)
60
+ http://rdoc.info/github/aussiegeek/rubyzip/master/frames
63
61
 
64
- http://sourceforge.net/project/showfiles.php?group_id=43107&package_id=35377
62
+ Authors
63
+ -------
65
64
 
66
- = Authors
65
+ Alan Harper ( alan at aussiegeek.net)
67
66
 
68
67
  Thomas Sondergaard (thomas at sondergaard.cc)
69
68
 
data/Rakefile CHANGED
@@ -1,111 +1,13 @@
1
- # Rakefile for RubyGems -*- ruby -*-
2
-
3
1
  require 'rubygems'
4
- require 'rake/clean'
5
2
  require 'rake/testtask'
6
- require 'rake/packagetask'
7
- require 'rake/gempackagetask'
8
- require 'rake/rdoctask'
9
- require 'rake/contrib/sshpublisher'
10
- require 'net/sftp'
11
-
12
- PKG_NAME = 'rubyzip'
13
- PKG_VERSION = File.read('lib/zip/zip.rb').match(/\s+VERSION\s*=\s*'(.*)'/)[1]
14
-
15
- PKG_FILES = FileList.new
16
-
17
- PKG_FILES.add %w{ README NEWS TODO ChangeLog install.rb Rakefile }
18
- PKG_FILES.add %w{ samples/*.rb }
19
- PKG_FILES.add %w{ test/*.rb }
20
- PKG_FILES.add %w{ test/data/* }
21
- PKG_FILES.exclude "test/data/generated"
22
- PKG_FILES.add %w{ lib/**/*.rb }
23
-
24
- def clobberFromCvsIgnore(path)
25
- CLOBBER.add File.readlines(path+'/.cvsignore').map {
26
- |f| File.join(path, f.chomp)
27
- } rescue StandardError
28
- end
29
-
30
- clobberFromCvsIgnore '.'
31
- clobberFromCvsIgnore 'samples'
32
- clobberFromCvsIgnore 'test'
33
- clobberFromCvsIgnore 'test/data'
34
-
35
- def rsystem(cmd)
36
- system(cmd) or raise "system command failed: '#{cmd}"
37
- end
38
3
 
39
4
  task :default => [:test]
40
5
 
41
- desc "Run unit tests"
42
- task :test do
43
- ruby %{-C test alltests.rb}
44
- end
45
-
46
- # Shortcuts for test targets
47
- task :ut => [:test]
48
-
49
- spec = Gem::Specification.new do |s|
50
- s.name = PKG_NAME
51
- s.version = PKG_VERSION
52
- s.author = "Thomas Sondergaard"
53
- s.email = "thomas(at)sondergaard.cc"
54
- s.homepage = "http://rubyzip.sourceforge.net/"
55
- s.platform = Gem::Platform::RUBY
56
- s.summary = "rubyzip is a ruby module for reading and writing zip files"
57
- s.files = PKG_FILES.to_a
58
- s.require_path = 'lib'
59
- end
60
-
61
- Rake::GemPackageTask.new(spec) do |pkg|
62
- pkg.need_zip = true
63
- pkg.need_tar = true
64
- end
65
-
66
- Rake::RDocTask.new do |rd|
67
- rd.main = "README"
68
- rd.rdoc_files.add %W{ lib/zip/*.rb README NEWS TODO ChangeLog }
69
- rd.options << "-t 'rubyzip documentation' --webcvs http://cvs.sourceforge.net/viewcvs.py/rubyzip/rubyzip/"
70
- # rd.options << "--all"
71
- end
72
-
73
- desc "Publish documentation"
74
- task :pdoc => [:rdoc] do
75
- rsystem("rsync -avz --delete html/* thomas,rubyzip@frs.sourceforge.net:/home/groups/r/ru/rubyzip/htdocs")
76
- end
77
-
78
- desc "Publish package"
79
- task :ppackage => [:package] do
80
- Net::SFTP.start("frs.sourceforge.net", "thomas,rubyzip") do
81
- |ftpclient|
82
- releasedir = File.join("/home/pfs/project/r/ru/rubyzip/rubyzip", PKG_VERSION)
83
- ftpclient.mkdir releasedir
84
- Dir['pkg/*.{tgz,zip,gem}'].each do
85
- |e|
86
- ftpclient.upload!(e, File.join(releasedir, File.basename(e)))
87
- end
88
- end
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << File.join(File.dirname(__FILE__), 'lib')
8
+ test.libs << File.join(File.dirname(__FILE__), 'test')
9
+ test.pattern = File.join(File.dirname(__FILE__), 'test/alltests.rb')
10
+ test.verbose = true
11
+ Dir.chdir File.join(File.dirname(__FILE__), 'test')
89
12
  end
90
13
 
91
- desc "Generate the ChangeLog file"
92
- task :ChangeLog do
93
- puts "Updating ChangeLog"
94
- system %{cvs2cl}
95
- end
96
-
97
- desc "Make a release"
98
- task :release => [:tag_release, :pdoc, :ppackage] do
99
- end
100
-
101
- desc "Make a release tag"
102
- task :tag_release do
103
- tag = "release-#{PKG_VERSION.gsub('.','-')}"
104
-
105
- puts "Checking for tag '#{tag}'"
106
- if (Regexp.new("^\\s+#{tag}") =~ `cvs log README`)
107
- abort "Tag '#{tag}' already exists"
108
- end
109
- puts "Tagging module with '#{tag}'"
110
- system("cvs tag #{tag}")
111
- end
@@ -0,0 +1,10 @@
1
+ module Zip
2
+ class Compressor #:nodoc:all
3
+ def finish
4
+ end
5
+ end
6
+ end
7
+
8
+ # Copyright (C) 2002, 2003 Thomas Sondergaard
9
+ # rubyzip is free software; you can redistribute it and/or
10
+ # modify it under the terms of the ruby license.
@@ -0,0 +1,10 @@
1
+ module Zip
2
+ VERSION = '0.9.4'
3
+ RUBY_MINOR_VERSION = RUBY_VERSION.split(".")[1].to_i
4
+ RUNNING_ON_WINDOWS = RbConfig::CONFIG['host_os'] =~ /^win|mswin/i
5
+ # Ruby 1.7.x compatibility
6
+ # In ruby 1.6.x and 1.8.0 reading from an empty stream returns
7
+ # an empty string the first time and then nil.
8
+ # not so in 1.7.x
9
+ EMPTY_FILE_RETURNS_EMPTY_STRING_FIRST = RUBY_MINOR_VERSION != 7
10
+ end
@@ -0,0 +1,13 @@
1
+ module Zip
2
+ class Decompressor #:nodoc:all
3
+ CHUNK_SIZE=32768
4
+ def initialize(inputStream)
5
+ super()
6
+ @inputStream=inputStream
7
+ end
8
+ end
9
+ end
10
+
11
+ # Copyright (C) 2002, 2003 Thomas Sondergaard
12
+ # rubyzip is free software; you can redistribute it and/or
13
+ # modify it under the terms of the ruby license.
@@ -0,0 +1,30 @@
1
+ module Zip
2
+ class Deflater < Compressor #:nodoc:all
3
+ def initialize(outputStream, level = Zlib::DEFAULT_COMPRESSION)
4
+ super()
5
+ @outputStream = outputStream
6
+ @zlibDeflater = Zlib::Deflate.new(level, -Zlib::MAX_WBITS)
7
+ @size = 0
8
+ @crc = Zlib::crc32
9
+ end
10
+
11
+ def << (data)
12
+ val = data.to_s
13
+ @crc = Zlib::crc32(val, @crc)
14
+ @size += val.size
15
+ @outputStream << @zlibDeflater.deflate(data)
16
+ end
17
+
18
+ def finish
19
+ until @zlibDeflater.finished?
20
+ @outputStream << @zlibDeflater.finish
21
+ end
22
+ end
23
+
24
+ attr_reader :size, :crc
25
+ end
26
+ end
27
+
28
+ # Copyright (C) 2002, 2003 Thomas Sondergaard
29
+ # rubyzip is free software; you can redistribute it and/or
30
+ # modify it under the terms of the ruby license.
@@ -0,0 +1,65 @@
1
+ module Zip
2
+ class Inflater < Decompressor #:nodoc:all
3
+ def initialize(inputStream)
4
+ super
5
+ @zlibInflater = Zlib::Inflate.new(-Zlib::MAX_WBITS)
6
+ @outputBuffer=""
7
+ @hasReturnedEmptyString = ! EMPTY_FILE_RETURNS_EMPTY_STRING_FIRST
8
+ end
9
+
10
+ def sysread(numberOfBytes = nil, buf = nil)
11
+ readEverything = numberOfBytes.nil?
12
+ while (readEverything || @outputBuffer.bytesize < numberOfBytes)
13
+ break if internal_input_finished?
14
+ @outputBuffer << internal_produce_input(buf)
15
+ end
16
+ return value_when_finished if @outputBuffer.bytesize == 0 && input_finished?
17
+ endIndex = numberOfBytes.nil? ? @outputBuffer.bytesize : numberOfBytes
18
+ return @outputBuffer.slice!(0...endIndex)
19
+ end
20
+
21
+ def produce_input
22
+ if (@outputBuffer.empty?)
23
+ return internal_produce_input
24
+ else
25
+ return @outputBuffer.slice!(0...(@outputBuffer.length))
26
+ end
27
+ end
28
+
29
+ # to be used with produce_input, not read (as read may still have more data cached)
30
+ # is data cached anywhere other than @outputBuffer? the comment above may be wrong
31
+ def input_finished?
32
+ @outputBuffer.empty? && internal_input_finished?
33
+ end
34
+ alias :eof :input_finished?
35
+ alias :eof? :input_finished?
36
+
37
+ private
38
+
39
+ def internal_produce_input(buf = nil)
40
+ retried = 0
41
+ begin
42
+ @zlibInflater.inflate(@inputStream.read(Decompressor::CHUNK_SIZE, buf))
43
+ rescue Zlib::BufError
44
+ raise if (retried >= 5) # how many times should we retry?
45
+ retried += 1
46
+ retry
47
+ end
48
+ end
49
+
50
+ def internal_input_finished?
51
+ @zlibInflater.finished?
52
+ end
53
+
54
+ # TODO: Specialize to handle different behaviour in ruby > 1.7.0 ?
55
+ def value_when_finished # mimic behaviour of ruby File object.
56
+ return if @hasReturnedEmptyString
57
+ @hasReturnedEmptyString = true
58
+ return ""
59
+ end
60
+ end
61
+ end
62
+
63
+ # Copyright (C) 2002, 2003 Thomas Sondergaard
64
+ # rubyzip is free software; you can redistribute it and/or
65
+ # modify it under the terms of the ruby license.
@@ -45,11 +45,11 @@ module IOExtras #:nodoc:
45
45
  def read(numberOfBytes = nil, buf = nil)
46
46
  tbuf = nil
47
47
 
48
- if @outputBuffer.length > 0
49
- if numberOfBytes <= @outputBuffer.length
48
+ if @outputBuffer.bytesize > 0
49
+ if numberOfBytes <= @outputBuffer.bytesize
50
50
  tbuf = @outputBuffer.slice!(0, numberOfBytes)
51
51
  else
52
- numberOfBytes -= @outputBuffer.length if (numberOfBytes)
52
+ numberOfBytes -= @outputBuffer.bytesize if (numberOfBytes)
53
53
  rbuf = sysread(numberOfBytes, buf)
54
54
  tbuf = @outputBuffer
55
55
  tbuf << rbuf if (rbuf)
@@ -73,45 +73,45 @@ module IOExtras #:nodoc:
73
73
  def readlines(aSepString = $/)
74
74
  retVal = []
75
75
  each_line(aSepString) { |line| retVal << line }
76
- return retVal
76
+ retVal
77
77
  end
78
-
79
- def gets(aSepString=$/)
78
+
79
+ def gets(aSepString = $/)
80
80
  @lineno = @lineno.next
81
- return read if aSepString == nil
82
- aSepString="#{$/}#{$/}" if aSepString == ""
83
-
84
- bufferIndex=0
81
+ return read if aSepString.nil?
82
+ aSepString = "#{$/}#{$/}" if aSepString.empty?
83
+
84
+ bufferIndex = 0
85
85
  while ((matchIndex = @outputBuffer.index(aSepString, bufferIndex)) == nil)
86
- bufferIndex=@outputBuffer.length
87
- if input_finished?
88
- return @outputBuffer.empty? ? nil : flush
89
- end
90
- @outputBuffer << produce_input
86
+ bufferIndex = @outputBuffer.bytesize
87
+ if input_finished?
88
+ return @outputBuffer.empty? ? nil : flush
89
+ end
90
+ @outputBuffer << produce_input
91
91
  end
92
- sepIndex=matchIndex + aSepString.length
92
+ sepIndex = matchIndex + aSepString.bytesize
93
93
  return @outputBuffer.slice!(0...sepIndex)
94
94
  end
95
-
95
+
96
96
  def flush
97
- retVal=@outputBuffer
97
+ retVal = @outputBuffer
98
98
  @outputBuffer=""
99
99
  return retVal
100
100
  end
101
-
101
+
102
102
  def readline(aSepString = $/)
103
103
  retVal = gets(aSepString)
104
104
  raise EOFError if retVal == nil
105
- return retVal
105
+ retVal
106
106
  end
107
-
107
+
108
108
  def each_line(aSepString = $/)
109
109
  while true
110
- yield readline(aSepString)
110
+ yield readline(aSepString)
111
111
  end
112
112
  rescue EOFError
113
113
  end
114
-
114
+
115
115
  alias_method :each, :each_line
116
116
  end
117
117
 
@@ -123,12 +123,12 @@ module IOExtras #:nodoc:
123
123
 
124
124
  def write(data)
125
125
  self << data
126
- data.to_s.length
126
+ data.to_s.bytesize
127
127
  end
128
128
 
129
129
 
130
130
  def print(*params)
131
- self << params.to_s << $\.to_s
131
+ self << params.join($,) << $\.to_s
132
132
  end
133
133
 
134
134
  def printf(aFormatString, *params)
@@ -137,21 +137,20 @@ module IOExtras #:nodoc:
137
137
 
138
138
  def putc(anObject)
139
139
  self << case anObject
140
- when Fixnum then anObject.chr
141
- when String then anObject
142
- else raise TypeError, "putc: Only Fixnum and String supported"
143
- end
140
+ when Fixnum then anObject.chr
141
+ when String then anObject
142
+ else raise TypeError, "putc: Only Fixnum and String supported"
143
+ end
144
144
  anObject
145
145
  end
146
-
146
+
147
147
  def puts(*params)
148
148
  params << "\n" if params.empty?
149
- params.flatten.each {
150
- |element|
151
- val = element.to_s
152
- self << val
153
- self << "\n" unless val[-1,1] == "\n"
154
- }
149
+ params.flatten.each do |element|
150
+ val = element.to_s
151
+ self << val
152
+ self << "\n" unless val[-1,1] == "\n"
153
+ end
155
154
  end
156
155
 
157
156
  end
@@ -0,0 +1,15 @@
1
+ module Zip
2
+ class NullCompressor < Compressor #:nodoc:all
3
+ include Singleton
4
+
5
+ def << (data)
6
+ raise IOError, "closed stream"
7
+ end
8
+
9
+ attr_reader :size, :compressed_size
10
+ end
11
+ end
12
+
13
+ # Copyright (C) 2002, 2003 Thomas Sondergaard
14
+ # rubyzip is free software; you can redistribute it and/or
15
+ # modify it under the terms of the ruby license.