zip-container 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +6 -0
- data/Changes.rdoc +23 -0
- data/ReadMe.rdoc +12 -1
- data/examples/create-zip-container +1 -1
- data/examples/verify-zip-container +1 -1
- data/examples/zip-container-info +1 -1
- data/lib/zip-container.rb +2 -1
- data/lib/zip-container/entries/directory.rb +17 -7
- data/lib/zip-container/entries/entry.rb +16 -4
- data/lib/zip-container/entries/file.rb +21 -10
- data/lib/zip-container/entries/managed.rb +47 -13
- data/lib/zip-container/entries/reserved.rb +3 -3
- data/lib/zip-container/exceptions.rb +11 -5
- data/lib/zip-container/{container.rb → file.rb} +85 -17
- data/lib/zip-container/util.rb +59 -0
- data/test/data/subclassed.container +0 -0
- data/test/helpers/entry_lists.rb +35 -0
- data/test/tc_create.rb +10 -10
- data/test/tc_exceptions.rb +56 -0
- data/test/tc_managed_entries.rb +127 -12
- data/test/tc_read.rb +13 -13
- data/test/tc_reserved_names.rb +11 -11
- data/test/tc_util.rb +67 -0
- data/test/ts_container.rb +4 -1
- data/version.yml +2 -2
- data/zip-container.gemspec +2 -1
- metadata +15 -6
data/test/tc_read.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2013 The University of Manchester, UK.
|
1
|
+
# Copyright (c) 2013, 2014 The University of Manchester, UK.
|
2
2
|
#
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
@@ -37,38 +37,38 @@ class TestRead < Test::Unit::TestCase
|
|
37
37
|
|
38
38
|
# Check that the null file does not verify.
|
39
39
|
def test_verify_null_file
|
40
|
-
assert_raise(
|
41
|
-
ZipContainer::
|
40
|
+
assert_raise(ZipContainer::ZipError) do
|
41
|
+
ZipContainer::File.verify!($file_null)
|
42
42
|
end
|
43
43
|
|
44
|
-
refute(ZipContainer::
|
44
|
+
refute(ZipContainer::File.verify($file_null))
|
45
45
|
end
|
46
46
|
|
47
47
|
# Check that the empty container file does verify.
|
48
48
|
def test_verify_empty_container
|
49
|
-
assert_nothing_raised(ZipContainer::MalformedContainerError,
|
50
|
-
ZipContainer::
|
49
|
+
assert_nothing_raised(ZipContainer::MalformedContainerError, ZipContainer::ZipError) do
|
50
|
+
ZipContainer::File.verify!($empty)
|
51
51
|
end
|
52
52
|
|
53
|
-
assert(ZipContainer::
|
53
|
+
assert(ZipContainer::File.verify($empty))
|
54
54
|
end
|
55
55
|
|
56
56
|
# Check that the empty zip file does not verify.
|
57
57
|
def test_verify_empty_zip
|
58
58
|
assert_raise(ZipContainer::MalformedContainerError) do
|
59
|
-
ZipContainer::
|
59
|
+
ZipContainer::File.verify!($empty_zip)
|
60
60
|
end
|
61
61
|
|
62
|
-
refute(ZipContainer::
|
62
|
+
refute(ZipContainer::File.verify($empty_zip))
|
63
63
|
end
|
64
64
|
|
65
65
|
# Check that a compressed mimetype file is detected.
|
66
66
|
def test_verify_compressed_mimetype
|
67
67
|
assert_raise(ZipContainer::MalformedContainerError) do
|
68
|
-
ZipContainer::
|
68
|
+
ZipContainer::File.verify!($compressed_mimetype)
|
69
69
|
end
|
70
70
|
|
71
|
-
refute(ZipContainer::
|
71
|
+
refute(ZipContainer::File.verify($compressed_mimetype))
|
72
72
|
end
|
73
73
|
|
74
74
|
# Check the raw mimetype bytes
|
@@ -83,8 +83,8 @@ class TestRead < Test::Unit::TestCase
|
|
83
83
|
# Check reading files out of a container file and make sure we don't change
|
84
84
|
# it.
|
85
85
|
def test_read_files_from_container
|
86
|
-
assert_nothing_raised(ZipContainer::MalformedContainerError,
|
87
|
-
ZipContainer::
|
86
|
+
assert_nothing_raised(ZipContainer::MalformedContainerError, ZipContainer::ZipError) do
|
87
|
+
ZipContainer::File.open($example) do |c|
|
88
88
|
assert(c.on_disk?)
|
89
89
|
refute(c.in_memory?)
|
90
90
|
|
data/test/tc_reserved_names.rb
CHANGED
@@ -34,7 +34,7 @@ require 'test/unit'
|
|
34
34
|
require 'zip-container'
|
35
35
|
|
36
36
|
# A class to test the overriding of reserved and managed names.
|
37
|
-
class NewZipContainer < ZipContainer::
|
37
|
+
class NewZipContainer < ZipContainer::File
|
38
38
|
|
39
39
|
private_class_method :new
|
40
40
|
|
@@ -66,7 +66,7 @@ class TestReservedNames < Test::Unit::TestCase
|
|
66
66
|
# Check the reserved names stuff all works correctly, baring in mind that
|
67
67
|
# such comparisons for ZipContainer file should be case sensitive.
|
68
68
|
def test_reserved_names
|
69
|
-
ZipContainer::
|
69
|
+
ZipContainer::File.open($example) do |c|
|
70
70
|
assert_equal(1, c.reserved_names.length)
|
71
71
|
assert_equal(["mimetype"], c.reserved_names)
|
72
72
|
|
@@ -129,7 +129,7 @@ class TestReservedNames < Test::Unit::TestCase
|
|
129
129
|
|
130
130
|
# Check that nothing happens when trying to delete the mimetype file.
|
131
131
|
def test_delete_mimetype
|
132
|
-
ZipContainer::
|
132
|
+
ZipContainer::File.open($example) do |c|
|
133
133
|
assert(c.file.exists?("mimetype"))
|
134
134
|
assert_nil(c.remove("mimetype"))
|
135
135
|
assert(c.file.exists?("mimetype"))
|
@@ -138,7 +138,7 @@ class TestReservedNames < Test::Unit::TestCase
|
|
138
138
|
|
139
139
|
# Check that nothing happens when trying to rename the mimetype file.
|
140
140
|
def test_rename_mimetype
|
141
|
-
ZipContainer::
|
141
|
+
ZipContainer::File.open($example) do |c|
|
142
142
|
assert(c.file.exists?("mimetype"))
|
143
143
|
assert_nil(c.rename("mimetype", "something-else"))
|
144
144
|
assert(c.file.exists?("mimetype"))
|
@@ -149,7 +149,7 @@ class TestReservedNames < Test::Unit::TestCase
|
|
149
149
|
# Check that nothing happens when trying to replace the contents of the
|
150
150
|
# mimetype file.
|
151
151
|
def test_replace_mimetype
|
152
|
-
ZipContainer::
|
152
|
+
ZipContainer::File.open($example) do |c|
|
153
153
|
assert(c.file.exists?("mimetype"))
|
154
154
|
assert_nil(c.replace("mimetype", $zip_empty))
|
155
155
|
assert_equal("application/epub+zip", c.file.read("mimetype"))
|
@@ -159,7 +159,7 @@ class TestReservedNames < Test::Unit::TestCase
|
|
159
159
|
# Check that an exception is raised when trying to add file with a reserved
|
160
160
|
# name.
|
161
161
|
def test_add_reserved
|
162
|
-
ZipContainer::
|
162
|
+
ZipContainer::File.open($empty) do |c|
|
163
163
|
assert_raises(ZipContainer::ReservedNameClashError) do
|
164
164
|
c.add("mimetype", $zip_empty)
|
165
165
|
end
|
@@ -191,7 +191,7 @@ class TestReservedNames < Test::Unit::TestCase
|
|
191
191
|
# Check that the META-INF directory is detected as non-existent when trying
|
192
192
|
# to delete it.
|
193
193
|
def test_delete_metainf
|
194
|
-
ZipContainer::
|
194
|
+
ZipContainer::File.open($example) do |c|
|
195
195
|
assert_raises(Errno::ENOENT) do
|
196
196
|
c.remove("META-INF")
|
197
197
|
end
|
@@ -201,7 +201,7 @@ class TestReservedNames < Test::Unit::TestCase
|
|
201
201
|
# Check that the META-INF directory is detected as non-existent when trying
|
202
202
|
# to rename it.
|
203
203
|
def test_rename_metainf
|
204
|
-
ZipContainer::
|
204
|
+
ZipContainer::File.open($example) do |c|
|
205
205
|
assert_raises(Errno::ENOENT) do
|
206
206
|
c.rename("META-INF", "something-else")
|
207
207
|
end
|
@@ -211,7 +211,7 @@ class TestReservedNames < Test::Unit::TestCase
|
|
211
211
|
# Check that an exception is raised when trying to create a directory with a
|
212
212
|
# reserved name.
|
213
213
|
def test_mkdir_reserved
|
214
|
-
ZipContainer::
|
214
|
+
ZipContainer::File.open($empty) do |c|
|
215
215
|
assert_raises(ZipContainer::ReservedNameClashError) do
|
216
216
|
c.mkdir("mimetype")
|
217
217
|
end
|
@@ -246,7 +246,7 @@ class TestReservedNames < Test::Unit::TestCase
|
|
246
246
|
|
247
247
|
# Check that a file cannot be renamed to one of the reserved names.
|
248
248
|
def test_rename_to_reserved
|
249
|
-
ZipContainer::
|
249
|
+
ZipContainer::File.open($example) do |c|
|
250
250
|
assert_raises(ZipContainer::ReservedNameClashError) do
|
251
251
|
c.rename("dir/code.rb", "mimetype")
|
252
252
|
end
|
@@ -270,7 +270,7 @@ class TestReservedNames < Test::Unit::TestCase
|
|
270
270
|
# Check that the ruby-like File and Dir classes respect reserved and managed
|
271
271
|
# names.
|
272
272
|
def test_file_dir_ops_reserved
|
273
|
-
ZipContainer::
|
273
|
+
ZipContainer::File.open($empty) do |c|
|
274
274
|
assert_raises(ZipContainer::ReservedNameClashError) do
|
275
275
|
c.file.open("mimetype", "w") do |f|
|
276
276
|
f.puts "TESTING"
|
data/test/tc_util.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Copyright (c) 2014 The University of Manchester, UK.
|
2
|
+
#
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# * Neither the names of The University of Manchester nor the names of its
|
16
|
+
# contributors may be used to endorse or promote products derived from this
|
17
|
+
# software without specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
22
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
23
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
24
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
#
|
31
|
+
# Author: Robert Haines
|
32
|
+
|
33
|
+
require 'test/unit'
|
34
|
+
require 'zip-container'
|
35
|
+
|
36
|
+
class Util
|
37
|
+
include ZipContainer::Util
|
38
|
+
end
|
39
|
+
|
40
|
+
class TestUtil < Test::Unit::TestCase
|
41
|
+
|
42
|
+
def setup
|
43
|
+
@util = Util.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_entry_name_strings
|
47
|
+
assert_equal("test", @util.entry_name("test"))
|
48
|
+
assert_equal("test", @util.entry_name("test/"))
|
49
|
+
assert_equal("test/test", @util.entry_name("test/test"))
|
50
|
+
assert_equal("test/test", @util.entry_name("test/test/"))
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_entry_name_entries
|
54
|
+
assert_equal("test", @util.entry_name(Zip::Entry.new("fake.zip", "test")))
|
55
|
+
assert_equal("test", @util.entry_name(Zip::Entry.new("fake.zip", "test/")))
|
56
|
+
assert_equal("test/test",
|
57
|
+
@util.entry_name(Zip::Entry.new("fake.zip", "test/test")))
|
58
|
+
assert_equal("test/test",
|
59
|
+
@util.entry_name(Zip::Entry.new("fake.zip", "test/test/")))
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_entry_name_odd_things
|
63
|
+
uri = URI.parse("http://www.example.com/path")
|
64
|
+
assert_equal(uri, @util.entry_name(uri))
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
data/test/ts_container.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2013 The University of Manchester, UK.
|
1
|
+
# Copyright (c) 2013, 2014 The University of Manchester, UK.
|
2
2
|
#
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
@@ -42,8 +42,11 @@ $empty = "test/data/empty.container"
|
|
42
42
|
$empty_zip = "test/data/empty.zip"
|
43
43
|
$compressed_mimetype = "test/data/compressed_mimetype.container"
|
44
44
|
$example = "test/data/example.container"
|
45
|
+
$subclass = "test/data/subclassed.container"
|
45
46
|
|
46
47
|
# Run test cases.
|
48
|
+
require 'tc_util'
|
49
|
+
require 'tc_exceptions'
|
47
50
|
require 'tc_create'
|
48
51
|
require 'tc_read'
|
49
52
|
require 'tc_reserved_names'
|
data/version.yml
CHANGED
data/zip-container.gemspec
CHANGED
@@ -54,10 +54,11 @@ Gem::Specification.new do |s|
|
|
54
54
|
s.has_rdoc = true
|
55
55
|
s.extra_rdoc_files = [ "Changes.rdoc", "Licence.rdoc", "ReadMe.rdoc" ]
|
56
56
|
s.rdoc_options = [ "-N", "--tab-width=2", "--main=ReadMe.rdoc" ]
|
57
|
+
s.required_ruby_version = ">= 1.9.3"
|
57
58
|
s.add_development_dependency("rake", "~> 10.0.4")
|
58
59
|
s.add_development_dependency("bundler", "~> 1.5")
|
59
60
|
s.add_development_dependency("rdoc", "~> 4.0.1")
|
60
61
|
s.add_development_dependency('coveralls')
|
61
|
-
s.add_runtime_dependency("rubyzip", "~> 1.1.
|
62
|
+
s.add_runtime_dependency("rubyzip", "~> 1.1.6")
|
62
63
|
end
|
63
64
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zip-container
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Haines
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 1.1.
|
75
|
+
version: 1.1.6
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 1.1.
|
82
|
+
version: 1.1.6
|
83
83
|
description: A Ruby library for working with ZIP Container Format files. See http://www.idpf.org/epub/30/spec/epub30-ocf.html
|
84
84
|
for the OCF specification and https://learn.adobe.com/wiki/display/PDFNAV/Universal+Container+Format
|
85
85
|
for the UCF specification.
|
@@ -105,23 +105,28 @@ files:
|
|
105
105
|
- examples/verify-zip-container
|
106
106
|
- examples/zip-container-info
|
107
107
|
- lib/zip-container.rb
|
108
|
-
- lib/zip-container/container.rb
|
109
108
|
- lib/zip-container/entries/directory.rb
|
110
109
|
- lib/zip-container/entries/entry.rb
|
111
110
|
- lib/zip-container/entries/file.rb
|
112
111
|
- lib/zip-container/entries/managed.rb
|
113
112
|
- lib/zip-container/entries/reserved.rb
|
114
113
|
- lib/zip-container/exceptions.rb
|
114
|
+
- lib/zip-container/file.rb
|
115
|
+
- lib/zip-container/util.rb
|
115
116
|
- lib/zip-container/version.rb
|
116
117
|
- test/data/compressed_mimetype.container
|
117
118
|
- test/data/empty.container
|
118
119
|
- test/data/empty.zip
|
119
120
|
- test/data/example.container
|
120
121
|
- test/data/null.file
|
122
|
+
- test/data/subclassed.container
|
123
|
+
- test/helpers/entry_lists.rb
|
121
124
|
- test/tc_create.rb
|
125
|
+
- test/tc_exceptions.rb
|
122
126
|
- test/tc_managed_entries.rb
|
123
127
|
- test/tc_read.rb
|
124
128
|
- test/tc_reserved_names.rb
|
129
|
+
- test/tc_util.rb
|
125
130
|
- test/ts_container.rb
|
126
131
|
- version.yml
|
127
132
|
- zip-container.gemspec
|
@@ -140,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
145
|
requirements:
|
141
146
|
- - ! '>='
|
142
147
|
- !ruby/object:Gem::Version
|
143
|
-
version:
|
148
|
+
version: 1.9.3
|
144
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
150
|
requirements:
|
146
151
|
- - ! '>='
|
@@ -158,8 +163,12 @@ test_files:
|
|
158
163
|
- test/data/empty.zip
|
159
164
|
- test/data/example.container
|
160
165
|
- test/data/null.file
|
166
|
+
- test/data/subclassed.container
|
167
|
+
- test/helpers/entry_lists.rb
|
161
168
|
- test/tc_create.rb
|
169
|
+
- test/tc_exceptions.rb
|
162
170
|
- test/tc_managed_entries.rb
|
163
171
|
- test/tc_read.rb
|
164
172
|
- test/tc_reserved_names.rb
|
173
|
+
- test/tc_util.rb
|
165
174
|
- test/ts_container.rb
|