zip-container 0.9.0 → 1.0.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/Changes.rdoc +4 -0
- data/Rakefile +1 -1
- data/ReadMe.rdoc +16 -8
- data/lib/zip-container/container.rb +17 -18
- data/lib/zip-container/entries/managed.rb +2 -3
- data/lib/zip-container/entries/reserved.rb +3 -4
- data/lib/zip-container.rb +2 -0
- data/test/tc_create.rb +2 -2
- data/version.yml +2 -2
- data/zip-container.gemspec +5 -5
- metadata +4 -4
data/Changes.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -65,7 +65,7 @@ Jeweler::Tasks.new do |s|
|
|
65
65
|
s.add_development_dependency('rake', '~> 10.0.4')
|
66
66
|
s.add_development_dependency('rdoc', '~> 4.0.1')
|
67
67
|
s.add_development_dependency('jeweler', '~> 1.8.4')
|
68
|
-
s.add_runtime_dependency('rubyzip', '~> 0.
|
68
|
+
s.add_runtime_dependency('rubyzip', '~> 1.0.0')
|
69
69
|
end
|
70
70
|
|
71
71
|
Rake::TestTask.new do |t|
|
data/ReadMe.rdoc
CHANGED
@@ -7,6 +7,7 @@ Source code:: https://github.com/myGrid/ruby-zip-container
|
|
7
7
|
Licence:: BSD (See Licence file or http://www.opensource.org/licenses/bsd-license.php)
|
8
8
|
Copyright:: (c) 2013 The University of Manchester, UK
|
9
9
|
|
10
|
+
{<img src="https://badge.fury.io/rb/zip-container.png" alt="Gem Version" />}[http://badge.fury.io/rb/zip-container]
|
10
11
|
{<img src="https://codeclimate.com/github/myGrid/ruby-zip-container.png" />}[https://codeclimate.com/github/myGrid/ruby-zip-container]
|
11
12
|
|
12
13
|
== Synopsis
|
@@ -16,11 +17,20 @@ This is a Ruby library for working with ZIP Container files. See the
|
|
16
17
|
{UDF}[https://learn.adobe.com/wiki/display/PDFNAV/Universal+Container+Format]
|
17
18
|
specifications for more details.
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
== Backwards incompatibility warning!
|
21
|
+
|
22
|
+
Version 1.0.0 and up of this gem uses version 1.0.0 and up of the
|
23
|
+
{rubyzip}[https://rubygems.org/gems/rubyzip] library. This has a backwards
|
24
|
+
incompatible API that may clash with other gems that you are using. Please see
|
25
|
+
the {important note}[https://github.com/rubyzip/rubyzip/blob/master/README.md#important-note]
|
26
|
+
in the rubyzip readme for a workaround.
|
27
|
+
|
28
|
+
== Usage
|
29
|
+
|
30
|
+
This library largely mimics the rubyzip Zip::File API so much of what you can
|
31
|
+
do with that is supported for ZIP Containers. There is also
|
32
|
+
{API documentation}[http://mygrid.github.io/ruby-zip-container/] with much more
|
33
|
+
detail and any differences explained.
|
24
34
|
|
25
35
|
There are some examples of how to use the library provided in the examples
|
26
36
|
directory. See the contents of the tests directory for even more.
|
@@ -29,6 +39,4 @@ directory. See the contents of the tests directory for even more.
|
|
29
39
|
|
30
40
|
The basic requirements of a ZIP Container are all implemented but memory
|
31
41
|
resident ZIP Container files are not yet supported. Presently all operations
|
32
|
-
are performed on files that are resident on disk
|
33
|
-
{rubyzip library}[https://github.com/aussiegeek/rubyzip] currently
|
34
|
-
{cannot do anything else}[https://github.com/aussiegeek/rubyzip/issues/74].
|
42
|
+
are performed on files that are resident on disk.
|
@@ -31,7 +31,6 @@
|
|
31
31
|
# Author: Robert Haines
|
32
32
|
|
33
33
|
require 'forwardable'
|
34
|
-
require 'zip/zipfilesystem'
|
35
34
|
|
36
35
|
module ZipContainer
|
37
36
|
|
@@ -40,9 +39,9 @@ module ZipContainer
|
|
40
39
|
# {UCF}[https://learn.adobe.com/wiki/display/PDFNAV/Universal+Container+Format]
|
41
40
|
# specifications for more details.
|
42
41
|
#
|
43
|
-
# This class provides most of the facilities of the <tt>Zip::
|
42
|
+
# This class provides most of the facilities of the <tt>Zip::File</tt>
|
44
43
|
# class in the rubyzip gem. Please also consult the
|
45
|
-
# {rubyzip documentation}[http://rubydoc.info/gems/rubyzip/
|
44
|
+
# {rubyzip documentation}[http://rubydoc.info/gems/rubyzip/1.1.0/frames]
|
46
45
|
# alongside these pages.
|
47
46
|
#
|
48
47
|
# There are code examples available with the source code of this library.
|
@@ -79,9 +78,9 @@ module ZipContainer
|
|
79
78
|
|
80
79
|
# Here we fake up the connection to the rubyzip filesystem classes so
|
81
80
|
# that they also respect the reserved names that we define.
|
82
|
-
mapped_zip = ::Zip::
|
83
|
-
@fs_dir = ::Zip::
|
84
|
-
@fs_file = ::Zip::
|
81
|
+
mapped_zip = ::Zip::FileSystem::ZipFileNameMapper.new(self)
|
82
|
+
@fs_dir = ::Zip::FileSystem::ZipFsDir.new(mapped_zip)
|
83
|
+
@fs_file = ::Zip::FileSystem::ZipFsFile.new(mapped_zip)
|
85
84
|
@fs_dir.file = @fs_file
|
86
85
|
@fs_file.dir = @fs_dir
|
87
86
|
end
|
@@ -93,8 +92,8 @@ module ZipContainer
|
|
93
92
|
#
|
94
93
|
# Create a new ZipContainer file on disk with the specified mimetype.
|
95
94
|
def Container.create(filename, mimetype, &block)
|
96
|
-
::Zip::
|
97
|
-
stream.put_next_entry(MIMETYPE_FILE, nil, nil, ::Zip::
|
95
|
+
::Zip::OutputStream.open(filename) do |stream|
|
96
|
+
stream.put_next_entry(MIMETYPE_FILE, nil, nil, ::Zip::Entry::STORED)
|
98
97
|
stream.write mimetype
|
99
98
|
end
|
100
99
|
|
@@ -117,7 +116,7 @@ module ZipContainer
|
|
117
116
|
# Container.each_entry {|entry| ...}
|
118
117
|
#
|
119
118
|
# Iterate over the entries in the ZipContainer file. The entry objects
|
120
|
-
# returned by this method are Zip::
|
119
|
+
# returned by this method are Zip::Entry objects. Please see the
|
121
120
|
# rubyzip documentation for details.
|
122
121
|
def Container.each_entry(filename, &block)
|
123
122
|
c = new(filename)
|
@@ -351,7 +350,7 @@ module ZipContainer
|
|
351
350
|
private
|
352
351
|
|
353
352
|
def open_document(document)
|
354
|
-
::Zip::
|
353
|
+
::Zip::File.new(document)
|
355
354
|
end
|
356
355
|
|
357
356
|
def check_mimetype!
|
@@ -359,10 +358,10 @@ module ZipContainer
|
|
359
358
|
entry = @zipfile.find_entry(MIMETYPE_FILE)
|
360
359
|
|
361
360
|
raise MalformedContainerError.new("'mimetype' file is missing.") if entry.nil?
|
362
|
-
if entry.
|
361
|
+
if entry.local_header_offset != 0
|
363
362
|
raise MalformedContainerError.new("'mimetype' file is not at offset 0 in the archive.")
|
364
363
|
end
|
365
|
-
if entry.compression_method != ::Zip::
|
364
|
+
if entry.compression_method != ::Zip::Entry::STORED
|
366
365
|
raise MalformedContainerError.new("'mimetype' file is compressed.")
|
367
366
|
end
|
368
367
|
|
@@ -406,16 +405,16 @@ module ZipContainer
|
|
406
405
|
# each {|entry| ...}
|
407
406
|
#
|
408
407
|
# Iterate over the entries in the ZipContainer file. The entry objects
|
409
|
-
# returned by this method are Zip::
|
408
|
+
# returned by this method are Zip::Entry objects. Please see the
|
410
409
|
# rubyzip documentation for details.
|
411
410
|
|
412
411
|
##
|
413
|
-
# :method:
|
412
|
+
# :method: entries
|
414
413
|
# :call-seq:
|
415
414
|
# entries -> Enumerable
|
416
415
|
#
|
417
416
|
# Returns an Enumerable containing all the entries in the ZipContainer
|
418
|
-
# file The entry objects returned by this method are Zip::
|
417
|
+
# file The entry objects returned by this method are Zip::Entry
|
419
418
|
# objects. Please see the rubyzip documentation for details.
|
420
419
|
|
421
420
|
##
|
@@ -431,7 +430,7 @@ module ZipContainer
|
|
431
430
|
##
|
432
431
|
# :method: find_entry
|
433
432
|
# :call-seq:
|
434
|
-
# find_entry(entry) -> Zip::
|
433
|
+
# find_entry(entry) -> Zip::Entry
|
435
434
|
#
|
436
435
|
# Searches for entries within the ZipContainer file with the specified
|
437
436
|
# name. Returns +nil+ if no entry is found. See also +get_entry+.
|
@@ -439,7 +438,7 @@ module ZipContainer
|
|
439
438
|
##
|
440
439
|
# :method: get_entry
|
441
440
|
# :call-seq:
|
442
|
-
# get_entry(entry) -> Zip::
|
441
|
+
# get_entry(entry) -> Zip::Entry
|
443
442
|
#
|
444
443
|
# Searches for an entry within the ZipContainer file in a similar manner
|
445
444
|
# to +find_entry+, but throws +Errno::ENOENT+ if no entry is found.
|
@@ -457,7 +456,7 @@ module ZipContainer
|
|
457
456
|
##
|
458
457
|
# :method: glob
|
459
458
|
# :call-seq:
|
460
|
-
# glob(*args) -> Array of Zip::
|
459
|
+
# glob(*args) -> Array of Zip::Entry
|
461
460
|
# glob(*args) {|entry| ...}
|
462
461
|
#
|
463
462
|
# Searches for entries within the ZipContainer file that match the given
|
@@ -30,8 +30,7 @@
|
|
30
30
|
#
|
31
31
|
# Author: Robert Haines
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
#
|
35
34
|
module ZipContainer
|
36
35
|
|
37
36
|
# This module provides support for managed file and directory entries.
|
@@ -86,7 +85,7 @@ module ZipContainer
|
|
86
85
|
#
|
87
86
|
# Is the supplied entry/name a managed entry?
|
88
87
|
def managed_entry?(entry, list = managed_entry_names)
|
89
|
-
name = entry.kind_of?(::Zip::
|
88
|
+
name = entry.kind_of?(::Zip::Entry) ? entry.name : entry
|
90
89
|
name.chop! if name.end_with? "/"
|
91
90
|
list.map { |n| n.downcase }.include? name.downcase
|
92
91
|
end
|
@@ -30,8 +30,7 @@
|
|
30
30
|
#
|
31
31
|
# Author: Robert Haines
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
#
|
35
34
|
module ZipContainer
|
36
35
|
|
37
36
|
# This module provides support for reserved names.
|
@@ -67,9 +66,9 @@ module ZipContainer
|
|
67
66
|
# reserved_entry?(entry) -> boolean
|
68
67
|
#
|
69
68
|
# Is the given entry in the reserved list of names? A String or a
|
70
|
-
# Zip::
|
69
|
+
# Zip::Entry object can be passed in here.
|
71
70
|
def reserved_entry?(entry)
|
72
|
-
name = entry.kind_of?(::Zip::
|
71
|
+
name = entry.kind_of?(::Zip::Entry) ? entry.name : entry
|
73
72
|
name.chop! if name.end_with? "/"
|
74
73
|
reserved_names.map { |n| n.downcase }.include? name.downcase
|
75
74
|
end
|
data/lib/zip-container.rb
CHANGED
data/test/tc_create.rb
CHANGED
@@ -46,7 +46,7 @@ class TestCreation < Test::Unit::TestCase
|
|
46
46
|
assert(c.on_disk?)
|
47
47
|
refute(c.in_memory?)
|
48
48
|
|
49
|
-
assert(c.find_entry("mimetype").
|
49
|
+
assert(c.find_entry("mimetype").local_header_offset == 0)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -68,7 +68,7 @@ class TestCreation < Test::Unit::TestCase
|
|
68
68
|
assert(c.on_disk?)
|
69
69
|
refute(c.in_memory?)
|
70
70
|
|
71
|
-
assert(c.find_entry("mimetype").
|
71
|
+
assert(c.find_entry("mimetype").local_header_offset == 0)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
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 = "1.0.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-
|
12
|
+
s.date = "2013-12-19"
|
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 = [
|
@@ -60,18 +60,18 @@ Gem::Specification.new do |s|
|
|
60
60
|
s.add_development_dependency(%q<rake>, ["~> 10.0.4"])
|
61
61
|
s.add_development_dependency(%q<rdoc>, ["~> 4.0.1"])
|
62
62
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
63
|
-
s.add_runtime_dependency(%q<rubyzip>, ["~> 0.
|
63
|
+
s.add_runtime_dependency(%q<rubyzip>, ["~> 1.0.0"])
|
64
64
|
else
|
65
65
|
s.add_dependency(%q<rake>, ["~> 10.0.4"])
|
66
66
|
s.add_dependency(%q<rdoc>, ["~> 4.0.1"])
|
67
67
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
68
|
-
s.add_dependency(%q<rubyzip>, ["~> 0.
|
68
|
+
s.add_dependency(%q<rubyzip>, ["~> 1.0.0"])
|
69
69
|
end
|
70
70
|
else
|
71
71
|
s.add_dependency(%q<rake>, ["~> 10.0.4"])
|
72
72
|
s.add_dependency(%q<rdoc>, ["~> 4.0.1"])
|
73
73
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
74
|
-
s.add_dependency(%q<rubyzip>, ["~> 0.
|
74
|
+
s.add_dependency(%q<rubyzip>, ["~> 1.0.0"])
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
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: 1.0.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-
|
12
|
+
date: 2013-12-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
requirements:
|
67
67
|
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0.
|
69
|
+
version: 1.0.0
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +74,7 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: 0.
|
77
|
+
version: 1.0.0
|
78
78
|
description: A Ruby library for working with ZIP Container Format files. See http://www.idpf.org/epub/30/spec/epub30-ocf.html
|
79
79
|
for the OCF specification and https://learn.adobe.com/wiki/display/PDFNAV/Universal+Container+Format
|
80
80
|
for the UCF specification.
|