rubyzip 0.9.1 → 2.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +354 -0
- data/Rakefile +15 -104
- data/TODO +0 -1
- data/lib/zip/central_directory.rb +212 -0
- data/lib/zip/compressor.rb +9 -0
- data/lib/zip/constants.rb +115 -0
- data/lib/zip/crypto/decrypted_io.rb +40 -0
- data/lib/zip/crypto/encryption.rb +11 -0
- data/lib/zip/crypto/null_encryption.rb +43 -0
- data/lib/zip/crypto/traditional_encryption.rb +99 -0
- data/lib/zip/decompressor.rb +31 -0
- data/lib/zip/deflater.rb +34 -0
- data/lib/zip/dos_time.rb +53 -0
- data/lib/zip/entry.rb +719 -0
- data/lib/zip/entry_set.rb +88 -0
- data/lib/zip/errors.rb +19 -0
- data/lib/zip/extra_field/generic.rb +44 -0
- data/lib/zip/extra_field/ntfs.rb +94 -0
- data/lib/zip/extra_field/old_unix.rb +46 -0
- data/lib/zip/extra_field/universal_time.rb +77 -0
- data/lib/zip/extra_field/unix.rb +39 -0
- data/lib/zip/extra_field/zip64.rb +70 -0
- data/lib/zip/extra_field/zip64_placeholder.rb +15 -0
- data/lib/zip/extra_field.rb +103 -0
- data/lib/zip/file.rb +468 -0
- data/lib/zip/filesystem.rb +643 -0
- data/lib/zip/inflater.rb +54 -0
- data/lib/zip/input_stream.rb +180 -0
- data/lib/zip/ioextras/abstract_input_stream.rb +122 -0
- data/lib/zip/ioextras/abstract_output_stream.rb +43 -0
- data/lib/zip/ioextras.rb +21 -140
- data/lib/zip/null_compressor.rb +15 -0
- data/lib/zip/null_decompressor.rb +19 -0
- data/lib/zip/null_input_stream.rb +10 -0
- data/lib/zip/output_stream.rb +198 -0
- data/lib/zip/pass_thru_compressor.rb +23 -0
- data/lib/zip/pass_thru_decompressor.rb +31 -0
- data/lib/zip/streamable_directory.rb +15 -0
- data/lib/zip/streamable_stream.rb +52 -0
- data/lib/zip/version.rb +3 -0
- data/lib/zip.rb +72 -0
- data/samples/example.rb +44 -32
- data/samples/example_filesystem.rb +16 -19
- data/samples/example_recursive.rb +54 -0
- data/samples/gtk_ruby_zip.rb +84 -0
- data/samples/qtzip.rb +25 -34
- data/samples/write_simple.rb +10 -13
- data/samples/zipfind.rb +38 -45
- metadata +182 -91
- data/ChangeLog +0 -1504
- data/NEWS +0 -144
- data/README +0 -72
- data/install.rb +0 -22
- data/lib/download_quizzes.rb +0 -119
- data/lib/quiz1/t/solutions/Bill Guindon/solitaire.rb +0 -205
- data/lib/quiz1/t/solutions/Carlos/solitaire.rb +0 -111
- data/lib/quiz1/t/solutions/Dennis Ranke/solitaire.rb +0 -111
- data/lib/quiz1/t/solutions/Florian Gross/solitaire.rb +0 -301
- data/lib/quiz1/t/solutions/Glen M. Lewis/solitaire.rb +0 -268
- data/lib/quiz1/t/solutions/James Edward Gray II/solitaire.rb +0 -132
- data/lib/quiz1/t/solutions/Jamis Buck/bin/main.rb +0 -13
- data/lib/quiz1/t/solutions/Jamis Buck/lib/cipher.rb +0 -230
- data/lib/quiz1/t/solutions/Jamis Buck/lib/cli.rb +0 -24
- data/lib/quiz1/t/solutions/Jamis Buck/test/tc_deck.rb +0 -30
- data/lib/quiz1/t/solutions/Jamis Buck/test/tc_key-stream.rb +0 -19
- data/lib/quiz1/t/solutions/Jamis Buck/test/tc_keying-algorithms.rb +0 -31
- data/lib/quiz1/t/solutions/Jamis Buck/test/tc_solitaire-cipher.rb +0 -66
- data/lib/quiz1/t/solutions/Jamis Buck/test/tc_unkeyed-algorithm.rb +0 -17
- data/lib/quiz1/t/solutions/Jamis Buck/test/tests.rb +0 -2
- data/lib/quiz1/t/solutions/Jim Menard/solitaire_cypher.rb +0 -204
- data/lib/quiz1/t/solutions/Jim Menard/test.rb +0 -47
- data/lib/quiz1/t/solutions/Moses Hohman/cipher.rb +0 -97
- data/lib/quiz1/t/solutions/Moses Hohman/deck.rb +0 -140
- data/lib/quiz1/t/solutions/Moses Hohman/solitaire.rb +0 -14
- data/lib/quiz1/t/solutions/Moses Hohman/test_cipher.rb +0 -68
- data/lib/quiz1/t/solutions/Moses Hohman/test_deck.rb +0 -146
- data/lib/quiz1/t/solutions/Moses Hohman/test_util.rb +0 -38
- data/lib/quiz1/t/solutions/Moses Hohman/testsuite.rb +0 -5
- data/lib/quiz1/t/solutions/Moses Hohman/util.rb +0 -27
- data/lib/quiz1/t/solutions/Niklas Frykholm/solitaire.rb +0 -151
- data/lib/quiz1/t/solutions/Thomas Leitner/solitaire.rb +0 -198
- data/lib/zip/stdrubyext.rb +0 -111
- data/lib/zip/tempfile_bugfixed.rb +0 -195
- data/lib/zip/zip.rb +0 -1847
- data/lib/zip/zipfilesystem.rb +0 -609
- data/lib/zip/ziprequire.rb +0 -90
- data/samples/gtkRubyzip.rb +0 -86
- data/test/alltests.rb +0 -9
- data/test/data/file1.txt +0 -46
- data/test/data/file1.txt.deflatedData +0 -0
- data/test/data/file2.txt +0 -1504
- data/test/data/notzippedruby.rb +0 -7
- data/test/data/rubycode.zip +0 -0
- data/test/data/rubycode2.zip +0 -0
- data/test/data/testDirectory.bin +0 -0
- data/test/data/zipWithDirs.zip +0 -0
- data/test/gentestfiles.rb +0 -157
- data/test/ioextrastest.rb +0 -208
- data/test/stdrubyexttest.rb +0 -52
- data/test/zipfilesystemtest.rb +0 -831
- data/test/ziprequiretest.rb +0 -43
- data/test/ziptest.rb +0 -1599
@@ -0,0 +1,180 @@
|
|
1
|
+
module Zip
|
2
|
+
# InputStream is the basic class for reading zip entries in a
|
3
|
+
# zip file. It is possible to create a InputStream object directly,
|
4
|
+
# passing the zip file name to the constructor, but more often than not
|
5
|
+
# the InputStream will be obtained from a File (perhaps using the
|
6
|
+
# ZipFileSystem interface) object for a particular entry in the zip
|
7
|
+
# archive.
|
8
|
+
#
|
9
|
+
# A InputStream inherits IOExtras::AbstractInputStream in order
|
10
|
+
# to provide an IO-like interface for reading from a single zip
|
11
|
+
# entry. Beyond methods for mimicking an IO-object it contains
|
12
|
+
# the method get_next_entry for iterating through the entries of
|
13
|
+
# an archive. get_next_entry returns a Entry object that describes
|
14
|
+
# the zip entry the InputStream is currently reading from.
|
15
|
+
#
|
16
|
+
# Example that creates a zip archive with ZipOutputStream and reads it
|
17
|
+
# back again with a InputStream.
|
18
|
+
#
|
19
|
+
# require 'zip'
|
20
|
+
#
|
21
|
+
# Zip::OutputStream.open("my.zip") do |io|
|
22
|
+
#
|
23
|
+
# io.put_next_entry("first_entry.txt")
|
24
|
+
# io.write "Hello world!"
|
25
|
+
#
|
26
|
+
# io.put_next_entry("adir/first_entry.txt")
|
27
|
+
# io.write "Hello again!"
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
#
|
31
|
+
# Zip::InputStream.open("my.zip") do |io|
|
32
|
+
#
|
33
|
+
# while (entry = io.get_next_entry)
|
34
|
+
# puts "Contents of #{entry.name}: '#{io.read}'"
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# java.util.zip.ZipInputStream is the original inspiration for this
|
39
|
+
# class.
|
40
|
+
|
41
|
+
class InputStream
|
42
|
+
CHUNK_SIZE = 32_768
|
43
|
+
|
44
|
+
include ::Zip::IOExtras::AbstractInputStream
|
45
|
+
|
46
|
+
# Opens the indicated zip file. An exception is thrown
|
47
|
+
# if the specified offset in the specified filename is
|
48
|
+
# not a local zip entry header.
|
49
|
+
#
|
50
|
+
# @param context [String||IO||StringIO] file path or IO/StringIO object
|
51
|
+
# @param offset [Integer] offset in the IO/StringIO
|
52
|
+
def initialize(context, offset = 0, decrypter = nil)
|
53
|
+
super()
|
54
|
+
@archive_io = get_io(context, offset)
|
55
|
+
@decompressor = ::Zip::NullDecompressor
|
56
|
+
@decrypter = decrypter || ::Zip::NullDecrypter.new
|
57
|
+
@current_entry = nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def close
|
61
|
+
@archive_io.close
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns a Entry object. It is necessary to call this
|
65
|
+
# method on a newly created InputStream before reading from
|
66
|
+
# the first entry in the archive. Returns nil when there are
|
67
|
+
# no more entries.
|
68
|
+
def get_next_entry
|
69
|
+
@archive_io.seek(@current_entry.next_header_offset, IO::SEEK_SET) if @current_entry
|
70
|
+
open_entry
|
71
|
+
end
|
72
|
+
|
73
|
+
# Rewinds the stream to the beginning of the current entry
|
74
|
+
def rewind
|
75
|
+
return if @current_entry.nil?
|
76
|
+
|
77
|
+
@lineno = 0
|
78
|
+
@pos = 0
|
79
|
+
@archive_io.seek(@current_entry.local_header_offset, IO::SEEK_SET)
|
80
|
+
open_entry
|
81
|
+
end
|
82
|
+
|
83
|
+
# Modeled after IO.sysread
|
84
|
+
def sysread(length = nil, outbuf = '')
|
85
|
+
@decompressor.read(length, outbuf)
|
86
|
+
end
|
87
|
+
|
88
|
+
class << self
|
89
|
+
# Same as #initialize but if a block is passed the opened
|
90
|
+
# stream is passed to the block and closed when the block
|
91
|
+
# returns.
|
92
|
+
def open(filename_or_io, offset = 0, decrypter = nil)
|
93
|
+
zio = new(filename_or_io, offset, decrypter)
|
94
|
+
return zio unless block_given?
|
95
|
+
|
96
|
+
begin
|
97
|
+
yield zio
|
98
|
+
ensure
|
99
|
+
zio.close if zio
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def open_buffer(filename_or_io, offset = 0)
|
104
|
+
warn 'open_buffer is deprecated!!! Use open instead!'
|
105
|
+
::Zip::InputStream.open(filename_or_io, offset)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
protected
|
110
|
+
|
111
|
+
def get_io(io_or_file, offset = 0)
|
112
|
+
if io_or_file.respond_to?(:seek)
|
113
|
+
io = io_or_file.dup
|
114
|
+
io.seek(offset, ::IO::SEEK_SET)
|
115
|
+
io
|
116
|
+
else
|
117
|
+
file = ::File.open(io_or_file, 'rb')
|
118
|
+
file.seek(offset, ::IO::SEEK_SET)
|
119
|
+
file
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def open_entry
|
124
|
+
@current_entry = ::Zip::Entry.read_local_entry(@archive_io)
|
125
|
+
if @current_entry && @current_entry.encrypted? && @decrypter.kind_of?(NullEncrypter)
|
126
|
+
raise Error, 'password required to decode zip file'
|
127
|
+
end
|
128
|
+
|
129
|
+
if @current_entry && @current_entry.incomplete? && @current_entry.crc == 0 \
|
130
|
+
&& @current_entry.compressed_size == 0 \
|
131
|
+
&& @current_entry.size == 0 && !@complete_entry
|
132
|
+
raise GPFBit3Error,
|
133
|
+
'General purpose flag Bit 3 is set so not possible to get proper info from local header.' \
|
134
|
+
'Please use ::Zip::File instead of ::Zip::InputStream'
|
135
|
+
end
|
136
|
+
@decrypted_io = get_decrypted_io
|
137
|
+
@decompressor = get_decompressor
|
138
|
+
flush
|
139
|
+
@current_entry
|
140
|
+
end
|
141
|
+
|
142
|
+
def get_decrypted_io
|
143
|
+
header = @archive_io.read(@decrypter.header_bytesize)
|
144
|
+
@decrypter.reset!(header)
|
145
|
+
|
146
|
+
::Zip::DecryptedIo.new(@archive_io, @decrypter)
|
147
|
+
end
|
148
|
+
|
149
|
+
def get_decompressor
|
150
|
+
return ::Zip::NullDecompressor if @current_entry.nil?
|
151
|
+
|
152
|
+
decompressed_size =
|
153
|
+
if @current_entry.incomplete? && @current_entry.crc == 0 && @current_entry.size == 0 && @complete_entry
|
154
|
+
@complete_entry.size
|
155
|
+
else
|
156
|
+
@current_entry.size
|
157
|
+
end
|
158
|
+
|
159
|
+
decompressor_class = ::Zip::Decompressor.find_by_compression_method(@current_entry.compression_method)
|
160
|
+
if decompressor_class.nil?
|
161
|
+
raise ::Zip::CompressionMethodError,
|
162
|
+
"Unsupported compression method #{@current_entry.compression_method}"
|
163
|
+
end
|
164
|
+
|
165
|
+
decompressor_class.new(@decrypted_io, decompressed_size)
|
166
|
+
end
|
167
|
+
|
168
|
+
def produce_input
|
169
|
+
@decompressor.read(CHUNK_SIZE)
|
170
|
+
end
|
171
|
+
|
172
|
+
def input_finished?
|
173
|
+
@decompressor.eof
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
# Copyright (C) 2002, 2003 Thomas Sondergaard
|
179
|
+
# rubyzip is free software; you can redistribute it and/or
|
180
|
+
# modify it under the terms of the ruby license.
|
@@ -0,0 +1,122 @@
|
|
1
|
+
module Zip
|
2
|
+
module IOExtras
|
3
|
+
# Implements many of the convenience methods of IO
|
4
|
+
# such as gets, getc, readline and readlines
|
5
|
+
# depends on: input_finished?, produce_input and read
|
6
|
+
module AbstractInputStream
|
7
|
+
include Enumerable
|
8
|
+
include FakeIO
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
super
|
12
|
+
@lineno = 0
|
13
|
+
@pos = 0
|
14
|
+
@output_buffer = ''
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_accessor :lineno
|
18
|
+
attr_reader :pos
|
19
|
+
|
20
|
+
def read(number_of_bytes = nil, buf = '')
|
21
|
+
tbuf = if @output_buffer.bytesize > 0
|
22
|
+
if number_of_bytes <= @output_buffer.bytesize
|
23
|
+
@output_buffer.slice!(0, number_of_bytes)
|
24
|
+
else
|
25
|
+
number_of_bytes -= @output_buffer.bytesize if number_of_bytes
|
26
|
+
rbuf = sysread(number_of_bytes, buf)
|
27
|
+
out = @output_buffer
|
28
|
+
out << rbuf if rbuf
|
29
|
+
@output_buffer = ''
|
30
|
+
out
|
31
|
+
end
|
32
|
+
else
|
33
|
+
sysread(number_of_bytes, buf)
|
34
|
+
end
|
35
|
+
|
36
|
+
if tbuf.nil? || tbuf.empty?
|
37
|
+
return nil if number_of_bytes
|
38
|
+
|
39
|
+
return ''
|
40
|
+
end
|
41
|
+
|
42
|
+
@pos += tbuf.length
|
43
|
+
|
44
|
+
if buf
|
45
|
+
buf.replace(tbuf)
|
46
|
+
else
|
47
|
+
buf = tbuf
|
48
|
+
end
|
49
|
+
buf
|
50
|
+
end
|
51
|
+
|
52
|
+
def readlines(a_sep_string = $INPUT_RECORD_SEPARATOR)
|
53
|
+
ret_val = []
|
54
|
+
each_line(a_sep_string) { |line| ret_val << line }
|
55
|
+
ret_val
|
56
|
+
end
|
57
|
+
|
58
|
+
def gets(a_sep_string = $INPUT_RECORD_SEPARATOR, number_of_bytes = nil)
|
59
|
+
@lineno = @lineno.next
|
60
|
+
|
61
|
+
if number_of_bytes.respond_to?(:to_int)
|
62
|
+
number_of_bytes = number_of_bytes.to_int
|
63
|
+
a_sep_string = a_sep_string.to_str if a_sep_string
|
64
|
+
elsif a_sep_string.respond_to?(:to_int)
|
65
|
+
number_of_bytes = a_sep_string.to_int
|
66
|
+
a_sep_string = $INPUT_RECORD_SEPARATOR
|
67
|
+
else
|
68
|
+
number_of_bytes = nil
|
69
|
+
a_sep_string = a_sep_string.to_str if a_sep_string
|
70
|
+
end
|
71
|
+
|
72
|
+
return read(number_of_bytes) if a_sep_string.nil?
|
73
|
+
|
74
|
+
a_sep_string = "#{$INPUT_RECORD_SEPARATOR}#{$INPUT_RECORD_SEPARATOR}" if a_sep_string.empty?
|
75
|
+
|
76
|
+
buffer_index = 0
|
77
|
+
over_limit = (number_of_bytes && @output_buffer.bytesize >= number_of_bytes)
|
78
|
+
while (match_index = @output_buffer.index(a_sep_string, buffer_index)).nil? && !over_limit
|
79
|
+
buffer_index = [buffer_index, @output_buffer.bytesize - a_sep_string.bytesize].max
|
80
|
+
return @output_buffer.empty? ? nil : flush if input_finished?
|
81
|
+
|
82
|
+
@output_buffer << produce_input
|
83
|
+
over_limit = (number_of_bytes && @output_buffer.bytesize >= number_of_bytes)
|
84
|
+
end
|
85
|
+
sep_index = [match_index + a_sep_string.bytesize, number_of_bytes || @output_buffer.bytesize].min
|
86
|
+
@pos += sep_index
|
87
|
+
@output_buffer.slice!(0...sep_index)
|
88
|
+
end
|
89
|
+
|
90
|
+
def ungetc(byte)
|
91
|
+
@output_buffer = byte.chr + @output_buffer
|
92
|
+
end
|
93
|
+
|
94
|
+
def flush
|
95
|
+
ret_val = @output_buffer
|
96
|
+
@output_buffer = ''
|
97
|
+
ret_val
|
98
|
+
end
|
99
|
+
|
100
|
+
def readline(a_sep_string = $INPUT_RECORD_SEPARATOR)
|
101
|
+
ret_val = gets(a_sep_string)
|
102
|
+
raise EOFError unless ret_val
|
103
|
+
|
104
|
+
ret_val
|
105
|
+
end
|
106
|
+
|
107
|
+
def each_line(a_sep_string = $INPUT_RECORD_SEPARATOR)
|
108
|
+
loop { yield readline(a_sep_string) }
|
109
|
+
rescue EOFError
|
110
|
+
# We just need to catch this; we don't need to handle it.
|
111
|
+
end
|
112
|
+
|
113
|
+
alias each each_line
|
114
|
+
|
115
|
+
def eof
|
116
|
+
@output_buffer.empty? && input_finished?
|
117
|
+
end
|
118
|
+
|
119
|
+
alias eof? eof
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Zip
|
2
|
+
module IOExtras
|
3
|
+
# Implements many of the output convenience methods of IO.
|
4
|
+
# relies on <<
|
5
|
+
module AbstractOutputStream
|
6
|
+
include FakeIO
|
7
|
+
|
8
|
+
def write(data)
|
9
|
+
self << data
|
10
|
+
data.to_s.bytesize
|
11
|
+
end
|
12
|
+
|
13
|
+
def print(*params)
|
14
|
+
self << params.join($OUTPUT_FIELD_SEPARATOR) << $OUTPUT_RECORD_SEPARATOR.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def printf(a_format_string, *params)
|
18
|
+
self << format(a_format_string, *params)
|
19
|
+
end
|
20
|
+
|
21
|
+
def putc(an_object)
|
22
|
+
self << case an_object
|
23
|
+
when Integer
|
24
|
+
an_object.chr
|
25
|
+
when String
|
26
|
+
an_object
|
27
|
+
else
|
28
|
+
raise TypeError, 'putc: Only Integer and String supported'
|
29
|
+
end
|
30
|
+
an_object
|
31
|
+
end
|
32
|
+
|
33
|
+
def puts(*params)
|
34
|
+
params << "\n" if params.empty?
|
35
|
+
params.flatten.each do |element|
|
36
|
+
val = element.to_s
|
37
|
+
self << val
|
38
|
+
self << "\n" unless val[-1, 1] == "\n"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/zip/ioextras.rb
CHANGED
@@ -1,154 +1,35 @@
|
|
1
|
-
module
|
1
|
+
module Zip
|
2
|
+
module IOExtras #:nodoc:
|
3
|
+
CHUNK_SIZE = 131_072
|
2
4
|
|
3
|
-
|
5
|
+
RANGE_ALL = 0..-1
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
s = ''
|
9
|
-
ostream.write(istream.read(CHUNK_SIZE, s)) until istream.eof?
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
# Implements kind_of? in order to pretend to be an IO object
|
14
|
-
module FakeIO
|
15
|
-
def kind_of?(object)
|
16
|
-
object == IO || super
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# Implements many of the convenience methods of IO
|
21
|
-
# such as gets, getc, readline and readlines
|
22
|
-
# depends on: input_finished?, produce_input and read
|
23
|
-
module AbstractInputStream
|
24
|
-
include Enumerable
|
25
|
-
include FakeIO
|
26
|
-
|
27
|
-
def initialize
|
28
|
-
super
|
29
|
-
@lineno = 0
|
30
|
-
@outputBuffer = ""
|
31
|
-
end
|
32
|
-
|
33
|
-
attr_accessor :lineno
|
34
|
-
|
35
|
-
def read(numberOfBytes = nil, buf = nil)
|
36
|
-
tbuf = nil
|
37
|
-
|
38
|
-
if @outputBuffer.length > 0
|
39
|
-
if numberOfBytes <= @outputBuffer.length
|
40
|
-
tbuf = @outputBuffer.slice!(0, numberOfBytes)
|
41
|
-
else
|
42
|
-
numberOfBytes -= @outputBuffer.length if (numberOfBytes)
|
43
|
-
rbuf = sysread(numberOfBytes, buf)
|
44
|
-
tbuf = @outputBuffer
|
45
|
-
tbuf << rbuf if (rbuf)
|
46
|
-
@outputBuffer = ""
|
47
|
-
end
|
48
|
-
else
|
49
|
-
tbuf = sysread(numberOfBytes, buf)
|
7
|
+
class << self
|
8
|
+
def copy_stream(ostream, istream)
|
9
|
+
ostream.write(istream.read(CHUNK_SIZE, '')) until istream.eof?
|
50
10
|
end
|
51
11
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
12
|
+
def copy_stream_n(ostream, istream, nbytes)
|
13
|
+
toread = nbytes
|
14
|
+
while toread > 0 && !istream.eof?
|
15
|
+
tr = toread > CHUNK_SIZE ? CHUNK_SIZE : toread
|
16
|
+
ostream.write(istream.read(tr, ''))
|
17
|
+
toread -= tr
|
18
|
+
end
|
58
19
|
end
|
59
|
-
|
60
|
-
buf
|
61
20
|
end
|
62
21
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
def gets(aSepString=$/)
|
70
|
-
@lineno = @lineno.next
|
71
|
-
return read if aSepString == nil
|
72
|
-
aSepString="#{$/}#{$/}" if aSepString == ""
|
73
|
-
|
74
|
-
bufferIndex=0
|
75
|
-
while ((matchIndex = @outputBuffer.index(aSepString, bufferIndex)) == nil)
|
76
|
-
bufferIndex=@outputBuffer.length
|
77
|
-
if input_finished?
|
78
|
-
return @outputBuffer.empty? ? nil : flush
|
79
|
-
end
|
80
|
-
@outputBuffer << produce_input
|
22
|
+
# Implements kind_of? in order to pretend to be an IO object
|
23
|
+
module FakeIO
|
24
|
+
def kind_of?(object)
|
25
|
+
object == IO || super
|
81
26
|
end
|
82
|
-
sepIndex=matchIndex + aSepString.length
|
83
|
-
return @outputBuffer.slice!(0...sepIndex)
|
84
|
-
end
|
85
|
-
|
86
|
-
def flush
|
87
|
-
retVal=@outputBuffer
|
88
|
-
@outputBuffer=""
|
89
|
-
return retVal
|
90
|
-
end
|
91
|
-
|
92
|
-
def readline(aSepString = $/)
|
93
|
-
retVal = gets(aSepString)
|
94
|
-
raise EOFError if retVal == nil
|
95
|
-
return retVal
|
96
27
|
end
|
97
|
-
|
98
|
-
def each_line(aSepString = $/)
|
99
|
-
while true
|
100
|
-
yield readline(aSepString)
|
101
|
-
end
|
102
|
-
rescue EOFError
|
103
|
-
end
|
104
|
-
|
105
|
-
alias_method :each, :each_line
|
106
|
-
end
|
107
|
-
|
108
|
-
|
109
|
-
# Implements many of the output convenience methods of IO.
|
110
|
-
# relies on <<
|
111
|
-
module AbstractOutputStream
|
112
|
-
include FakeIO
|
113
|
-
|
114
|
-
def write(data)
|
115
|
-
self << data
|
116
|
-
data.to_s.length
|
117
|
-
end
|
118
|
-
|
119
|
-
|
120
|
-
def print(*params)
|
121
|
-
self << params.to_s << $\.to_s
|
122
|
-
end
|
123
|
-
|
124
|
-
def printf(aFormatString, *params)
|
125
|
-
self << sprintf(aFormatString, *params)
|
126
|
-
end
|
127
|
-
|
128
|
-
def putc(anObject)
|
129
|
-
self << case anObject
|
130
|
-
when Fixnum then anObject.chr
|
131
|
-
when String then anObject
|
132
|
-
else raise TypeError, "putc: Only Fixnum and String supported"
|
133
|
-
end
|
134
|
-
anObject
|
135
|
-
end
|
136
|
-
|
137
|
-
def puts(*params)
|
138
|
-
params << "\n" if params.empty?
|
139
|
-
params.flatten.each {
|
140
|
-
|element|
|
141
|
-
val = element.to_s
|
142
|
-
self << val
|
143
|
-
self << "\n" unless val[-1,1] == "\n"
|
144
|
-
}
|
145
|
-
end
|
146
|
-
|
147
28
|
end
|
29
|
+
end
|
148
30
|
|
149
|
-
|
150
|
-
|
151
|
-
|
31
|
+
require 'zip/ioextras/abstract_input_stream'
|
32
|
+
require 'zip/ioextras/abstract_output_stream'
|
152
33
|
|
153
34
|
# Copyright (C) 2002-2004 Thomas Sondergaard
|
154
35
|
# rubyzip is free software; you can redistribute it and/or
|
@@ -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.
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Zip
|
2
|
+
module NullDecompressor #:nodoc:all
|
3
|
+
module_function
|
4
|
+
|
5
|
+
def read(_length = nil, _outbuf = nil)
|
6
|
+
nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def eof
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
alias eof? eof
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Copyright (C) 2002, 2003 Thomas Sondergaard
|
18
|
+
# rubyzip is free software; you can redistribute it and/or
|
19
|
+
# modify it under the terms of the ruby license.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Zip
|
2
|
+
module NullInputStream #:nodoc:all
|
3
|
+
include ::Zip::NullDecompressor
|
4
|
+
include ::Zip::IOExtras::AbstractInputStream
|
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.
|