archive-zip 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/LICENSE +22 -57
- data/{NEWS → NEWS.md} +29 -16
- data/README.md +250 -0
- data/Rakefile +119 -76
- data/lib/archive/support/binary_stringio.rb +9 -2
- data/lib/archive/support/time.rb +2 -2
- data/lib/archive/zip.rb +1 -1
- data/lib/archive/zip/entry.rb +2 -2
- data/lib/archive/zip/version.rb +1 -1
- data/spec/archive/zip/archive_spec.rb +54 -0
- data/spec/archive/zip/codec/deflate/compress/checksum_spec.rb +8 -6
- data/spec/archive/zip/codec/deflate/compress/close_spec.rb +13 -12
- data/spec/archive/zip/codec/deflate/compress/crc32_spec.rb +6 -4
- data/spec/archive/zip/codec/deflate/compress/data_descriptor_spec.rb +17 -10
- data/spec/archive/zip/codec/deflate/compress/new_spec.rb +7 -5
- data/spec/archive/zip/codec/deflate/compress/open_spec.rb +9 -7
- data/spec/archive/zip/codec/deflate/compress/write_spec.rb +15 -15
- data/spec/archive/zip/codec/deflate/decompress/checksum_spec.rb +6 -4
- data/spec/archive/zip/codec/deflate/decompress/close_spec.rb +10 -9
- data/spec/archive/zip/codec/deflate/decompress/crc32_spec.rb +6 -4
- data/spec/archive/zip/codec/deflate/decompress/data_descriptor_spec.rb +17 -10
- data/spec/archive/zip/codec/deflate/decompress/new_spec.rb +5 -3
- data/spec/archive/zip/codec/deflate/decompress/open_spec.rb +7 -5
- data/spec/archive/zip/codec/null_encryption/decrypt/close_spec.rb +10 -9
- data/spec/archive/zip/codec/null_encryption/decrypt/new_spec.rb +6 -4
- data/spec/archive/zip/codec/null_encryption/decrypt/open_spec.rb +8 -6
- data/spec/archive/zip/codec/null_encryption/decrypt/read_spec.rb +8 -6
- data/spec/archive/zip/codec/null_encryption/decrypt/rewind_spec.rb +9 -7
- data/spec/archive/zip/codec/null_encryption/decrypt/seek_spec.rb +15 -13
- data/spec/archive/zip/codec/null_encryption/decrypt/tell_spec.rb +8 -6
- data/spec/archive/zip/codec/null_encryption/encrypt/close_spec.rb +10 -9
- data/spec/archive/zip/codec/null_encryption/encrypt/new_spec.rb +5 -3
- data/spec/archive/zip/codec/null_encryption/encrypt/open_spec.rb +9 -5
- data/spec/archive/zip/codec/null_encryption/encrypt/rewind_spec.rb +9 -7
- data/spec/archive/zip/codec/null_encryption/encrypt/seek_spec.rb +15 -13
- data/spec/archive/zip/codec/null_encryption/encrypt/tell_spec.rb +11 -9
- data/spec/archive/zip/codec/null_encryption/encrypt/write_spec.rb +12 -10
- data/spec/archive/zip/codec/store/compress/close_spec.rb +10 -9
- data/spec/archive/zip/codec/store/compress/data_descriptor_spec.rb +19 -10
- data/spec/archive/zip/codec/store/compress/new_spec.rb +5 -3
- data/spec/archive/zip/codec/store/compress/open_spec.rb +7 -5
- data/spec/archive/zip/codec/store/compress/rewind_spec.rb +9 -7
- data/spec/archive/zip/codec/store/compress/seek_spec.rb +15 -13
- data/spec/archive/zip/codec/store/compress/tell_spec.rb +11 -9
- data/spec/archive/zip/codec/store/compress/write_spec.rb +10 -10
- data/spec/archive/zip/codec/store/decompress/close_spec.rb +10 -9
- data/spec/archive/zip/codec/store/decompress/data_descriptor_spec.rb +17 -10
- data/spec/archive/zip/codec/store/decompress/new_spec.rb +5 -3
- data/spec/archive/zip/codec/store/decompress/open_spec.rb +7 -5
- data/spec/archive/zip/codec/store/decompress/read_spec.rb +8 -6
- data/spec/archive/zip/codec/store/decompress/rewind_spec.rb +9 -7
- data/spec/archive/zip/codec/store/decompress/seek_spec.rb +15 -13
- data/spec/archive/zip/codec/store/decompress/tell_spec.rb +8 -6
- data/spec/archive/zip/codec/traditional_encryption/decrypt/close_spec.rb +13 -24
- data/spec/archive/zip/codec/traditional_encryption/decrypt/new_spec.rb +6 -4
- data/spec/archive/zip/codec/traditional_encryption/decrypt/open_spec.rb +10 -6
- data/spec/archive/zip/codec/traditional_encryption/decrypt/read_spec.rb +12 -13
- data/spec/archive/zip/codec/traditional_encryption/decrypt/rewind_spec.rb +10 -12
- data/spec/archive/zip/codec/traditional_encryption/decrypt/seek_spec.rb +16 -18
- data/spec/archive/zip/codec/traditional_encryption/decrypt/tell_spec.rb +8 -6
- data/spec/archive/zip/codec/traditional_encryption/encrypt/close_spec.rb +13 -24
- data/spec/archive/zip/codec/traditional_encryption/encrypt/new_spec.rb +5 -3
- data/spec/archive/zip/codec/traditional_encryption/encrypt/open_spec.rb +7 -5
- data/spec/archive/zip/codec/traditional_encryption/encrypt/rewind_spec.rb +10 -12
- data/spec/archive/zip/codec/traditional_encryption/encrypt/seek_spec.rb +16 -18
- data/spec/archive/zip/codec/traditional_encryption/encrypt/tell_spec.rb +12 -14
- data/spec/archive/zip/codec/traditional_encryption/encrypt/write_spec.rb +8 -23
- data/spec/binary_stringio/new_spec.rb +18 -12
- data/spec/binary_stringio/set_encoding_spec.rb +10 -7
- data/spec/ioextensions/read_exactly_spec.rb +14 -12
- data/spec/zlib/zreader/checksum_spec.rb +10 -8
- data/spec/zlib/zreader/close_spec.rb +5 -3
- data/spec/zlib/zreader/compressed_size_spec.rb +6 -4
- data/spec/zlib/zreader/new_spec.rb +7 -5
- data/spec/zlib/zreader/open_spec.rb +9 -7
- data/spec/zlib/zreader/read_spec.rb +10 -8
- data/spec/zlib/zreader/rewind_spec.rb +7 -5
- data/spec/zlib/zreader/seek_spec.rb +13 -11
- data/spec/zlib/zreader/tell_spec.rb +8 -6
- data/spec/zlib/zreader/uncompressed_size_spec.rb +6 -4
- data/spec/zlib/zwriter/checksum_spec.rb +10 -8
- data/spec/zlib/zwriter/close_spec.rb +5 -3
- data/spec/zlib/zwriter/compressed_size_spec.rb +6 -4
- data/spec/zlib/zwriter/new_spec.rb +10 -8
- data/spec/zlib/zwriter/open_spec.rb +12 -10
- data/spec/zlib/zwriter/rewind_spec.rb +9 -7
- data/spec/zlib/zwriter/seek_spec.rb +15 -17
- data/spec/zlib/zwriter/tell_spec.rb +11 -9
- data/spec/zlib/zwriter/uncompressed_size_spec.rb +6 -4
- data/spec/zlib/zwriter/write_spec.rb +9 -9
- metadata +268 -217
- data/CONTRIBUTORS +0 -13
- data/GPL +0 -676
- data/HACKING +0 -105
- data/LEGAL +0 -8
- data/README +0 -151
- data/TODO +0 -5
- data/default.mspec +0 -8
- data/spec_helper.rb +0 -49
@@ -1,20 +1,22 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/support/zlib'
|
6
8
|
|
7
9
|
describe "Zlib::ZReader#tell" do
|
8
10
|
it "returns the current position of the stream" do
|
9
11
|
ZlibSpecs.compressed_data do |cd|
|
10
12
|
Zlib::ZReader.open(cd) do |zr|
|
11
|
-
zr.tell.
|
13
|
+
zr.tell.must_equal 0
|
12
14
|
zr.read(4)
|
13
|
-
zr.tell.
|
15
|
+
zr.tell.must_equal 4
|
14
16
|
zr.read
|
15
|
-
zr.tell.
|
17
|
+
zr.tell.must_equal 235
|
16
18
|
zr.rewind
|
17
|
-
zr.tell.
|
19
|
+
zr.tell.must_equal 0
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/support/zlib'
|
6
8
|
|
7
9
|
describe "Zlib::ZReader#uncompressed_size" do
|
@@ -9,10 +11,10 @@ describe "Zlib::ZReader#uncompressed_size" do
|
|
9
11
|
closed_zr = ZlibSpecs.compressed_data_raw do |compressed_data|
|
10
12
|
Zlib::ZReader.open(compressed_data, -15) do |zr|
|
11
13
|
zr.read
|
12
|
-
zr.uncompressed_size.
|
14
|
+
zr.uncompressed_size.must_equal 235
|
13
15
|
zr
|
14
16
|
end
|
15
17
|
end
|
16
|
-
closed_zr.uncompressed_size.
|
18
|
+
closed_zr.uncompressed_size.must_equal 235
|
17
19
|
end
|
18
20
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/support/zlib'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
@@ -11,10 +13,10 @@ describe "Zlib::ZWriter#checksum" do
|
|
11
13
|
closed_zw = Zlib::ZWriter.open(compressed_data, nil, 15) do |zw|
|
12
14
|
zw.write(ZlibSpecs.test_data)
|
13
15
|
zw.flush
|
14
|
-
zw.checksum.
|
16
|
+
zw.checksum.must_equal Zlib.adler32(ZlibSpecs.test_data)
|
15
17
|
zw
|
16
18
|
end
|
17
|
-
closed_zw.checksum.
|
19
|
+
closed_zw.checksum.must_equal Zlib.adler32(ZlibSpecs.test_data)
|
18
20
|
end
|
19
21
|
|
20
22
|
it "computes the CRC32 checksum of gzip formatted data" do
|
@@ -22,10 +24,10 @@ describe "Zlib::ZWriter#checksum" do
|
|
22
24
|
closed_zw = Zlib::ZWriter.open(compressed_data, nil, 31) do |zw|
|
23
25
|
zw.write(ZlibSpecs.test_data)
|
24
26
|
zw.flush
|
25
|
-
zw.checksum.
|
27
|
+
zw.checksum.must_equal Zlib.crc32(ZlibSpecs.test_data)
|
26
28
|
zw
|
27
29
|
end
|
28
|
-
closed_zw.checksum.
|
30
|
+
closed_zw.checksum.must_equal Zlib.crc32(ZlibSpecs.test_data)
|
29
31
|
end
|
30
32
|
|
31
33
|
it "does not compute a checksum for raw zlib data" do
|
@@ -33,9 +35,9 @@ describe "Zlib::ZWriter#checksum" do
|
|
33
35
|
closed_zw = Zlib::ZWriter.open(compressed_data, nil, -15) do |zw|
|
34
36
|
zw.write(ZlibSpecs.test_data)
|
35
37
|
zw.flush
|
36
|
-
zw.checksum.
|
38
|
+
zw.checksum.must_equal nil
|
37
39
|
zw
|
38
40
|
end
|
39
|
-
closed_zw.checksum.
|
41
|
+
closed_zw.checksum.must_equal nil
|
40
42
|
end
|
41
43
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/support/zlib'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
@@ -9,6 +11,6 @@ describe "Zlib::ZWriter.close" do
|
|
9
11
|
it "closes the stream" do
|
10
12
|
zw = Zlib::ZWriter.new(BinaryStringIO.new)
|
11
13
|
zw.close
|
12
|
-
zw.closed?.
|
14
|
+
zw.closed?.must_equal true
|
13
15
|
end
|
14
16
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/support/zlib'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
@@ -11,9 +13,9 @@ describe "Zlib::ZWriter#compressed_size" do
|
|
11
13
|
closed_zw = Zlib::ZWriter.open(compressed_data, nil, -15) do |zw|
|
12
14
|
zw.sync = true
|
13
15
|
zw.write(ZlibSpecs.test_data)
|
14
|
-
zw.compressed_size.
|
16
|
+
zw.compressed_size.must_be :>=, 0
|
15
17
|
zw
|
16
18
|
end
|
17
|
-
closed_zw.compressed_size.
|
19
|
+
closed_zw.compressed_size.must_equal 160
|
18
20
|
end
|
19
21
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/support/zlib'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
8
10
|
describe "Zlib::ZWriter.new" do
|
9
11
|
it "returns a new instance" do
|
10
12
|
zw = Zlib::ZWriter.new(BinaryStringIO.new)
|
11
|
-
zw.class.
|
13
|
+
zw.class.must_equal Zlib::ZWriter
|
12
14
|
zw.close
|
13
15
|
end
|
14
16
|
|
@@ -19,7 +21,7 @@ describe "Zlib::ZWriter.new" do
|
|
19
21
|
zw.write(data)
|
20
22
|
zw.close
|
21
23
|
|
22
|
-
compressed_data.string.
|
24
|
+
compressed_data.string.must_equal ZlibSpecs.compressed_data
|
23
25
|
end
|
24
26
|
|
25
27
|
it "allows level to be set" do
|
@@ -29,7 +31,7 @@ describe "Zlib::ZWriter.new" do
|
|
29
31
|
zw.write(data)
|
30
32
|
zw.close
|
31
33
|
|
32
|
-
compressed_data.string.
|
34
|
+
compressed_data.string.must_equal ZlibSpecs.compressed_data_nocomp
|
33
35
|
end
|
34
36
|
|
35
37
|
it "allows window_bits to be set" do
|
@@ -39,7 +41,7 @@ describe "Zlib::ZWriter.new" do
|
|
39
41
|
zw.write(data)
|
40
42
|
zw.close
|
41
43
|
|
42
|
-
compressed_data.string.
|
44
|
+
compressed_data.string.must_equal ZlibSpecs.compressed_data_minwin
|
43
45
|
end
|
44
46
|
|
45
47
|
it "allows mem_level to be set" do
|
@@ -49,7 +51,7 @@ describe "Zlib::ZWriter.new" do
|
|
49
51
|
zw.write(data)
|
50
52
|
zw.close
|
51
53
|
|
52
|
-
compressed_data.string.
|
54
|
+
compressed_data.string.must_equal ZlibSpecs.compressed_data_minmem
|
53
55
|
end
|
54
56
|
|
55
57
|
it "allows strategy to be set" do
|
@@ -59,6 +61,6 @@ describe "Zlib::ZWriter.new" do
|
|
59
61
|
zw.write(data)
|
60
62
|
zw.close
|
61
63
|
|
62
|
-
compressed_data.string.
|
64
|
+
compressed_data.string.must_equal ZlibSpecs.compressed_data_huffman
|
63
65
|
end
|
64
66
|
end
|
@@ -1,23 +1,25 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/support/zlib'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
8
10
|
describe "Zlib::ZWriter.open" do
|
9
11
|
it "returns a new instance when run without a block" do
|
10
12
|
zw = Zlib::ZWriter.open(BinaryStringIO.new)
|
11
|
-
zw.class.
|
13
|
+
zw.class.must_equal Zlib::ZWriter
|
12
14
|
zw.close
|
13
15
|
end
|
14
16
|
|
15
17
|
it "executes a block with a new instance as an argument" do
|
16
|
-
Zlib::ZWriter.open(BinaryStringIO.new) { |zr| zr.class.
|
18
|
+
Zlib::ZWriter.open(BinaryStringIO.new) { |zr| zr.class.must_equal Zlib::ZWriter }
|
17
19
|
end
|
18
20
|
|
19
21
|
it "closes the object after executing a block" do
|
20
|
-
Zlib::ZWriter.open(BinaryStringIO.new) { |zr| zr }.closed?.
|
22
|
+
Zlib::ZWriter.open(BinaryStringIO.new) { |zr| zr }.closed?.must_equal true
|
21
23
|
end
|
22
24
|
|
23
25
|
it "provides default settings for level, window_bits, mem_level, and strategy" do
|
@@ -25,7 +27,7 @@ describe "Zlib::ZWriter.open" do
|
|
25
27
|
compressed_data = BinaryStringIO.new
|
26
28
|
Zlib::ZWriter.open(compressed_data) { |zw| zw.write(data) }
|
27
29
|
|
28
|
-
compressed_data.string.
|
30
|
+
compressed_data.string.must_equal ZlibSpecs.compressed_data
|
29
31
|
end
|
30
32
|
|
31
33
|
it "allows level to be set" do
|
@@ -35,7 +37,7 @@ describe "Zlib::ZWriter.open" do
|
|
35
37
|
zw.write(data)
|
36
38
|
end
|
37
39
|
|
38
|
-
compressed_data.string.
|
40
|
+
compressed_data.string.must_equal ZlibSpecs.compressed_data_nocomp
|
39
41
|
end
|
40
42
|
|
41
43
|
it "allows window_bits to be set" do
|
@@ -43,7 +45,7 @@ describe "Zlib::ZWriter.open" do
|
|
43
45
|
compressed_data = BinaryStringIO.new
|
44
46
|
Zlib::ZWriter.open(compressed_data, nil, 8) { |zw| zw.write(data) }
|
45
47
|
|
46
|
-
compressed_data.string.
|
48
|
+
compressed_data.string.must_equal ZlibSpecs.compressed_data_minwin
|
47
49
|
end
|
48
50
|
|
49
51
|
it "allows mem_level to be set" do
|
@@ -51,7 +53,7 @@ describe "Zlib::ZWriter.open" do
|
|
51
53
|
compressed_data = BinaryStringIO.new
|
52
54
|
Zlib::ZWriter.open(compressed_data, nil, nil, 1) { |zw| zw.write(data) }
|
53
55
|
|
54
|
-
compressed_data.string.
|
56
|
+
compressed_data.string.must_equal ZlibSpecs.compressed_data_minmem
|
55
57
|
end
|
56
58
|
|
57
59
|
it "allows strategy to be set" do
|
@@ -63,6 +65,6 @@ describe "Zlib::ZWriter.open" do
|
|
63
65
|
zw.write(data)
|
64
66
|
end
|
65
67
|
|
66
|
-
compressed_data.string.
|
68
|
+
compressed_data.string.must_equal ZlibSpecs.compressed_data_huffman
|
67
69
|
end
|
68
70
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/support/zlib'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
@@ -10,17 +12,17 @@ describe "Zlib::ZWriter#rewind" do
|
|
10
12
|
sio = BinaryStringIO.new
|
11
13
|
Zlib::ZWriter.open(sio) do |zw|
|
12
14
|
zw.write('test')
|
13
|
-
|
15
|
+
zw.rewind
|
14
16
|
zw.write(ZlibSpecs.test_data)
|
15
17
|
end
|
16
|
-
sio.string.
|
18
|
+
sio.string.must_equal ZlibSpecs.compressed_data
|
17
19
|
end
|
18
20
|
|
19
21
|
it "raises Errno::EINVAL when attempting to rewind the stream when the delegate does not respond to rewind" do
|
20
|
-
delegate =
|
21
|
-
delegate.
|
22
|
+
delegate = MiniTest::Mock.new
|
23
|
+
delegate.expect(:write, 8, [String])
|
22
24
|
Zlib::ZWriter.open(delegate) do |zw|
|
23
|
-
lambda { zw.rewind }.
|
25
|
+
lambda { zw.rewind }.must_raise Errno::EINVAL
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/support/zlib'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
@@ -10,19 +12,15 @@ describe "Zlib::ZWriter#seek" do
|
|
10
12
|
compressed_data = BinaryStringIO.new
|
11
13
|
Zlib::ZWriter.open(compressed_data) do |c|
|
12
14
|
c.write('test')
|
13
|
-
|
15
|
+
c.seek(0).must_equal 0
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
19
|
it "raises Errno::EINVAL when attempting to seek to the beginning of the stream when the delegate does not respond to rewind" do
|
18
|
-
delegate =
|
19
|
-
|
20
|
-
# of version 1.5.10.
|
21
|
-
#delegate.should_receive(:write).with(an_instance_of(String)).at_least(:once).and_return { |s| s.length }
|
22
|
-
# Use the following instead for now.
|
23
|
-
delegate.should_receive(:write).at_least(:once).and_return(1)
|
20
|
+
delegate = MiniTest::Mock.new
|
21
|
+
delegate.expect(:write, 8, [String])
|
24
22
|
Zlib::ZWriter.open(delegate) do |c|
|
25
|
-
lambda { c.seek(0) }.
|
23
|
+
lambda { c.seek(0) }.must_raise Errno::EINVAL
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
@@ -30,25 +28,25 @@ describe "Zlib::ZWriter#seek" do
|
|
30
28
|
compressed_data = BinaryStringIO.new
|
31
29
|
Zlib::ZWriter.open(compressed_data) do |c|
|
32
30
|
c.write('test')
|
33
|
-
lambda { c.seek(1, IO::SEEK_CUR) }.
|
34
|
-
lambda { c.seek(-1, IO::SEEK_CUR) }.
|
31
|
+
lambda { c.seek(1, IO::SEEK_CUR) }.must_raise Errno::EINVAL
|
32
|
+
lambda { c.seek(-1, IO::SEEK_CUR) }.must_raise Errno::EINVAL
|
35
33
|
end
|
36
34
|
end
|
37
35
|
|
38
36
|
it "raises Errno::EINVAL when seeking a non-zero offset relative to the beginning of the stream" do
|
39
37
|
compressed_data = BinaryStringIO.new
|
40
38
|
Zlib::ZWriter.open(compressed_data) do |c|
|
41
|
-
lambda { c.seek(-1, IO::SEEK_SET) }.
|
42
|
-
lambda { c.seek(1, IO::SEEK_SET) }.
|
39
|
+
lambda { c.seek(-1, IO::SEEK_SET) }.must_raise Errno::EINVAL
|
40
|
+
lambda { c.seek(1, IO::SEEK_SET) }.must_raise Errno::EINVAL
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
46
44
|
it "raises Errno::EINVAL when seeking relative to the end of the stream" do
|
47
45
|
compressed_data = BinaryStringIO.new
|
48
46
|
Zlib::ZWriter.open(compressed_data) do |c|
|
49
|
-
lambda { c.seek(0, IO::SEEK_END) }.
|
50
|
-
lambda { c.seek(-1, IO::SEEK_END) }.
|
51
|
-
lambda { c.seek(1, IO::SEEK_END) }.
|
47
|
+
lambda { c.seek(0, IO::SEEK_END) }.must_raise Errno::EINVAL
|
48
|
+
lambda { c.seek(-1, IO::SEEK_END) }.must_raise Errno::EINVAL
|
49
|
+
lambda { c.seek(1, IO::SEEK_END) }.must_raise Errno::EINVAL
|
52
50
|
end
|
53
51
|
end
|
54
52
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/support/zlib'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
@@ -9,21 +11,21 @@ describe "Zlib::ZWriter#tell" do
|
|
9
11
|
it "returns the current position of the stream" do
|
10
12
|
sio = BinaryStringIO.new
|
11
13
|
Zlib::ZWriter.open(sio) do |zw|
|
12
|
-
zw.tell.
|
14
|
+
zw.tell.must_equal 0
|
13
15
|
zw.write('test1')
|
14
|
-
zw.tell.
|
16
|
+
zw.tell.must_equal 5
|
15
17
|
zw.write('test2')
|
16
|
-
zw.tell.
|
18
|
+
zw.tell.must_equal 10
|
17
19
|
zw.rewind
|
18
|
-
zw.tell.
|
20
|
+
zw.tell.must_equal 0
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
24
|
it "raises IOError on closed stream" do
|
23
|
-
delegate =
|
24
|
-
delegate.
|
25
|
+
delegate = MiniTest::Mock.new
|
26
|
+
delegate.expect(:write, 8, [String])
|
25
27
|
lambda do
|
26
28
|
Zlib::ZWriter.open(delegate) { |zw| zw }.tell
|
27
|
-
end.
|
29
|
+
end.must_raise IOError
|
28
30
|
end
|
29
31
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/support/zlib'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
@@ -11,9 +13,9 @@ describe "Zlib::ZWriter#uncompressed_size" do
|
|
11
13
|
closed_zw = Zlib::ZWriter.open(compressed_data, nil, -15) do |zw|
|
12
14
|
zw.sync = true
|
13
15
|
zw.write(ZlibSpecs.test_data)
|
14
|
-
zw.uncompressed_size.
|
16
|
+
zw.uncompressed_size.must_equal 235
|
15
17
|
zw
|
16
18
|
end
|
17
|
-
closed_zw.uncompressed_size.
|
19
|
+
closed_zw.uncompressed_size.must_equal 235
|
18
20
|
end
|
19
21
|
end
|