zip-container 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changes.rdoc +5 -0
- data/examples/{create-zip-container.rb → create-zip-container} +15 -5
- data/examples/{verify-zip-container.rb → verify-zip-container} +11 -4
- data/examples/zip-container-info +2 -2
- data/lib/zip-container/container.rb +3 -3
- data/lib/zip-container/entries/directory.rb +1 -1
- data/lib/zip-container/entries/entry.rb +3 -3
- data/lib/zip-container/entries/file.rb +2 -2
- data/lib/zip-container/exceptions.rb +8 -8
- data/test/tc_create.rb +3 -3
- data/test/tc_managed_entries.rb +11 -11
- data/test/tc_read.rb +4 -4
- data/test/tc_reserved_names.rb +1 -1
- data/version.yml +1 -1
- data/zip-container.gemspec +4 -4
- metadata +4 -4
data/Changes.rdoc
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
1
2
|
# Copyright (c) 2013 The University of Manchester, UK.
|
2
3
|
#
|
3
4
|
# All rights reserved.
|
@@ -33,13 +34,22 @@
|
|
33
34
|
require 'rubygems'
|
34
35
|
require 'zip-container'
|
35
36
|
|
36
|
-
|
37
|
-
|
37
|
+
def usage
|
38
|
+
puts "Usage:\n create-zip-container <zip-container-file>"
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
|
42
|
+
usage unless ARGV.length == 1
|
38
43
|
|
39
|
-
|
44
|
+
container_file = ARGV[0]
|
45
|
+
|
46
|
+
if File.exists?(container_file)
|
47
|
+
puts "File '#{container_file}' already exists. Exiting."
|
48
|
+
exit 1
|
49
|
+
end
|
40
50
|
|
41
51
|
begin
|
42
|
-
ZipContainer::Container.create(
|
52
|
+
ZipContainer::Container.create(container_file, "application/epub+zip") do |c|
|
43
53
|
|
44
54
|
# Add a cheery greeting file from a string.
|
45
55
|
c.file.open("greeting.txt", "w") do |f|
|
@@ -55,7 +65,7 @@ begin
|
|
55
65
|
# Add a explanation of this file.
|
56
66
|
c.comment = "This is an example Container file!"
|
57
67
|
end
|
58
|
-
rescue ZipContainer::
|
68
|
+
rescue ZipContainer::MalformedContainerError, Zip::ZipError => err
|
59
69
|
puts err.to_s
|
60
70
|
exit 1
|
61
71
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
1
2
|
# Copyright (c) 2013 The University of Manchester, UK.
|
2
3
|
#
|
3
4
|
# All rights reserved.
|
@@ -33,12 +34,18 @@
|
|
33
34
|
require 'rubygems'
|
34
35
|
require 'zip-container'
|
35
36
|
|
36
|
-
|
37
|
-
|
37
|
+
def usage
|
38
|
+
puts "Usage:\n verify-zip-container <zip-container-file>"
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
|
42
|
+
usage unless ARGV.length == 1
|
43
|
+
|
44
|
+
container_file = ARGV[0]
|
38
45
|
|
39
46
|
begin
|
40
|
-
ZipContainer::Container.verify!(
|
41
|
-
rescue ZipContainer::
|
47
|
+
ZipContainer::Container.verify!(container_file)
|
48
|
+
rescue ZipContainer::MalformedContainerError, Zip::ZipError => err
|
42
49
|
puts err.to_s
|
43
50
|
exit 1
|
44
51
|
end
|
data/examples/zip-container-info
CHANGED
@@ -35,7 +35,7 @@ require 'rubygems'
|
|
35
35
|
require 'zip-container'
|
36
36
|
|
37
37
|
def usage
|
38
|
-
puts "zip-container-info zip-container-file"
|
38
|
+
puts "Usage:\n zip-container-info <zip-container-file>"
|
39
39
|
exit 1
|
40
40
|
end
|
41
41
|
|
@@ -45,7 +45,7 @@ container_file = ARGV[0]
|
|
45
45
|
|
46
46
|
begin
|
47
47
|
container = ZipContainer::Container.open(container_file)
|
48
|
-
rescue ZipContainer::
|
48
|
+
rescue ZipContainer::MalformedContainerError, Zip::ZipError => err
|
49
49
|
puts err.to_s
|
50
50
|
exit 1
|
51
51
|
end
|
@@ -358,12 +358,12 @@ module ZipContainer
|
|
358
358
|
# Check mimetype file is present and correct.
|
359
359
|
entry = @zipfile.find_entry(MIMETYPE_FILE)
|
360
360
|
|
361
|
-
raise
|
361
|
+
raise MalformedContainerError.new("'mimetype' file is missing.") if entry.nil?
|
362
362
|
if entry.localHeaderOffset != 0
|
363
|
-
raise
|
363
|
+
raise MalformedContainerError.new("'mimetype' file is not at offset 0 in the archive.")
|
364
364
|
end
|
365
365
|
if entry.compression_method != ::Zip::ZipEntry::STORED
|
366
|
-
raise
|
366
|
+
raise MalformedContainerError.new("'mimetype' file is compressed.")
|
367
367
|
end
|
368
368
|
|
369
369
|
true
|
@@ -61,7 +61,7 @@ module ZipContainer
|
|
61
61
|
# Verify this ManagedDirectory for correctness. ManagedFiles registered
|
62
62
|
# within it are verified recursively.
|
63
63
|
#
|
64
|
-
# A
|
64
|
+
# A MalformedContainerError is raised if it does not pass verification.
|
65
65
|
def verify!
|
66
66
|
super
|
67
67
|
@files.values.each { |f| f.verify! }
|
@@ -111,15 +111,15 @@ module ZipContainer
|
|
111
111
|
# :call-seq:
|
112
112
|
# verify!
|
113
113
|
#
|
114
|
-
# Verify this ManagedEntry raising a
|
114
|
+
# Verify this ManagedEntry raising a MalformedContainerError if it
|
115
115
|
# fails.
|
116
116
|
#
|
117
117
|
# Subclasses should override this method if they require more complex
|
118
118
|
# verification to be done.
|
119
119
|
def verify!
|
120
120
|
unless !@required || exists?
|
121
|
-
raise
|
122
|
-
"missing.")
|
121
|
+
raise MalformedContainerError.new("Entry '#{full_name}' is required "\
|
122
|
+
"but missing.")
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
@@ -67,11 +67,11 @@ module ZipContainer
|
|
67
67
|
# Verify this ManagedFile for correctness. The contents are validated if
|
68
68
|
# required.
|
69
69
|
#
|
70
|
-
# A
|
70
|
+
# A MalformedContainerError is raised if it does not pass verification.
|
71
71
|
def verify!
|
72
72
|
super
|
73
73
|
unless (exists? ? validate : true)
|
74
|
-
raise
|
74
|
+
raise MalformedContainerError.new("The contents of file "\
|
75
75
|
"'#{full_name}' do not pass validation.")
|
76
76
|
end
|
77
77
|
end
|
@@ -34,29 +34,29 @@
|
|
34
34
|
module ZipContainer
|
35
35
|
|
36
36
|
# The base class of all other exceptions raised by this library.
|
37
|
-
class
|
37
|
+
class ContainerError < RuntimeError
|
38
38
|
end
|
39
39
|
|
40
|
-
# This exception is raised when a bad
|
41
|
-
class
|
40
|
+
# This exception is raised when a bad Container is detected.
|
41
|
+
class MalformedContainerError < ContainerError
|
42
42
|
|
43
43
|
# :call-seq:
|
44
44
|
# new(reason = "")
|
45
45
|
#
|
46
|
-
# Create a new
|
47
|
-
# the
|
46
|
+
# Create a new MalformedContainerError with an optional reason for why
|
47
|
+
# the Container file is malformed.
|
48
48
|
def initialize(reason = nil)
|
49
49
|
if reason.nil?
|
50
|
-
super("Malformed
|
50
|
+
super("Malformed Container File.")
|
51
51
|
else
|
52
|
-
super("Malformed
|
52
|
+
super("Malformed Container File: #{reason}")
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
# This exception is raised when a clash occurs with a reserved or managed
|
58
58
|
# name.
|
59
|
-
class ReservedNameClashError <
|
59
|
+
class ReservedNameClashError < ContainerError
|
60
60
|
|
61
61
|
# :call-seq:
|
62
62
|
# new(name)
|
data/test/tc_create.rb
CHANGED
@@ -50,7 +50,7 @@ class TestCreation < Test::Unit::TestCase
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
assert_nothing_raised(ZipContainer::
|
53
|
+
assert_nothing_raised(ZipContainer::MalformedContainerError, Zip::ZipError) do
|
54
54
|
ZipContainer::Container.verify!(filename)
|
55
55
|
end
|
56
56
|
end
|
@@ -72,7 +72,7 @@ class TestCreation < Test::Unit::TestCase
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
assert_nothing_raised(ZipContainer::
|
75
|
+
assert_nothing_raised(ZipContainer::MalformedContainerError, Zip::ZipError) do
|
76
76
|
ZipContainer::Container.verify!(filename)
|
77
77
|
end
|
78
78
|
end
|
@@ -115,7 +115,7 @@ class TestCreation < Test::Unit::TestCase
|
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
|
-
assert_nothing_raised(ZipContainer::
|
118
|
+
assert_nothing_raised(ZipContainer::MalformedContainerError, Zip::ZipError) do
|
119
119
|
ZipContainer::Container.open(filename) do |c|
|
120
120
|
assert(c.on_disk?)
|
121
121
|
refute(c.in_memory?)
|
data/test/tc_managed_entries.rb
CHANGED
@@ -86,7 +86,7 @@ class TestManagedEntries < Test::Unit::TestCase
|
|
86
86
|
def test_fail_verification
|
87
87
|
refute(ManagedZipContainer.verify($example))
|
88
88
|
|
89
|
-
assert_raises(ZipContainer::
|
89
|
+
assert_raises(ZipContainer::MalformedContainerError) do
|
90
90
|
ManagedZipContainer.verify!($example)
|
91
91
|
end
|
92
92
|
end
|
@@ -96,7 +96,7 @@ class TestManagedEntries < Test::Unit::TestCase
|
|
96
96
|
def test_pass_verification
|
97
97
|
assert(ExampleZipContainer.verify($example))
|
98
98
|
|
99
|
-
assert_nothing_raised(ZipContainer::
|
99
|
+
assert_nothing_raised(ZipContainer::MalformedContainerError) do
|
100
100
|
ExampleZipContainer.verify!($example)
|
101
101
|
end
|
102
102
|
end
|
@@ -106,7 +106,7 @@ class TestManagedEntries < Test::Unit::TestCase
|
|
106
106
|
def test_pass_verification_2
|
107
107
|
assert(ExampleZipContainer2.verify($example))
|
108
108
|
|
109
|
-
assert_nothing_raised(ZipContainer::
|
109
|
+
assert_nothing_raised(ZipContainer::MalformedContainerError) do
|
110
110
|
ExampleZipContainer2.verify!($example)
|
111
111
|
end
|
112
112
|
end
|
@@ -128,7 +128,7 @@ class TestManagedEntries < Test::Unit::TestCase
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
-
assert_nothing_raised(ZipContainer::
|
131
|
+
assert_nothing_raised(ZipContainer::MalformedContainerError) do
|
132
132
|
ZipContainer::Container.verify!(filename)
|
133
133
|
end
|
134
134
|
end
|
@@ -142,14 +142,14 @@ class TestManagedEntries < Test::Unit::TestCase
|
|
142
142
|
|
143
143
|
assert_nothing_raised do
|
144
144
|
ManagedZipContainer.create(filename, $mimetype) do |c|
|
145
|
-
assert_raises(ZipContainer::
|
145
|
+
assert_raises(ZipContainer::MalformedContainerError) do
|
146
146
|
c.verify!
|
147
147
|
end
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
151
|
refute(ManagedZipContainer.verify(filename))
|
152
|
-
assert_raises(ZipContainer::
|
152
|
+
assert_raises(ZipContainer::MalformedContainerError) do
|
153
153
|
ManagedZipContainer.verify!(filename)
|
154
154
|
end
|
155
155
|
end
|
@@ -171,7 +171,7 @@ class TestManagedEntries < Test::Unit::TestCase
|
|
171
171
|
end
|
172
172
|
|
173
173
|
assert(ManagedZipContainer.verify(filename))
|
174
|
-
assert_nothing_raised(ZipContainer::
|
174
|
+
assert_nothing_raised(ZipContainer::MalformedContainerError) do
|
175
175
|
ManagedZipContainer.verify!(filename)
|
176
176
|
end
|
177
177
|
end
|
@@ -198,7 +198,7 @@ class TestManagedEntries < Test::Unit::TestCase
|
|
198
198
|
|
199
199
|
assert_nothing_raised do
|
200
200
|
ExampleZipContainer2.create(filename) do |c|
|
201
|
-
assert_raises(ZipContainer::
|
201
|
+
assert_raises(ZipContainer::MalformedContainerError) do
|
202
202
|
c.verify!
|
203
203
|
end
|
204
204
|
|
@@ -206,7 +206,7 @@ class TestManagedEntries < Test::Unit::TestCase
|
|
206
206
|
f.puts "Goodbye!"
|
207
207
|
end
|
208
208
|
|
209
|
-
assert_raises(ZipContainer::
|
209
|
+
assert_raises(ZipContainer::MalformedContainerError) do
|
210
210
|
c.verify!
|
211
211
|
end
|
212
212
|
|
@@ -214,14 +214,14 @@ class TestManagedEntries < Test::Unit::TestCase
|
|
214
214
|
f.puts "Hello, Y'All!"
|
215
215
|
end
|
216
216
|
|
217
|
-
assert_nothing_raised(ZipContainer::
|
217
|
+
assert_nothing_raised(ZipContainer::MalformedContainerError) do
|
218
218
|
c.verify!
|
219
219
|
end
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
223
223
|
assert(ExampleZipContainer2.verify(filename))
|
224
|
-
assert_nothing_raised(ZipContainer::
|
224
|
+
assert_nothing_raised(ZipContainer::MalformedContainerError) do
|
225
225
|
ExampleZipContainer2.verify!(filename)
|
226
226
|
end
|
227
227
|
end
|
data/test/tc_read.rb
CHANGED
@@ -46,7 +46,7 @@ class TestRead < Test::Unit::TestCase
|
|
46
46
|
|
47
47
|
# Check that the empty container file does verify.
|
48
48
|
def test_verify_empty_container
|
49
|
-
assert_nothing_raised(ZipContainer::
|
49
|
+
assert_nothing_raised(ZipContainer::MalformedContainerError, Zip::ZipError) do
|
50
50
|
ZipContainer::Container.verify!($empty)
|
51
51
|
end
|
52
52
|
|
@@ -55,7 +55,7 @@ class TestRead < Test::Unit::TestCase
|
|
55
55
|
|
56
56
|
# Check that the empty zip file does not verify.
|
57
57
|
def test_verify_empty_zip
|
58
|
-
assert_raise(ZipContainer::
|
58
|
+
assert_raise(ZipContainer::MalformedContainerError) do
|
59
59
|
ZipContainer::Container.verify!($empty_zip)
|
60
60
|
end
|
61
61
|
|
@@ -64,7 +64,7 @@ class TestRead < Test::Unit::TestCase
|
|
64
64
|
|
65
65
|
# Check that a compressed mimetype file is detected.
|
66
66
|
def test_verify_compressed_mimetype
|
67
|
-
assert_raise(ZipContainer::
|
67
|
+
assert_raise(ZipContainer::MalformedContainerError) do
|
68
68
|
ZipContainer::Container.verify!($compressed_mimetype)
|
69
69
|
end
|
70
70
|
|
@@ -83,7 +83,7 @@ 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::
|
86
|
+
assert_nothing_raised(ZipContainer::MalformedContainerError, Zip::ZipError) do
|
87
87
|
ZipContainer::Container.open($example) do |c|
|
88
88
|
assert(c.on_disk?)
|
89
89
|
refute(c.in_memory?)
|
data/test/tc_reserved_names.rb
CHANGED
@@ -58,7 +58,7 @@ class TestReservedNames < Test::Unit::TestCase
|
|
58
58
|
def test_verify_reserved_name
|
59
59
|
assert(NewZipContainer.verify($example))
|
60
60
|
|
61
|
-
assert_nothing_raised(ZipContainer::
|
61
|
+
assert_nothing_raised(ZipContainer::MalformedContainerError) do
|
62
62
|
NewZipContainer.verify!($example)
|
63
63
|
end
|
64
64
|
end
|
data/version.yml
CHANGED
data/zip-container.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "zip-container"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.9.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Robert Haines"]
|
12
|
-
s.date = "2013-06-
|
12
|
+
s.date = "2013-06-27"
|
13
13
|
s.description = "A Ruby library for working with ZIP Container Format files. See http://www.idpf.org/epub/30/spec/epub30-ocf.html for the OCF specification and https://learn.adobe.com/wiki/display/PDFNAV/Universal+Container+Format for the UCF specification."
|
14
14
|
s.email = ["support@mygrid.org.uk"]
|
15
15
|
s.extra_rdoc_files = [
|
@@ -22,8 +22,8 @@ Gem::Specification.new do |s|
|
|
22
22
|
"Licence.rdoc",
|
23
23
|
"Rakefile",
|
24
24
|
"ReadMe.rdoc",
|
25
|
-
"examples/create-zip-container
|
26
|
-
"examples/verify-zip-container
|
25
|
+
"examples/create-zip-container",
|
26
|
+
"examples/verify-zip-container",
|
27
27
|
"examples/zip-container-info",
|
28
28
|
"lib/zip-container.rb",
|
29
29
|
"lib/zip-container/container.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zip-container
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -91,8 +91,8 @@ files:
|
|
91
91
|
- Licence.rdoc
|
92
92
|
- Rakefile
|
93
93
|
- ReadMe.rdoc
|
94
|
-
- examples/create-zip-container
|
95
|
-
- examples/verify-zip-container
|
94
|
+
- examples/create-zip-container
|
95
|
+
- examples/verify-zip-container
|
96
96
|
- examples/zip-container-info
|
97
97
|
- lib/zip-container.rb
|
98
98
|
- lib/zip-container/container.rb
|