zip-container 2.1.0 → 2.2.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.
- checksums.yaml +8 -8
- data/Changes.rdoc +8 -0
- data/lib/zip-container/dir.rb +52 -13
- data/lib/zip-container/entries/entry.rb +3 -3
- data/lib/zip-container/file.rb +2 -2
- data/test/data/dirs/managed/dir/.gitkeep +0 -0
- data/test/data/dirs/managed/greeting.txt +1 -0
- data/test/data/dirs/managed/mimetype +1 -0
- data/test/tc_create_dir.rb +9 -12
- data/test/tc_managed_entries.rb +54 -0
- data/test/tc_read_dir.rb +21 -0
- data/test/ts_container.rb +1 -0
- data/version.yml +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NmZhNWQzYmVkZGVjNDczNTNjN2M3M2Q2ZmJjYmI5YTEzMDYwZTE0Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Mzg5YjU5ZjYyYjMzOGUyZWU1ZTk5NjI4YWRmNTQwNTk1NTU1OGJmZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
N2NjNjI1ZmJhNTQ5NzdiMGU3MjgxZTEwNjM5Zjk5NDgyMGYxYzRjZmYwMmNm
|
10
|
+
ODg2M2ZmZTllNjU2YjNmMWU2ZGQzOTlhYTE3ODAzNzI3NjY2YmRiY2JiYjg2
|
11
|
+
MjZkN2E5NTljMmIzYjIyNTcyZTE4ZDg3OGY4M2Q1NzkxOGJhZjc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzNhYjc1YmQ5MTg5YWU1ZDNlN2U0MDlkMDYxNDgxNDYxOTA2YWM5MzI2Njgz
|
14
|
+
MmRjOTkyNWM1NWMzZmE5ZDA1ZTBiNGJhMzRhNWZkMGU5MWEwMDBjNjcxNzUx
|
15
|
+
NDU2ZGMwNGEyNjBkYjFkM2Q3MzMwMzAzMzcyYjMyZTEwZjcyNjA=
|
data/Changes.rdoc
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
= Changes log for the ZIP Container Ruby Gem
|
2
2
|
|
3
|
+
== Version 2.2.0
|
4
|
+
|
5
|
+
* Fix pathname bug in ZipContainer::Dir.
|
6
|
+
* Fixup docs to refer to containers rather than documents.
|
7
|
+
* Fix the base class in the recursive methods.
|
8
|
+
* Add an internal compatibility method Dir#entries.
|
9
|
+
* Add a compatibility method Dir#read.
|
10
|
+
|
3
11
|
== Version 2.1.0
|
4
12
|
|
5
13
|
* Set up the Container superclass.
|
data/lib/zip-container/dir.rb
CHANGED
@@ -48,8 +48,8 @@ module ZipContainer
|
|
48
48
|
class Dir < Container
|
49
49
|
|
50
50
|
extend Forwardable
|
51
|
-
def_delegators :@container, :close, :each, :path, :pos, :pos=, :
|
52
|
-
:
|
51
|
+
def_delegators :@container, :close, :each, :path, :pos, :pos=, :rewind,
|
52
|
+
:seek, :tell
|
53
53
|
|
54
54
|
private_class_method :new
|
55
55
|
|
@@ -60,14 +60,14 @@ module ZipContainer
|
|
60
60
|
# :startdoc:
|
61
61
|
|
62
62
|
# :call-seq:
|
63
|
-
# create(pathname, mimetype) ->
|
64
|
-
# create(pathname, mimetype) {|
|
63
|
+
# create(pathname, mimetype) -> container
|
64
|
+
# create(pathname, mimetype) {|container| ...}
|
65
65
|
#
|
66
66
|
# Create a new (or convert an existing) directory as a ZipContainer with
|
67
67
|
# the specified mimetype.
|
68
68
|
def self.create(pathname, mimetype, &block)
|
69
69
|
::Dir.mkdir(pathname) unless ::File.directory?(pathname)
|
70
|
-
::File.write(
|
70
|
+
::File.write(::File.join(pathname, MIMETYPE_FILE), mimetype)
|
71
71
|
|
72
72
|
# Now open the newly created container.
|
73
73
|
c = new(pathname)
|
@@ -83,6 +83,53 @@ module ZipContainer
|
|
83
83
|
c
|
84
84
|
end
|
85
85
|
|
86
|
+
# :call-seq:
|
87
|
+
# read
|
88
|
+
# read(path) -> file contents
|
89
|
+
#
|
90
|
+
# Provides compatibility between directory and zip containers. If called
|
91
|
+
# without any parameters it acts like
|
92
|
+
# {::Dir.read}[http://ruby-doc.org/core-1.9.3/Dir.html#method-i-read] but
|
93
|
+
# if called with a path then it acts like
|
94
|
+
# {Zip::File#read}[http://www.rubydoc.info/gems/rubyzip/1.1.6/Zip/File#read-instance_method].
|
95
|
+
#
|
96
|
+
# Please see the documentation of the relevant method for more details.
|
97
|
+
def read(name = nil)
|
98
|
+
return @container.read if name.nil?
|
99
|
+
|
100
|
+
::File.read(full_path(name))
|
101
|
+
end
|
102
|
+
|
103
|
+
# :stopdoc:
|
104
|
+
# For internal use only!
|
105
|
+
# This method and the Entry and Entries classes provide compatibility
|
106
|
+
# between zip-style and dir-style entries
|
107
|
+
def entries
|
108
|
+
Entries.new(@container)
|
109
|
+
end
|
110
|
+
|
111
|
+
class Entries
|
112
|
+
include Enumerable
|
113
|
+
|
114
|
+
Entry = Struct.new(:name, :ftype)
|
115
|
+
|
116
|
+
def initialize(dir)
|
117
|
+
@entries = []
|
118
|
+
|
119
|
+
dir.each do |name|
|
120
|
+
type = ::File.directory?(name) ? :directory : :file
|
121
|
+
@entries << Entry.new(name, type)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def each(&block)
|
126
|
+
@entries.each do |entry|
|
127
|
+
yield entry
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
# :startdoc:
|
132
|
+
|
86
133
|
private
|
87
134
|
|
88
135
|
# Prepend the full path of the directory name to whatever is passed in
|
@@ -155,14 +202,6 @@ module ZipContainer
|
|
155
202
|
# Equal to
|
156
203
|
# {::Dir.pos=}[http://ruby-doc.org/core-1.9.3/Dir.html#method-i-pos-3D]
|
157
204
|
|
158
|
-
##
|
159
|
-
# :method: read
|
160
|
-
# :call-seq:
|
161
|
-
# read -> string or nil
|
162
|
-
#
|
163
|
-
# Equal to
|
164
|
-
# {::Dir.read}[http://ruby-doc.org/core-1.9.3/Dir.html#method-i-read]
|
165
|
-
|
166
205
|
##
|
167
206
|
# :method: rewind
|
168
207
|
# :call-seq:
|
@@ -60,7 +60,7 @@ module ZipContainer
|
|
60
60
|
#
|
61
61
|
# The fully qualified name of this ManagedEntry.
|
62
62
|
def full_name
|
63
|
-
@parent.is_a?(ZipContainer::
|
63
|
+
@parent.is_a?(ZipContainer::Container) ? @name : "#{@parent.full_name}/#{@name}"
|
64
64
|
end
|
65
65
|
|
66
66
|
# :call-seq:
|
@@ -78,7 +78,7 @@ module ZipContainer
|
|
78
78
|
# Is this ManagedEntry hidden for normal operations?
|
79
79
|
def hidden?
|
80
80
|
# An entry is hidden if its parent is hidden.
|
81
|
-
@parent.is_a?(ZipContainer::
|
81
|
+
@parent.is_a?(ZipContainer::Container) ? @hidden : @hidden || @parent.hidden?
|
82
82
|
end
|
83
83
|
|
84
84
|
# :call-seq:
|
@@ -140,7 +140,7 @@ module ZipContainer
|
|
140
140
|
#
|
141
141
|
# Return the Container that this ManagedEntry resides in.
|
142
142
|
def container
|
143
|
-
@parent.is_a?(ZipContainer::
|
143
|
+
@parent.is_a?(ZipContainer::Container) ? @parent : @parent.container
|
144
144
|
end
|
145
145
|
|
146
146
|
end
|
data/lib/zip-container/file.rb
CHANGED
@@ -70,8 +70,8 @@ module ZipContainer
|
|
70
70
|
# :startdoc:
|
71
71
|
|
72
72
|
# :call-seq:
|
73
|
-
# File.create(filename, mimetype) ->
|
74
|
-
# File.create(filename, mimetype) {|
|
73
|
+
# File.create(filename, mimetype) -> container
|
74
|
+
# File.create(filename, mimetype) {|container| ...}
|
75
75
|
#
|
76
76
|
# Create a new ZipContainer file on disk with the specified mimetype.
|
77
77
|
def self.create(filename, mimetype, &block)
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello, World!
|
@@ -0,0 +1 @@
|
|
1
|
+
application/epub+zip
|
data/test/tc_create_dir.rb
CHANGED
@@ -36,23 +36,20 @@ require 'zip-container'
|
|
36
36
|
|
37
37
|
class TestCreateDir < Test::Unit::TestCase
|
38
38
|
|
39
|
-
|
40
|
-
# build this fixture programmatically as there's no way to add a file
|
41
|
-
# without read permissions into git.
|
42
|
-
def test_verify_unreadable_mimetype
|
39
|
+
def test_create_container
|
43
40
|
Dir.mktmpdir do |dir|
|
44
|
-
container = File.join(dir, "
|
45
|
-
Dir.mkdir(container)
|
46
|
-
mime_path = File.join(container, ZipContainer::Container::MIMETYPE_FILE)
|
47
|
-
File.open(mime_path, "w") { |file| file.write "MIMETYPE" }
|
48
|
-
File.chmod(0000, mime_path)
|
41
|
+
container = File.join(dir, "empty.container")
|
49
42
|
|
50
|
-
|
51
|
-
|
43
|
+
assert_nothing_raised do
|
44
|
+
ZipContainer::Dir.create(container, $mimetype) do |c|
|
45
|
+
assert File.exists?(File.join(container, "mimetype"))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_nothing_raised(ZipContainer::MalformedContainerError, ZipContainer::ZipError) do
|
52
50
|
ZipContainer::Dir.verify!(container)
|
53
51
|
end
|
54
52
|
|
55
|
-
refute(ZipContainer::Dir.verify(container))
|
56
53
|
end
|
57
54
|
end
|
58
55
|
|
data/test/tc_managed_entries.rb
CHANGED
@@ -85,6 +85,28 @@ class ExampleZipContainer2 < ZipContainer::File
|
|
85
85
|
|
86
86
|
end
|
87
87
|
|
88
|
+
class ExampleDirContainer < ZipContainer::Dir
|
89
|
+
|
90
|
+
private_class_method :new
|
91
|
+
|
92
|
+
def initialize(filename)
|
93
|
+
super(filename)
|
94
|
+
|
95
|
+
valid = Proc.new { |contents| contents.match(/[Hh]ello/) }
|
96
|
+
|
97
|
+
test_file = ZipContainer::ManagedFile.new("test.txt")
|
98
|
+
register_managed_entry(ZipContainer::ManagedDirectory.new("dir",
|
99
|
+
:required => true, :entries => [test_file]))
|
100
|
+
register_managed_entry(ZipContainer::ManagedFile.new("greeting.txt",
|
101
|
+
:required => true, :validation_proc => valid))
|
102
|
+
end
|
103
|
+
|
104
|
+
#def ExampleDirContainer.create(filename, &block)
|
105
|
+
# super(filename, "application/example+zip", &block)
|
106
|
+
#end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
88
110
|
class TestManagedEntries < Test::Unit::TestCase
|
89
111
|
|
90
112
|
# Check that the example ZipContainer file does not validate as a
|
@@ -140,6 +162,38 @@ class TestManagedEntries < Test::Unit::TestCase
|
|
140
162
|
end
|
141
163
|
end
|
142
164
|
|
165
|
+
# Check that a subclassed container with managed files verifies correctly.
|
166
|
+
def test_verify_subclassed_dir_container
|
167
|
+
assert_nothing_raised do
|
168
|
+
ExampleDirContainer.verify!($dir_managed)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# Create a subclassed container. Check it doesn't verify at first; satisfy
|
173
|
+
# the conditions; then assert that it verifies correctly.
|
174
|
+
def test_create_subclassed_dir_container
|
175
|
+
Dir.mktmpdir do |dir|
|
176
|
+
filename = File.join(dir, "test.container")
|
177
|
+
|
178
|
+
assert_nothing_raised do
|
179
|
+
ExampleDirContainer.create(filename, $mimetype) do |c|
|
180
|
+
assert_raises(ZipContainer::MalformedContainerError) do
|
181
|
+
c.verify!
|
182
|
+
end
|
183
|
+
|
184
|
+
Dir.mkdir(File.join(filename, "dir"))
|
185
|
+
File.open(File.join(filename, "greeting.txt"), "w") do |f|
|
186
|
+
f.puts "Yo means hello."
|
187
|
+
end
|
188
|
+
|
189
|
+
assert_nothing_raised(ZipContainer::MalformedContainerError) do
|
190
|
+
c.verify!
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
143
197
|
# Check that a ManagedZipContainer does not verify immediately after
|
144
198
|
# creation.
|
145
199
|
def test_create_bad_subclassed_container
|
data/test/tc_read_dir.rb
CHANGED
@@ -31,6 +31,7 @@
|
|
31
31
|
# Author: Robert Haines
|
32
32
|
|
33
33
|
require 'test/unit'
|
34
|
+
require 'tmpdir'
|
34
35
|
require 'zip-container'
|
35
36
|
|
36
37
|
class TestReadDir < Test::Unit::TestCase
|
@@ -62,4 +63,24 @@ class TestReadDir < Test::Unit::TestCase
|
|
62
63
|
refute(ZipContainer::Dir.verify($dir_dir_mimetype))
|
63
64
|
end
|
64
65
|
|
66
|
+
# Check that a mimetype which is not readable does not verify. We have to
|
67
|
+
# build this fixture programmatically as there's no way to add a file
|
68
|
+
# without read permissions into git.
|
69
|
+
def test_verify_unreadable_mimetype
|
70
|
+
Dir.mktmpdir do |dir|
|
71
|
+
container = File.join(dir, "unreadable.container")
|
72
|
+
Dir.mkdir(container)
|
73
|
+
mime_path = File.join(container, ZipContainer::Container::MIMETYPE_FILE)
|
74
|
+
File.open(mime_path, "w") { |file| file.write "MIMETYPE" }
|
75
|
+
File.chmod(0000, mime_path)
|
76
|
+
|
77
|
+
refute File.readable?(mime_path)
|
78
|
+
assert_raise(ZipContainer::MalformedContainerError) do
|
79
|
+
ZipContainer::Dir.verify!(container)
|
80
|
+
end
|
81
|
+
|
82
|
+
refute(ZipContainer::Dir.verify(container))
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
65
86
|
end
|
data/test/ts_container.rb
CHANGED
@@ -40,6 +40,7 @@ $mimetype = "application/epub+zip"
|
|
40
40
|
$dir_null = "test/data/dirs/null"
|
41
41
|
$dir_empty = "test/data/dirs/empty"
|
42
42
|
$dir_dir_mimetype = "test/data/dirs/dir-mimetype"
|
43
|
+
$dir_managed = "test/data/dirs/managed"
|
43
44
|
$file_null = "test/data/null.file"
|
44
45
|
$empty = "test/data/empty.container"
|
45
46
|
$empty_zip = "test/data/empty.zip"
|
data/version.yml
CHANGED
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: 2.
|
4
|
+
version: 2.2.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-12-
|
11
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -134,6 +134,9 @@ files:
|
|
134
134
|
- test/data/compressed_mimetype.container
|
135
135
|
- test/data/dirs/dir-mimetype/mimetype/.gitkeep
|
136
136
|
- test/data/dirs/empty/mimetype
|
137
|
+
- test/data/dirs/managed/dir/.gitkeep
|
138
|
+
- test/data/dirs/managed/greeting.txt
|
139
|
+
- test/data/dirs/managed/mimetype
|
137
140
|
- test/data/dirs/null/.gitkeep
|
138
141
|
- test/data/empty.container
|
139
142
|
- test/data/empty.zip
|
@@ -183,6 +186,9 @@ test_files:
|
|
183
186
|
- test/data/compressed_mimetype.container
|
184
187
|
- test/data/dirs/dir-mimetype/mimetype/.gitkeep
|
185
188
|
- test/data/dirs/empty/mimetype
|
189
|
+
- test/data/dirs/managed/dir/.gitkeep
|
190
|
+
- test/data/dirs/managed/greeting.txt
|
191
|
+
- test/data/dirs/managed/mimetype
|
186
192
|
- test/data/dirs/null/.gitkeep
|
187
193
|
- test/data/empty.container
|
188
194
|
- test/data/empty.zip
|