archive-zip 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,26 @@
|
|
|
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#rewind" do
|
|
9
|
+
it "can rewind the stream when the delegate responds to rewind" do
|
|
10
|
+
encrypted_data = BinaryStringIO.new
|
|
11
|
+
Archive::Zip::Codec::NullEncryption::Encrypt.open(encrypted_data) do |e|
|
|
12
|
+
e.write('test')
|
|
13
|
+
lambda { e.rewind }.should_not raise_error
|
|
14
|
+
e.write(NullEncryptionSpecs.test_data)
|
|
15
|
+
end
|
|
16
|
+
encrypted_data.string.should == NullEncryptionSpecs.encrypted_data
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "raises Errno::EINVAL when attempting to rewind the stream when the delegate does not respond to rewind" do
|
|
20
|
+
delegate = mock('delegate')
|
|
21
|
+
delegate.should_receive(:close).once.and_return(nil)
|
|
22
|
+
Archive::Zip::Codec::NullEncryption::Encrypt.open(delegate) do |e|
|
|
23
|
+
lambda { e.rewind }.should raise_error(Errno::EINVAL)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
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#seek" do
|
|
9
|
+
it "can seek to the beginning of the stream when the delegate responds to rewind" do
|
|
10
|
+
encrypted_data = BinaryStringIO.new
|
|
11
|
+
Archive::Zip::Codec::NullEncryption::Encrypt.open(encrypted_data) do |e|
|
|
12
|
+
e.write('test')
|
|
13
|
+
lambda { e.seek(0) }.should_not raise_error
|
|
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::Encrypt.open(delegate) do |e|
|
|
21
|
+
lambda { e.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
|
+
encrypted_data = BinaryStringIO.new
|
|
27
|
+
Archive::Zip::Codec::NullEncryption::Encrypt.open(encrypted_data) do |e|
|
|
28
|
+
e.write('test')
|
|
29
|
+
lambda { e.seek(1, IO::SEEK_CUR) }.should raise_error(Errno::EINVAL)
|
|
30
|
+
lambda { e.seek(-1, IO::SEEK_CUR) }.should raise_error(Errno::EINVAL)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "raises Errno::EINVAL when seeking a non-zero offset relative to the beginning of the stream" do
|
|
35
|
+
encrypted_data = BinaryStringIO.new
|
|
36
|
+
Archive::Zip::Codec::NullEncryption::Encrypt.open(encrypted_data) do |e|
|
|
37
|
+
lambda { e.seek(-1, IO::SEEK_SET) }.should raise_error(Errno::EINVAL)
|
|
38
|
+
lambda { e.seek(1, IO::SEEK_SET) }.should raise_error(Errno::EINVAL)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "raises Errno::EINVAL when seeking relative to the end of the stream" do
|
|
43
|
+
encrypted_data = BinaryStringIO.new
|
|
44
|
+
Archive::Zip::Codec::NullEncryption::Encrypt.open(encrypted_data) do |e|
|
|
45
|
+
lambda { e.seek(0, IO::SEEK_END) }.should raise_error(Errno::EINVAL)
|
|
46
|
+
lambda { e.seek(-1, IO::SEEK_END) }.should raise_error(Errno::EINVAL)
|
|
47
|
+
lambda { e.seek(1, IO::SEEK_END) }.should raise_error(Errno::EINVAL)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
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#tell" do
|
|
9
|
+
it "returns the current position of the stream" do
|
|
10
|
+
sio = BinaryStringIO.new
|
|
11
|
+
Archive::Zip::Codec::NullEncryption::Encrypt.open(sio) do |e|
|
|
12
|
+
e.tell.should == 0
|
|
13
|
+
e.write('test1')
|
|
14
|
+
e.tell.should == 5
|
|
15
|
+
e.write('test2')
|
|
16
|
+
e.tell.should == 10
|
|
17
|
+
e.rewind
|
|
18
|
+
e.tell.should == 0
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "raises IOError on closed stream" do
|
|
23
|
+
delegate = mock('delegate')
|
|
24
|
+
delegate.should_receive(:close).once.and_return(nil)
|
|
25
|
+
lambda do
|
|
26
|
+
Archive::Zip::Codec::NullEncryption::Encrypt.open(delegate) { |e| e }.tell
|
|
27
|
+
end.should raise_error(IOError)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
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#write" do
|
|
9
|
+
it "calls the write method of the delegate" do
|
|
10
|
+
delegate = mock('delegate')
|
|
11
|
+
# RSpec's mocking facility supposedly supports this, but MSpec's does not as
|
|
12
|
+
# of version 1.5.10.
|
|
13
|
+
#delegate.should_receive(:write).with(an_instance_of(String)).at_least(:once).and_return { |s| s.length }
|
|
14
|
+
# Use the following instead for now.
|
|
15
|
+
delegate.should_receive(:write).at_least(:once).and_return(1)
|
|
16
|
+
delegate.should_receive(:close).once.and_return(nil)
|
|
17
|
+
Archive::Zip::Codec::NullEncryption::Encrypt.open(delegate) do |e|
|
|
18
|
+
e.write(NullEncryptionSpecs.test_data)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "passes data through unmodified" do
|
|
23
|
+
encrypted_data = BinaryStringIO.new
|
|
24
|
+
Archive::Zip::Codec::NullEncryption::Encrypt.open(encrypted_data) do |e|
|
|
25
|
+
e.write(NullEncryptionSpecs.test_data)
|
|
26
|
+
end
|
|
27
|
+
encrypted_data.string.should == NullEncryptionSpecs.encrypted_data
|
|
28
|
+
end
|
|
29
|
+
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/store'
|
|
6
|
+
require 'archive/support/binary_stringio'
|
|
7
|
+
|
|
8
|
+
describe "Archive::Zip::Codec::Store::Compress#close" do
|
|
9
|
+
it "closes the stream" do
|
|
10
|
+
c = Archive::Zip::Codec::Store::Compress.new(BinaryStringIO.new)
|
|
11
|
+
c.close
|
|
12
|
+
c.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
|
+
c = Archive::Zip::Codec::Store::Compress.new(delegate)
|
|
19
|
+
c.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
|
+
c = Archive::Zip::Codec::Store::Compress.new(delegate)
|
|
26
|
+
c.close(true)
|
|
27
|
+
|
|
28
|
+
delegate = mock('delegate')
|
|
29
|
+
delegate.should_not_receive(:close)
|
|
30
|
+
c = Archive::Zip::Codec::Store::Compress.new(delegate)
|
|
31
|
+
c.close(false)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../../spec_helper'
|
|
4
|
+
require File.dirname(__FILE__) + '/../fixtures/classes'
|
|
5
|
+
require 'archive/support/zlib'
|
|
6
|
+
require 'archive/zip/codec/store'
|
|
7
|
+
require 'archive/support/binary_stringio'
|
|
8
|
+
|
|
9
|
+
describe "Archive::Zip::Codec::Store::Compress#data_descriptor" do
|
|
10
|
+
it "is an instance of Archive::Zip::DataDescriptor" do
|
|
11
|
+
test_data = StoreSpecs.test_data
|
|
12
|
+
compressed_data = BinaryStringIO.new
|
|
13
|
+
closed_compressor = Archive::Zip::Codec::Store::Compress.open(
|
|
14
|
+
compressed_data
|
|
15
|
+
) do |compressor|
|
|
16
|
+
compressor.write(test_data)
|
|
17
|
+
compressor.flush
|
|
18
|
+
compressor.data_descriptor.class.should == Archive::Zip::DataDescriptor
|
|
19
|
+
compressor
|
|
20
|
+
end
|
|
21
|
+
closed_compressor.data_descriptor.class.should ==
|
|
22
|
+
Archive::Zip::DataDescriptor
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "has a crc32 attribute containing the CRC32 checksum" do
|
|
26
|
+
test_data = StoreSpecs.test_data
|
|
27
|
+
compressed_data = BinaryStringIO.new
|
|
28
|
+
closed_compressor = Archive::Zip::Codec::Store::Compress.open(
|
|
29
|
+
compressed_data
|
|
30
|
+
) do |compressor|
|
|
31
|
+
compressor.write(test_data)
|
|
32
|
+
compressor.flush
|
|
33
|
+
compressor.data_descriptor.crc32.should == Zlib.crc32(test_data)
|
|
34
|
+
compressor
|
|
35
|
+
end
|
|
36
|
+
closed_compressor.data_descriptor.crc32.should == Zlib.crc32(test_data)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "has a compressed_size attribute containing the size of the compressed data" do
|
|
40
|
+
test_data = StoreSpecs.test_data
|
|
41
|
+
compressed_data = BinaryStringIO.new
|
|
42
|
+
closed_compressor = Archive::Zip::Codec::Store::Compress.open(
|
|
43
|
+
compressed_data
|
|
44
|
+
) do |compressor|
|
|
45
|
+
compressor.write(test_data)
|
|
46
|
+
compressor.flush
|
|
47
|
+
compressor.data_descriptor.compressed_size.should ==
|
|
48
|
+
compressed_data.string.size
|
|
49
|
+
compressor
|
|
50
|
+
end
|
|
51
|
+
closed_compressor.data_descriptor.compressed_size.should ==
|
|
52
|
+
compressed_data.string.size
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "has an uncompressed_size attribute containing the size of the input data" do
|
|
56
|
+
test_data = StoreSpecs.test_data
|
|
57
|
+
compressed_data = BinaryStringIO.new
|
|
58
|
+
closed_compressor = Archive::Zip::Codec::Store::Compress.open(
|
|
59
|
+
compressed_data
|
|
60
|
+
) do |compressor|
|
|
61
|
+
compressor.write(test_data)
|
|
62
|
+
compressor.flush
|
|
63
|
+
compressor.data_descriptor.uncompressed_size.should == test_data.size
|
|
64
|
+
compressor
|
|
65
|
+
end
|
|
66
|
+
closed_compressor.data_descriptor.uncompressed_size.should == test_data.size
|
|
67
|
+
end
|
|
68
|
+
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::Store::Compress.new" do
|
|
9
|
+
it "returns a new instance" do
|
|
10
|
+
c = Archive::Zip::Codec::Store::Compress.new(BinaryStringIO.new)
|
|
11
|
+
c.class.should == Archive::Zip::Codec::Store::Compress
|
|
12
|
+
c.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::Store::Compress.open" do
|
|
9
|
+
it "returns a new instance when run without a block" do
|
|
10
|
+
c = Archive::Zip::Codec::Store::Compress.open(BinaryStringIO.new)
|
|
11
|
+
c.class.should == Archive::Zip::Codec::Store::Compress
|
|
12
|
+
c.close
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "executes a block with a new instance as an argument" do
|
|
16
|
+
Archive::Zip::Codec::Store::Compress.open(BinaryStringIO.new) do |compressor|
|
|
17
|
+
compressor.class.should == Archive::Zip::Codec::Store::Compress
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "closes the object after executing a block" do
|
|
22
|
+
c = Archive::Zip::Codec::Store::Compress.open(BinaryStringIO.new) do |compressor|
|
|
23
|
+
compressor
|
|
24
|
+
end
|
|
25
|
+
c.closed?.should.be_true
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
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::Store::Compress#rewind" do
|
|
9
|
+
it "can rewind the stream when the delegate responds to rewind" do
|
|
10
|
+
sio = BinaryStringIO.new
|
|
11
|
+
Archive::Zip::Codec::Store::Compress.open(sio) do |c|
|
|
12
|
+
c.write('test')
|
|
13
|
+
lambda { c.rewind }.should_not raise_error
|
|
14
|
+
c.write(StoreSpecs.test_data)
|
|
15
|
+
end
|
|
16
|
+
sio.string.should == StoreSpecs.compressed_data
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "raises Errno::EINVAL when attempting to rewind the stream when the delegate does not respond to rewind" do
|
|
20
|
+
delegate = mock('delegate')
|
|
21
|
+
delegate.should_receive(:close).once.and_return(nil)
|
|
22
|
+
Archive::Zip::Codec::Store::Compress.open(delegate) do |c|
|
|
23
|
+
lambda { c.rewind }.should raise_error(Errno::EINVAL)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
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::Store::Compress#seek" do
|
|
9
|
+
it "can seek to the beginning of the stream when the delegate responds to rewind" do
|
|
10
|
+
compressed_data = BinaryStringIO.new
|
|
11
|
+
Archive::Zip::Codec::Store::Compress.open(compressed_data) do |c|
|
|
12
|
+
c.write('test')
|
|
13
|
+
lambda { c.seek(0) }.should_not raise_error
|
|
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::Store::Compress.open(delegate) do |c|
|
|
21
|
+
lambda { c.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
|
+
compressed_data = BinaryStringIO.new
|
|
27
|
+
Archive::Zip::Codec::Store::Compress.open(compressed_data) do |c|
|
|
28
|
+
c.write('test')
|
|
29
|
+
lambda { c.seek(1, IO::SEEK_CUR) }.should raise_error(Errno::EINVAL)
|
|
30
|
+
lambda { c.seek(-1, IO::SEEK_CUR) }.should raise_error(Errno::EINVAL)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "raises Errno::EINVAL when seeking a non-zero offset relative to the beginning of the stream" do
|
|
35
|
+
compressed_data = BinaryStringIO.new
|
|
36
|
+
Archive::Zip::Codec::Store::Compress.open(compressed_data) do |c|
|
|
37
|
+
lambda { c.seek(-1, IO::SEEK_SET) }.should raise_error(Errno::EINVAL)
|
|
38
|
+
lambda { c.seek(1, IO::SEEK_SET) }.should raise_error(Errno::EINVAL)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "raises Errno::EINVAL when seeking relative to the end of the stream" do
|
|
43
|
+
compressed_data = BinaryStringIO.new
|
|
44
|
+
Archive::Zip::Codec::Store::Compress.open(compressed_data) do |c|
|
|
45
|
+
lambda { c.seek(0, IO::SEEK_END) }.should raise_error(Errno::EINVAL)
|
|
46
|
+
lambda { c.seek(-1, IO::SEEK_END) }.should raise_error(Errno::EINVAL)
|
|
47
|
+
lambda { c.seek(1, IO::SEEK_END) }.should raise_error(Errno::EINVAL)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
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::Store::Compress#tell" do
|
|
9
|
+
it "returns the current position of the stream" do
|
|
10
|
+
sio = BinaryStringIO.new
|
|
11
|
+
Archive::Zip::Codec::Store::Compress.open(sio) do |c|
|
|
12
|
+
c.tell.should == 0
|
|
13
|
+
c.write('test1')
|
|
14
|
+
c.tell.should == 5
|
|
15
|
+
c.write('test2')
|
|
16
|
+
c.tell.should == 10
|
|
17
|
+
c.rewind
|
|
18
|
+
c.tell.should == 0
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "raises IOError on closed stream" do
|
|
23
|
+
delegate = mock('delegate')
|
|
24
|
+
delegate.should_receive(:close).once.and_return(nil)
|
|
25
|
+
lambda do
|
|
26
|
+
Archive::Zip::Codec::Store::Compress.open(delegate) { |c| c }.tell
|
|
27
|
+
end.should raise_error(IOError)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
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::Store::Compress#write" do
|
|
9
|
+
it "calls the write method of the delegate" do
|
|
10
|
+
delegate = mock('delegate')
|
|
11
|
+
# RSpec's mocking facility supposedly supports this, but MSpec's does not as
|
|
12
|
+
# of version 1.5.10.
|
|
13
|
+
#delegate.should_receive(:write).with(an_instance_of(String)).at_least(:once).and_return { |s| s.length }
|
|
14
|
+
# Use the following instead for now.
|
|
15
|
+
delegate.should_receive(:write).at_least(:once).and_return(1)
|
|
16
|
+
delegate.should_receive(:close).once.and_return(nil)
|
|
17
|
+
Archive::Zip::Codec::Store::Compress.open(delegate) do |c|
|
|
18
|
+
c.write(StoreSpecs.test_data)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "passes data through unmodified" do
|
|
23
|
+
compressed_data = BinaryStringIO.new
|
|
24
|
+
Archive::Zip::Codec::Store::Compress.open(compressed_data) do |c|
|
|
25
|
+
c.write(StoreSpecs.test_data)
|
|
26
|
+
end
|
|
27
|
+
compressed_data.string.should == StoreSpecs.compressed_data
|
|
28
|
+
end
|
|
29
|
+
end
|