archive-zip 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HACKING +25 -42
- data/NEWS +25 -0
- data/README +2 -2
- data/Rakefile +202 -0
- data/TODO +5 -0
- data/default.mspec +8 -0
- data/lib/archive/support/binary_stringio.rb +23 -0
- data/lib/archive/support/integer.rb +13 -0
- data/lib/archive/support/io-like.rb +3 -1
- data/lib/archive/support/ioextensions.rb +16 -0
- data/lib/archive/support/iowindow.rb +10 -18
- data/lib/archive/support/time.rb +2 -0
- data/lib/archive/support/zlib.rb +298 -71
- data/lib/archive/zip.rb +161 -139
- data/lib/archive/zip/codec.rb +2 -0
- data/lib/archive/zip/codec/deflate.rb +59 -11
- data/lib/archive/zip/codec/null_encryption.rb +75 -14
- data/lib/archive/zip/codec/store.rb +75 -26
- data/lib/archive/zip/codec/traditional_encryption.rb +146 -35
- data/lib/archive/zip/data_descriptor.rb +6 -4
- data/lib/archive/zip/entry.rb +184 -132
- data/lib/archive/zip/error.rb +2 -0
- data/lib/archive/zip/extra_field.rb +20 -6
- data/lib/archive/zip/extra_field/extended_timestamp.rb +141 -60
- data/lib/archive/zip/extra_field/raw.rb +70 -12
- data/lib/archive/zip/extra_field/unix.rb +58 -16
- data/lib/archive/zip/version.rb +6 -0
- data/spec/archive/zip/codec/deflate/compress/checksum_spec.rb +42 -0
- data/spec/archive/zip/codec/deflate/compress/close_spec.rb +44 -0
- data/spec/archive/zip/codec/deflate/compress/crc32_spec.rb +21 -0
- data/spec/archive/zip/codec/deflate/compress/data_descriptor_spec.rb +67 -0
- data/spec/archive/zip/codec/deflate/compress/new_spec.rb +37 -0
- data/spec/archive/zip/codec/deflate/compress/open_spec.rb +46 -0
- data/spec/archive/zip/codec/deflate/compress/write_spec.rb +109 -0
- data/spec/archive/zip/codec/deflate/decompress/checksum_spec.rb +18 -0
- data/spec/archive/zip/codec/deflate/decompress/close_spec.rb +33 -0
- data/spec/archive/zip/codec/deflate/decompress/crc32_spec.rb +18 -0
- data/spec/archive/zip/codec/deflate/decompress/data_descriptor_spec.rb +67 -0
- data/spec/archive/zip/codec/deflate/decompress/new_spec.rb +14 -0
- data/spec/archive/zip/codec/deflate/decompress/open_spec.rb +27 -0
- data/spec/archive/zip/codec/deflate/fixtures/classes.rb +25 -0
- data/spec/archive/zip/codec/deflate/fixtures/compressed_file.bin +1 -0
- data/spec/archive/zip/codec/deflate/fixtures/compressed_file_nocomp.bin +0 -0
- data/spec/archive/zip/codec/deflate/fixtures/raw_file.txt +10 -0
- data/spec/archive/zip/codec/null_encryption/decrypt/close_spec.rb +33 -0
- data/spec/archive/zip/codec/null_encryption/decrypt/new_spec.rb +14 -0
- data/spec/archive/zip/codec/null_encryption/decrypt/open_spec.rb +27 -0
- data/spec/archive/zip/codec/null_encryption/decrypt/read_spec.rb +24 -0
- data/spec/archive/zip/codec/null_encryption/decrypt/rewind_spec.rb +25 -0
- data/spec/archive/zip/codec/null_encryption/decrypt/seek_spec.rb +57 -0
- data/spec/archive/zip/codec/null_encryption/decrypt/tell_spec.rb +21 -0
- data/spec/archive/zip/codec/null_encryption/encrypt/close_spec.rb +33 -0
- data/spec/archive/zip/codec/null_encryption/encrypt/new_spec.rb +14 -0
- data/spec/archive/zip/codec/null_encryption/encrypt/open_spec.rb +27 -0
- data/spec/archive/zip/codec/null_encryption/encrypt/rewind_spec.rb +26 -0
- data/spec/archive/zip/codec/null_encryption/encrypt/seek_spec.rb +50 -0
- data/spec/archive/zip/codec/null_encryption/encrypt/tell_spec.rb +29 -0
- data/spec/archive/zip/codec/null_encryption/encrypt/write_spec.rb +29 -0
- data/spec/archive/zip/codec/null_encryption/fixtures/classes.rb +12 -0
- data/spec/archive/zip/codec/null_encryption/fixtures/raw_file.txt +10 -0
- data/spec/archive/zip/codec/store/compress/close_spec.rb +33 -0
- data/spec/archive/zip/codec/store/compress/data_descriptor_spec.rb +68 -0
- data/spec/archive/zip/codec/store/compress/new_spec.rb +14 -0
- data/spec/archive/zip/codec/store/compress/open_spec.rb +27 -0
- data/spec/archive/zip/codec/store/compress/rewind_spec.rb +26 -0
- data/spec/archive/zip/codec/store/compress/seek_spec.rb +50 -0
- data/spec/archive/zip/codec/store/compress/tell_spec.rb +29 -0
- data/spec/archive/zip/codec/store/compress/write_spec.rb +29 -0
- data/spec/archive/zip/codec/store/decompress/close_spec.rb +33 -0
- data/spec/archive/zip/codec/store/decompress/data_descriptor_spec.rb +68 -0
- data/spec/archive/zip/codec/store/decompress/new_spec.rb +14 -0
- data/spec/archive/zip/codec/store/decompress/open_spec.rb +27 -0
- data/spec/archive/zip/codec/store/decompress/read_spec.rb +24 -0
- data/spec/archive/zip/codec/store/decompress/rewind_spec.rb +25 -0
- data/spec/archive/zip/codec/store/decompress/seek_spec.rb +57 -0
- data/spec/archive/zip/codec/store/decompress/tell_spec.rb +21 -0
- data/spec/archive/zip/codec/store/fixtures/classes.rb +12 -0
- data/spec/archive/zip/codec/store/fixtures/raw_file.txt +10 -0
- data/spec/archive/zip/codec/traditional_encryption/decrypt/close_spec.rb +64 -0
- data/spec/archive/zip/codec/traditional_encryption/decrypt/new_spec.rb +18 -0
- data/spec/archive/zip/codec/traditional_encryption/decrypt/open_spec.rb +39 -0
- data/spec/archive/zip/codec/traditional_encryption/decrypt/read_spec.rb +126 -0
- data/spec/archive/zip/codec/traditional_encryption/decrypt/rewind_spec.rb +38 -0
- data/spec/archive/zip/codec/traditional_encryption/decrypt/seek_spec.rb +82 -0
- data/spec/archive/zip/codec/traditional_encryption/decrypt/tell_spec.rb +25 -0
- data/spec/archive/zip/codec/traditional_encryption/encrypt/close_spec.rb +64 -0
- data/spec/archive/zip/codec/traditional_encryption/encrypt/new_spec.rb +18 -0
- data/spec/archive/zip/codec/traditional_encryption/encrypt/open_spec.rb +39 -0
- data/spec/archive/zip/codec/traditional_encryption/encrypt/rewind_spec.rb +41 -0
- data/spec/archive/zip/codec/traditional_encryption/encrypt/seek_spec.rb +75 -0
- data/spec/archive/zip/codec/traditional_encryption/encrypt/tell_spec.rb +42 -0
- data/spec/archive/zip/codec/traditional_encryption/encrypt/write_spec.rb +127 -0
- data/spec/archive/zip/codec/traditional_encryption/fixtures/classes.rb +27 -0
- data/spec/archive/zip/codec/traditional_encryption/fixtures/encrypted_file.bin +0 -0
- data/spec/archive/zip/codec/traditional_encryption/fixtures/raw_file.txt +10 -0
- data/spec/binary_stringio/new_spec.rb +34 -0
- data/spec/binary_stringio/set_encoding_spec.rb +14 -0
- data/spec/ioextensions/read_exactly_spec.rb +50 -0
- data/spec/zlib/fixtures/classes.rb +65 -0
- data/spec/zlib/fixtures/compressed_file.bin +1 -0
- data/spec/zlib/fixtures/compressed_file_gzip.bin +0 -0
- data/spec/zlib/fixtures/compressed_file_huffman.bin +2 -0
- data/spec/zlib/fixtures/compressed_file_minmem.bin +0 -0
- data/spec/zlib/fixtures/compressed_file_minwin.bin +1 -0
- data/spec/zlib/fixtures/compressed_file_nocomp.bin +0 -0
- data/spec/zlib/fixtures/compressed_file_raw.bin +1 -0
- data/spec/zlib/fixtures/raw_file.txt +10 -0
- data/spec/zlib/zreader/checksum_spec.rb +40 -0
- data/spec/zlib/zreader/close_spec.rb +14 -0
- data/spec/zlib/zreader/compressed_size_spec.rb +18 -0
- data/spec/zlib/zreader/new_spec.rb +41 -0
- data/spec/zlib/zreader/open_spec.rb +49 -0
- data/spec/zlib/zreader/read_spec.rb +47 -0
- data/spec/zlib/zreader/rewind_spec.rb +23 -0
- data/spec/zlib/zreader/seek_spec.rb +55 -0
- data/spec/zlib/zreader/tell_spec.rb +21 -0
- data/spec/zlib/zreader/uncompressed_size_spec.rb +18 -0
- data/spec/zlib/zwriter/checksum_spec.rb +41 -0
- data/spec/zlib/zwriter/close_spec.rb +14 -0
- data/spec/zlib/zwriter/compressed_size_spec.rb +19 -0
- data/spec/zlib/zwriter/new_spec.rb +64 -0
- data/spec/zlib/zwriter/open_spec.rb +68 -0
- data/spec/zlib/zwriter/rewind_spec.rb +26 -0
- data/spec/zlib/zwriter/seek_spec.rb +54 -0
- data/spec/zlib/zwriter/tell_spec.rb +29 -0
- data/spec/zlib/zwriter/uncompressed_size_spec.rb +19 -0
- data/spec/zlib/zwriter/write_spec.rb +28 -0
- data/spec_helper.rb +49 -0
- metadata +296 -74
- data/MANIFEST +0 -27
- data/lib/archive/support/io.rb +0 -14
- data/lib/archive/support/stringio.rb +0 -22
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../../spec_helper'
|
4
|
+
require File.dirname(__FILE__) + '/../fixtures/classes'
|
5
|
+
require 'archive/zip/codec/deflate'
|
6
|
+
|
7
|
+
describe "Archive::Zip::Codec::Deflate::Decompress#data_descriptor" do
|
8
|
+
it "is an instance of Archive::Zip::DataDescriptor" do
|
9
|
+
DeflateSpecs.compressed_data do |cd|
|
10
|
+
closed_decompressor = Archive::Zip::Codec::Deflate::Decompress.open(
|
11
|
+
cd
|
12
|
+
) do |decompressor|
|
13
|
+
decompressor.read
|
14
|
+
decompressor.data_descriptor.class.should ==
|
15
|
+
Archive::Zip::DataDescriptor
|
16
|
+
decompressor
|
17
|
+
end
|
18
|
+
closed_decompressor.data_descriptor.class.should ==
|
19
|
+
Archive::Zip::DataDescriptor
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "has a crc32 attribute containing the CRC32 checksum" do
|
24
|
+
crc32 = Zlib.crc32(DeflateSpecs.test_data)
|
25
|
+
DeflateSpecs.compressed_data do |cd|
|
26
|
+
closed_decompressor = Archive::Zip::Codec::Deflate::Decompress.open(
|
27
|
+
cd
|
28
|
+
) do |decompressor|
|
29
|
+
decompressor.read
|
30
|
+
decompressor.data_descriptor.crc32.should == crc32
|
31
|
+
decompressor
|
32
|
+
end
|
33
|
+
closed_decompressor.data_descriptor.crc32.should == crc32
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has a compressed_size attribute containing the size of the compressed data" do
|
38
|
+
compressed_size = DeflateSpecs.compressed_data.size
|
39
|
+
DeflateSpecs.compressed_data do |cd|
|
40
|
+
closed_decompressor = Archive::Zip::Codec::Deflate::Decompress.open(
|
41
|
+
cd
|
42
|
+
) do |decompressor|
|
43
|
+
decompressor.read
|
44
|
+
decompressor.data_descriptor.compressed_size.should == compressed_size
|
45
|
+
decompressor
|
46
|
+
end
|
47
|
+
closed_decompressor.data_descriptor.compressed_size.should ==
|
48
|
+
compressed_size
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "has an uncompressed_size attribute containing the size of the input data" do
|
53
|
+
uncompressed_size = DeflateSpecs.test_data.size
|
54
|
+
DeflateSpecs.compressed_data do |cd|
|
55
|
+
closed_decompressor = Archive::Zip::Codec::Deflate::Decompress.open(
|
56
|
+
cd
|
57
|
+
) do |decompressor|
|
58
|
+
decompressor.read
|
59
|
+
decompressor.data_descriptor.uncompressed_size.should ==
|
60
|
+
uncompressed_size
|
61
|
+
decompressor
|
62
|
+
end
|
63
|
+
closed_decompressor.data_descriptor.uncompressed_size.should ==
|
64
|
+
uncompressed_size
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../../spec_helper'
|
4
|
+
require File.dirname(__FILE__) + '/../fixtures/classes'
|
5
|
+
require 'archive/zip/codec/deflate'
|
6
|
+
require 'archive/support/binary_stringio'
|
7
|
+
|
8
|
+
describe "Archive::Zip::Codec::Deflate::Decompress.new" do
|
9
|
+
it "returns a new instance" do
|
10
|
+
d = Archive::Zip::Codec::Deflate::Decompress.new(BinaryStringIO.new)
|
11
|
+
d.class.should == Archive::Zip::Codec::Deflate::Decompress
|
12
|
+
d.close
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../../spec_helper'
|
4
|
+
require File.dirname(__FILE__) + '/../fixtures/classes'
|
5
|
+
require 'archive/zip/codec/deflate'
|
6
|
+
require 'archive/support/binary_stringio'
|
7
|
+
|
8
|
+
describe "Archive::Zip::Codec::Deflate::Decompress.open" do
|
9
|
+
it "returns a new instance when run without a block" do
|
10
|
+
d = Archive::Zip::Codec::Deflate::Decompress.open(BinaryStringIO.new)
|
11
|
+
d.class.should == Archive::Zip::Codec::Deflate::Decompress
|
12
|
+
d.close
|
13
|
+
end
|
14
|
+
|
15
|
+
it "executes a block with a new instance as an argument" do
|
16
|
+
Archive::Zip::Codec::Deflate::Decompress.open(BinaryStringIO.new) do |decompressor|
|
17
|
+
decompressor.class.should == Archive::Zip::Codec::Deflate::Decompress
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "closes the object after executing a block" do
|
22
|
+
d = Archive::Zip::Codec::Deflate::Decompress.open(BinaryStringIO.new) do |decompressor|
|
23
|
+
decompressor
|
24
|
+
end
|
25
|
+
d.closed?.should.be_true
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
class DeflateSpecs
|
4
|
+
def self.compressed_data_nocomp(&b)
|
5
|
+
File.open(
|
6
|
+
File.join(File.dirname(__FILE__), 'compressed_file_nocomp.bin'), 'rb'
|
7
|
+
) do |f|
|
8
|
+
f.read
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.compressed_data
|
13
|
+
File.open(
|
14
|
+
File.join(File.dirname(__FILE__), 'compressed_file.bin'), 'rb'
|
15
|
+
) do |f|
|
16
|
+
block_given? ? yield(f) : f.read
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.test_data
|
21
|
+
File.open(File.join(File.dirname(__FILE__), 'raw_file.txt'), 'rb') do |f|
|
22
|
+
block_given? ? yield(f) : f.read
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
%�A�0E�9�?A��\�kj���E5��K���o��)+�S.��-� �����Z����J[0��u~*����wC���D�m%���c�$Q�T����-ecx���pX"�m[K\ٝd�Ƌ����/n�Ɂr)>e����=��`��T�
|
Binary file
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../../spec_helper'
|
4
|
+
require File.dirname(__FILE__) + '/../fixtures/classes'
|
5
|
+
require 'archive/zip/codec/null_encryption'
|
6
|
+
require 'archive/support/binary_stringio'
|
7
|
+
|
8
|
+
describe "Archive::Zip::Codec::NullEncryption::Decrypt#close" do
|
9
|
+
it "closes the stream" do
|
10
|
+
d = Archive::Zip::Codec::NullEncryption::Decrypt.new(BinaryStringIO.new)
|
11
|
+
d.close
|
12
|
+
d.closed?.should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "closes the delegate stream by default" do
|
16
|
+
delegate = mock('delegate')
|
17
|
+
delegate.should_receive(:close).and_return(nil)
|
18
|
+
d = Archive::Zip::Codec::NullEncryption::Decrypt.new(delegate)
|
19
|
+
d.close
|
20
|
+
end
|
21
|
+
|
22
|
+
it "optionally leaves the delegate stream open" do
|
23
|
+
delegate = mock('delegate')
|
24
|
+
delegate.should_receive(:close).and_return(nil)
|
25
|
+
d = Archive::Zip::Codec::NullEncryption::Decrypt.new(delegate)
|
26
|
+
d.close(true)
|
27
|
+
|
28
|
+
delegate = mock('delegate')
|
29
|
+
delegate.should_not_receive(:close)
|
30
|
+
d = Archive::Zip::Codec::NullEncryption::Decrypt.new(delegate)
|
31
|
+
d.close(false)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../../spec_helper'
|
4
|
+
require File.dirname(__FILE__) + '/../fixtures/classes'
|
5
|
+
require 'archive/zip/codec/store'
|
6
|
+
require 'archive/support/binary_stringio'
|
7
|
+
|
8
|
+
describe "Archive::Zip::Codec::NullEncryption::Decrypt.new" do
|
9
|
+
it "returns a new instance" do
|
10
|
+
d = Archive::Zip::Codec::NullEncryption::Decrypt.new(BinaryStringIO.new)
|
11
|
+
d.class.should == Archive::Zip::Codec::NullEncryption::Decrypt
|
12
|
+
d.close
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../../spec_helper'
|
4
|
+
require File.dirname(__FILE__) + '/../fixtures/classes'
|
5
|
+
require 'archive/zip/codec/store'
|
6
|
+
require 'archive/support/binary_stringio'
|
7
|
+
|
8
|
+
describe "Archive::Zip::Codec::NullEncryption::Decrypt.open" do
|
9
|
+
it "returns a new instance when run without a block" do
|
10
|
+
d = Archive::Zip::Codec::NullEncryption::Decrypt.open(BinaryStringIO.new)
|
11
|
+
d.class.should == Archive::Zip::Codec::NullEncryption::Decrypt
|
12
|
+
d.close
|
13
|
+
end
|
14
|
+
|
15
|
+
it "executes a block with a new instance as an argument" do
|
16
|
+
Archive::Zip::Codec::NullEncryption::Decrypt.open(BinaryStringIO.new) do |decryptor|
|
17
|
+
decryptor.class.should == Archive::Zip::Codec::NullEncryption::Decrypt
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "closes the object after executing a block" do
|
22
|
+
d = Archive::Zip::Codec::NullEncryption::Decrypt.open(BinaryStringIO.new) do |decryptor|
|
23
|
+
decryptor
|
24
|
+
end
|
25
|
+
d.closed?.should.be_true
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../../spec_helper'
|
4
|
+
require File.dirname(__FILE__) + '/../fixtures/classes'
|
5
|
+
require 'archive/zip/codec/null_encryption'
|
6
|
+
|
7
|
+
describe "Archive::Zip::Codec::NullEncryption::Decrypt#read" do
|
8
|
+
it "calls the read method of the delegate" do
|
9
|
+
delegate = mock('delegate')
|
10
|
+
delegate.should_receive(:read).and_return(nil)
|
11
|
+
delegate.should_receive(:close).and_return(nil)
|
12
|
+
Archive::Zip::Codec::NullEncryption::Decrypt.open(delegate) do |d|
|
13
|
+
d.read
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "passes data through unmodified" do
|
18
|
+
NullEncryptionSpecs.encrypted_data do |ed|
|
19
|
+
Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
|
20
|
+
d.read.should == NullEncryptionSpecs.test_data
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../../spec_helper'
|
4
|
+
require File.dirname(__FILE__) + '/../fixtures/classes'
|
5
|
+
require 'archive/zip/codec/null_encryption'
|
6
|
+
|
7
|
+
describe "Archive::Zip::Codec::NullEncryption::Decrypt#rewind" do
|
8
|
+
it "can rewind the stream when the delegate responds to rewind" do
|
9
|
+
NullEncryptionSpecs.encrypted_data do |ed|
|
10
|
+
Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
|
11
|
+
d.read(4)
|
12
|
+
lambda { d.rewind }.should_not raise_error
|
13
|
+
d.read.should == NullEncryptionSpecs.test_data
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "raises Errno::EINVAL when attempting to rewind the stream when the delegate does not respond to rewind" do
|
19
|
+
delegate = mock('delegate')
|
20
|
+
delegate.should_receive(:close).and_return(nil)
|
21
|
+
Archive::Zip::Codec::NullEncryption::Decrypt.open(delegate) do |d|
|
22
|
+
lambda { d.rewind }.should raise_error(Errno::EINVAL)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../../spec_helper'
|
4
|
+
require File.dirname(__FILE__) + '/../fixtures/classes'
|
5
|
+
require 'archive/zip/codec/null_encryption'
|
6
|
+
|
7
|
+
describe "Archive::Zip::Codec::NullEncryption::Decrypt#seek" do
|
8
|
+
it "can seek to the beginning of the stream when the delegate responds to rewind" do
|
9
|
+
NullEncryptionSpecs.encrypted_data do |ed|
|
10
|
+
Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
|
11
|
+
d.read(4)
|
12
|
+
lambda { d.seek(0) }.should_not raise_error
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
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 = mock('delegate')
|
19
|
+
delegate.should_receive(:close).and_return(nil)
|
20
|
+
Archive::Zip::Codec::NullEncryption::Decrypt.open(delegate) do |d|
|
21
|
+
lambda { d.seek(0) }.should raise_error(Errno::EINVAL)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "raises Errno::EINVAL when seeking forward or backward from the current position of the stream" do
|
26
|
+
NullEncryptionSpecs.encrypted_data do |ed|
|
27
|
+
Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
|
28
|
+
# Disable read buffering to avoid some seeking optimizations implemented
|
29
|
+
# by IO::Like which allow seeking forward within the buffer.
|
30
|
+
d.fill_size = 0
|
31
|
+
|
32
|
+
d.read(4)
|
33
|
+
lambda { d.seek(1, IO::SEEK_CUR) }.should raise_error(Errno::EINVAL)
|
34
|
+
lambda { d.seek(-1, IO::SEEK_CUR) }.should raise_error(Errno::EINVAL)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "raises Errno::EINVAL when seeking a non-zero offset relative to the beginning of the stream" do
|
40
|
+
NullEncryptionSpecs.encrypted_data do |ed|
|
41
|
+
Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
|
42
|
+
lambda { d.seek(-1, IO::SEEK_SET) }.should raise_error(Errno::EINVAL)
|
43
|
+
lambda { d.seek(1, IO::SEEK_SET) }.should raise_error(Errno::EINVAL)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "raises Errno::EINVAL when seeking relative to the end of the stream" do
|
49
|
+
NullEncryptionSpecs.encrypted_data do |ed|
|
50
|
+
Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
|
51
|
+
lambda { d.seek(0, IO::SEEK_END) }.should raise_error(Errno::EINVAL)
|
52
|
+
lambda { d.seek(-1, IO::SEEK_END) }.should raise_error(Errno::EINVAL)
|
53
|
+
lambda { d.seek(1, IO::SEEK_END) }.should raise_error(Errno::EINVAL)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../../spec_helper'
|
4
|
+
require File.dirname(__FILE__) + '/../fixtures/classes'
|
5
|
+
require 'archive/zip/codec/null_encryption'
|
6
|
+
|
7
|
+
describe "Archive::Zip::Codec::NullEncryption::Decrypt#tell" do
|
8
|
+
it "returns the current position of the stream" do
|
9
|
+
NullEncryptionSpecs.encrypted_data do |ed|
|
10
|
+
Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
|
11
|
+
d.tell.should == 0
|
12
|
+
d.read(4)
|
13
|
+
d.tell.should == 4
|
14
|
+
d.read
|
15
|
+
d.tell.should == 235
|
16
|
+
d.rewind
|
17
|
+
d.tell.should == 0
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../../spec_helper'
|
4
|
+
require File.dirname(__FILE__) + '/../fixtures/classes'
|
5
|
+
require 'archive/zip/codec/null_encryption'
|
6
|
+
require 'archive/support/binary_stringio'
|
7
|
+
|
8
|
+
describe "Archive::Zip::Codec::NullEncryption::Encrypt#close" do
|
9
|
+
it "closes the stream" do
|
10
|
+
e = Archive::Zip::Codec::NullEncryption::Encrypt.new(BinaryStringIO.new)
|
11
|
+
e.close
|
12
|
+
e.closed?.should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "closes the delegate stream by default" do
|
16
|
+
delegate = mock('delegate')
|
17
|
+
delegate.should_receive(:close).and_return(nil)
|
18
|
+
e = Archive::Zip::Codec::NullEncryption::Encrypt.new(delegate)
|
19
|
+
e.close
|
20
|
+
end
|
21
|
+
|
22
|
+
it "optionally leaves the delegate stream open" do
|
23
|
+
delegate = mock('delegate')
|
24
|
+
delegate.should_receive(:close).and_return(nil)
|
25
|
+
e = Archive::Zip::Codec::NullEncryption::Encrypt.new(delegate)
|
26
|
+
e.close(true)
|
27
|
+
|
28
|
+
delegate = mock('delegate')
|
29
|
+
delegate.should_not_receive(:close)
|
30
|
+
e = Archive::Zip::Codec::NullEncryption::Encrypt.new(delegate)
|
31
|
+
e.close(false)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../../spec_helper'
|
4
|
+
require File.dirname(__FILE__) + '/../fixtures/classes'
|
5
|
+
require 'archive/zip/codec/null_encryption'
|
6
|
+
require 'archive/support/binary_stringio'
|
7
|
+
|
8
|
+
describe "Archive::Zip::Codec::NullEncryption::Encrypt.new" do
|
9
|
+
it "returns a new instance" do
|
10
|
+
e = Archive::Zip::Codec::NullEncryption::Encrypt.new(BinaryStringIO.new)
|
11
|
+
e.class.should == Archive::Zip::Codec::NullEncryption::Encrypt
|
12
|
+
e.close
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../../spec_helper'
|
4
|
+
require File.dirname(__FILE__) + '/../fixtures/classes'
|
5
|
+
require 'archive/zip/codec/null_encryption'
|
6
|
+
require 'archive/support/binary_stringio'
|
7
|
+
|
8
|
+
describe "Archive::Zip::Codec::NullEncryption::Encrypt.open" do
|
9
|
+
it "returns a new instance when run without a block" do
|
10
|
+
e = Archive::Zip::Codec::NullEncryption::Encrypt.open(BinaryStringIO.new)
|
11
|
+
e.class.should == Archive::Zip::Codec::NullEncryption::Encrypt
|
12
|
+
e.close
|
13
|
+
end
|
14
|
+
|
15
|
+
it "executes a block with a new instance as an argument" do
|
16
|
+
Archive::Zip::Codec::NullEncryption::Encrypt.open(BinaryStringIO.new) do |encryptor|
|
17
|
+
encryptor.class.should == Archive::Zip::Codec::NullEncryption::Encrypt
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "closes the object after executing a block" do
|
22
|
+
e = Archive::Zip::Codec::NullEncryption::Encrypt.open(BinaryStringIO.new) do |encryptor|
|
23
|
+
encryptor
|
24
|
+
end
|
25
|
+
e.closed?.should.be_true
|
26
|
+
end
|
27
|
+
end
|