ucf 2.0.2 → 3.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.
- checksums.yaml +4 -4
- data/.github/workflows/latest-docs.yml +29 -0
- data/.github/workflows/lint.yml +19 -0
- data/.github/workflows/tests.yml +89 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +63 -0
- data/{test/tc_read_dir.rb → .simplecov} +19 -21
- data/{Changes.rdoc → CHANGES.md} +41 -14
- data/CODE_OF_CONDUCT.md +74 -0
- data/CONTRIBUTING.md +67 -0
- data/Gemfile +4 -2
- data/{Licence.rdoc → LICENCE} +1 -1
- data/README.md +57 -0
- data/Rakefile +21 -18
- data/bin/console +15 -0
- data/bin/setup +6 -0
- data/examples/create-ucf +11 -10
- data/examples/ucfinfo +11 -7
- data/examples/verify-ucf +5 -3
- data/lib/ucf/dir.rb +7 -8
- data/lib/ucf/file.rb +7 -8
- data/lib/ucf/{meta-inf.rb → meta_inf.rb} +24 -23
- data/lib/ucf/version.rb +6 -13
- data/lib/ucf.rb +4 -2
- data/ucf.gemspec +46 -31
- metadata +108 -83
- data/.ruby-env +0 -1
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.travis.yml +0 -19
- data/ReadMe.rdoc +0 -90
- data/test/data/META-INF/container.xml +0 -13
- data/test/data/META-INF/manifest.xml +0 -26
- data/test/data/compressed_mimetype.ucf +0 -0
- data/test/data/dirs/empty/mimetype +0 -1
- data/test/data/dirs/managed/greeting.txt +0 -1
- data/test/data/dirs/managed/mimetype +0 -1
- data/test/data/dirs/null/.gitkeep +0 -1
- data/test/data/empty.ucf +0 -0
- data/test/data/empty.zip +0 -0
- data/test/data/example.ucf +0 -0
- data/test/data/null.file +0 -0
- data/test/tc_create_file.rb +0 -142
- data/test/tc_managed_entries.rb +0 -238
- data/test/tc_read_file.rb +0 -119
- data/test/tc_reserved_names.rb +0 -357
- data/test/ts_ucf.rb +0 -52
- data/version.yml +0 -4
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'ucf'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/examples/create-ucf
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Copyright (c) 2013-2025 The University of Manchester, UK.
|
3
5
|
#
|
4
6
|
# All rights reserved.
|
5
7
|
#
|
@@ -44,29 +46,28 @@ usage unless ARGV.length == 1
|
|
44
46
|
|
45
47
|
ucffile = ARGV[0]
|
46
48
|
|
47
|
-
if File.
|
49
|
+
if File.exist?(ucffile)
|
48
50
|
puts "File '#{ucffile}' already exists. Exiting."
|
49
51
|
exit 1
|
50
52
|
end
|
51
53
|
|
52
54
|
begin
|
53
55
|
UCF::File.create(ucffile) do |c|
|
54
|
-
|
55
56
|
# Add a cheery greeting file from a string.
|
56
|
-
c.file.open(
|
57
|
-
f.puts
|
57
|
+
c.file.open('greeting.txt', 'w') do |f|
|
58
|
+
f.puts 'Hello, World!'
|
58
59
|
end
|
59
60
|
|
60
61
|
# Create a subdirectory.
|
61
|
-
c.dir.mkdir(
|
62
|
+
c.dir.mkdir('dir')
|
62
63
|
|
63
64
|
# Copy this example code in straight from a file.
|
64
|
-
c.add(
|
65
|
+
c.add('dir/code.rb', __FILE__)
|
65
66
|
|
66
67
|
# Add a explanation of this file.
|
67
|
-
c.comment =
|
68
|
+
c.comment = 'This is an example UCF file!'
|
68
69
|
end
|
69
|
-
rescue ZipContainer::MalformedContainerError, ZipContainer::Error =>
|
70
|
-
puts
|
70
|
+
rescue ZipContainer::MalformedContainerError, ZipContainer::Error => e
|
71
|
+
puts e
|
71
72
|
exit 1
|
72
73
|
end
|
data/examples/ucfinfo
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Copyright (c) 2013-2025 The University of Manchester, UK.
|
3
5
|
#
|
4
6
|
# All rights reserved.
|
5
7
|
#
|
@@ -46,12 +48,12 @@ ucffile = ARGV[0]
|
|
46
48
|
|
47
49
|
begin
|
48
50
|
ucf = UCF::File.open(ucffile)
|
49
|
-
rescue ZipContainer::MalformedContainerError, ZipContainer::Error =>
|
50
|
-
puts
|
51
|
+
rescue ZipContainer::MalformedContainerError, ZipContainer::Error => e
|
52
|
+
puts e
|
51
53
|
exit 1
|
52
54
|
end
|
53
55
|
|
54
|
-
puts "Archive: #{ucf
|
56
|
+
puts "Archive: #{ucf}"
|
55
57
|
puts "UCF file size: #{File.size(ucffile)} bytes, number of entries: #{ucf.size}"
|
56
58
|
|
57
59
|
total_size = 0
|
@@ -60,11 +62,13 @@ total_comp = 0
|
|
60
62
|
ucf.each do |entry|
|
61
63
|
total_size += entry.size
|
62
64
|
total_comp += entry.compressed_size
|
63
|
-
comp = entry.compression_method
|
65
|
+
comp = entry.compression_method.zero? ? 'stor' : 'defN'
|
64
66
|
size = entry.size.to_s.rjust(8)
|
65
67
|
puts "#{size} #{comp} #{entry.time} #{entry.name}"
|
66
68
|
end
|
67
69
|
|
68
70
|
ratio = ((total_size - total_comp) / total_size.to_f) * 100
|
69
|
-
puts
|
70
|
-
|
71
|
+
puts format(
|
72
|
+
'%<num>d files, %<size>d bytes uncompressed, %<comp>d bytes compressed: %<ratio>.1f%%',
|
73
|
+
{ num: ucf.size, size: total_size, comp: total_comp, ratio: ratio }
|
74
|
+
)
|
data/examples/verify-ucf
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Copyright (c) 2013-2025 The University of Manchester, UK.
|
3
5
|
#
|
4
6
|
# All rights reserved.
|
5
7
|
#
|
@@ -46,7 +48,7 @@ ucffile = ARGV[0]
|
|
46
48
|
|
47
49
|
begin
|
48
50
|
UCF::File.verify!(ucffile)
|
49
|
-
rescue ZipContainer::MalformedContainerError, ZipContainer::Error =>
|
50
|
-
puts
|
51
|
+
rescue ZipContainer::MalformedContainerError, ZipContainer::Error => e
|
52
|
+
puts e
|
51
53
|
exit 1
|
52
54
|
end
|
data/lib/ucf/dir.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2014-2025 The University of Manchester, UK.
|
2
4
|
#
|
3
5
|
# All rights reserved.
|
4
6
|
#
|
@@ -30,9 +32,8 @@
|
|
30
32
|
#
|
31
33
|
# Author: Robert Haines
|
32
34
|
|
33
|
-
|
35
|
+
##
|
34
36
|
module UCF
|
35
|
-
|
36
37
|
# This class represents a UCF document - also known as an EPUB and very
|
37
38
|
# similar to the
|
38
39
|
# {EPUB Open Container Format (OCF)}[http://www.idpf.org/epub/30/spec/epub30-ocf.html].
|
@@ -41,17 +42,16 @@ module UCF
|
|
41
42
|
# for more details.
|
42
43
|
#
|
43
44
|
# This class is a specialization of ZipContainer::Dir so you should see the
|
44
|
-
# {ZipContainer documentation}[http://
|
45
|
+
# {ZipContainer documentation}[http://hainesr.github.io/ruby-zip-container/]
|
45
46
|
# for much more information and a list of all the other methods available in
|
46
47
|
# this class. RDoc does not list inherited methods, unfortunately.
|
47
48
|
#
|
48
49
|
# There are code examples available with the source code of this library.
|
49
50
|
class Dir < ZipContainer::Dir
|
50
|
-
|
51
51
|
private_class_method :new
|
52
52
|
|
53
53
|
# :stopdoc:
|
54
|
-
DEFAULT_MIMETYPE =
|
54
|
+
DEFAULT_MIMETYPE = 'application/epub+zip'
|
55
55
|
|
56
56
|
def initialize(filename)
|
57
57
|
super(filename)
|
@@ -72,12 +72,11 @@ module UCF
|
|
72
72
|
# default, "application/epub+zip", will be used.
|
73
73
|
#
|
74
74
|
# Please see the
|
75
|
-
# {ZipContainer documentation}[http://
|
75
|
+
# {ZipContainer documentation}[http://hainesr.github.io/ruby-zip-container/]
|
76
76
|
# for much more information and a list of all the other methods available
|
77
77
|
# in this class. RDoc does not list inherited methods, unfortunately.
|
78
78
|
def self.create(filename, mimetype = DEFAULT_MIMETYPE, &block)
|
79
79
|
super(filename, mimetype, &block)
|
80
80
|
end
|
81
|
-
|
82
81
|
end
|
83
82
|
end
|
data/lib/ucf/file.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2013-2025 The University of Manchester, UK.
|
2
4
|
#
|
3
5
|
# All rights reserved.
|
4
6
|
#
|
@@ -30,9 +32,8 @@
|
|
30
32
|
#
|
31
33
|
# Author: Robert Haines
|
32
34
|
|
33
|
-
|
35
|
+
##
|
34
36
|
module UCF
|
35
|
-
|
36
37
|
# This class represents a UCF document file - also known as an EPUB and very
|
37
38
|
# similar to the
|
38
39
|
# {EPUB Open Container Format (OCF)}[http://www.idpf.org/epub/30/spec/epub30-ocf.html].
|
@@ -41,17 +42,16 @@ module UCF
|
|
41
42
|
# for more details.
|
42
43
|
#
|
43
44
|
# This class is a specialization of ZipContainer::File so you should see the
|
44
|
-
# {ZipContainer documentation}[http://
|
45
|
+
# {ZipContainer documentation}[http://hainesr.github.io/ruby-zip-container/]
|
45
46
|
# for much more information and a list of all the other methods available in
|
46
47
|
# this class. RDoc does not list inherited methods, unfortunately.
|
47
48
|
#
|
48
49
|
# There are code examples available with the source code of this library.
|
49
50
|
class File < ZipContainer::File
|
50
|
-
|
51
51
|
private_class_method :new
|
52
52
|
|
53
53
|
# :stopdoc:
|
54
|
-
DEFAULT_MIMETYPE =
|
54
|
+
DEFAULT_MIMETYPE = 'application/epub+zip'
|
55
55
|
|
56
56
|
def initialize(filename)
|
57
57
|
super(filename)
|
@@ -72,12 +72,11 @@ module UCF
|
|
72
72
|
# "application/epub+zip", will be used.
|
73
73
|
#
|
74
74
|
# Please see the
|
75
|
-
# {ZipContainer documentation}[http://
|
75
|
+
# {ZipContainer documentation}[http://hainesr.github.io/ruby-zip-container/]
|
76
76
|
# for much more information and a list of all the other methods available
|
77
77
|
# in this class. RDoc does not list inherited methods, unfortunately.
|
78
78
|
def self.create(filename, mimetype = DEFAULT_MIMETYPE, &block)
|
79
79
|
super(filename, mimetype, &block)
|
80
80
|
end
|
81
|
-
|
82
81
|
end
|
83
82
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2013-2025 The University of Manchester, UK.
|
2
4
|
#
|
3
5
|
# All rights reserved.
|
4
6
|
#
|
@@ -37,41 +39,41 @@ rescue LoadError
|
|
37
39
|
end
|
38
40
|
|
39
41
|
module UCF
|
40
|
-
|
41
42
|
# This is a subclass of ManagedDirectory to represent the META-INF directory
|
42
43
|
# in a basic UCF Document.
|
43
|
-
class MetaInf < ZipContainer::ManagedDirectory
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
MANIFEST_SCHEMA = ::File.join(SCHEMA_DIR, "OpenDocument-manifest-schema-v1.0-os.rng")
|
44
|
+
class MetaInf < ZipContainer::ManagedDirectory # :nodoc:
|
45
|
+
SCHEMA_DIR = ::File.join(::File.dirname(__FILE__), 'schema')
|
46
|
+
CONTAINER_SCHEMA = ::File.join(SCHEMA_DIR, 'container.rng')
|
47
|
+
MANIFEST_SCHEMA = ::File.join(SCHEMA_DIR, 'OpenDocument-manifest-schema-v1.0-os.rng')
|
48
48
|
|
49
49
|
# :call-seq:
|
50
50
|
# new -> MetaInf
|
51
51
|
#
|
52
52
|
# Create a standard META-INF ManagedDirectory.
|
53
53
|
def initialize
|
54
|
-
super(
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
54
|
+
super(
|
55
|
+
'META-INF',
|
56
|
+
required: false,
|
57
|
+
entries:
|
58
|
+
[
|
59
|
+
File.new('container.xml', CONTAINER_SCHEMA),
|
60
|
+
File.new('manifest.xml', MANIFEST_SCHEMA),
|
61
|
+
File.new('metadata.xml'),
|
62
|
+
File.new('signatures.xml'),
|
63
|
+
File.new('encryption.xml'),
|
64
|
+
File.new('rights.xml')
|
65
|
+
]
|
63
66
|
)
|
64
67
|
end
|
65
68
|
|
66
|
-
class File < ZipContainer::ManagedFile
|
67
|
-
|
69
|
+
class File < ZipContainer::ManagedFile # :nodoc:
|
68
70
|
def initialize(name, schema = nil)
|
69
|
-
super(name, :
|
71
|
+
super(name, required: false)
|
70
72
|
|
71
73
|
@schema = nil
|
72
|
-
|
73
|
-
|
74
|
-
|
74
|
+
return unless defined?(::Nokogiri)
|
75
|
+
|
76
|
+
@schema = schema.nil? ? nil : Nokogiri::XML::RelaxNG(::File.open(schema))
|
75
77
|
end
|
76
78
|
|
77
79
|
protected
|
@@ -80,6 +82,5 @@ module UCF
|
|
80
82
|
@schema.nil? ? true : @schema.validate(Nokogiri::XML(contents)) == []
|
81
83
|
end
|
82
84
|
end
|
83
|
-
|
84
85
|
end
|
85
86
|
end
|
data/lib/ucf/version.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2014-2025 The University of Manchester, UK.
|
2
4
|
#
|
3
5
|
# All rights reserved.
|
4
6
|
#
|
@@ -30,17 +32,8 @@
|
|
30
32
|
#
|
31
33
|
# Author: Robert Haines
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
+
##
|
35
36
|
module UCF
|
36
|
-
|
37
|
-
|
38
|
-
module Version
|
39
|
-
# Version information in a Hash
|
40
|
-
INFO = YAML.load_file(File.join(File.dirname(__FILE__), "..", "..",
|
41
|
-
"version.yml"))
|
42
|
-
|
43
|
-
# Version number as a String
|
44
|
-
STRING = [:major, :minor, :patch].map {|d| INFO[d]}.compact.join('.')
|
45
|
-
end
|
37
|
+
# The current version of the UCF library.
|
38
|
+
VERSION = '3.0.0'
|
46
39
|
end
|
data/lib/ucf.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2013-2025 The University of Manchester, UK.
|
2
4
|
#
|
3
5
|
# All rights reserved.
|
4
6
|
#
|
@@ -36,7 +38,7 @@ require 'bundler/setup'
|
|
36
38
|
require 'zip-container'
|
37
39
|
|
38
40
|
require 'ucf/version'
|
39
|
-
require 'ucf/
|
41
|
+
require 'ucf/meta_inf'
|
40
42
|
require 'ucf/dir'
|
41
43
|
require 'ucf/file'
|
42
44
|
|
data/ucf.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2013-2025 The University of Manchester, UK.
|
2
4
|
#
|
3
5
|
# All rights reserved.
|
4
6
|
#
|
@@ -30,37 +32,50 @@
|
|
30
32
|
#
|
31
33
|
# Author: Robert Haines
|
32
34
|
|
33
|
-
|
34
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
35
|
-
require "ucf/version"
|
35
|
+
require_relative 'lib/ucf/version'
|
36
36
|
|
37
37
|
Gem::Specification.new do |s|
|
38
|
-
s.name =
|
39
|
-
s.version = UCF::
|
40
|
-
s.authors = [
|
41
|
-
s.email = [
|
42
|
-
s.homepage =
|
38
|
+
s.name = 'ucf'
|
39
|
+
s.version = UCF::VERSION
|
40
|
+
s.authors = ['Robert Haines', 'Finn Bacall']
|
41
|
+
s.email = ['robert.haines@manchester.ac.uk']
|
42
|
+
s.homepage = 'https://github.com/hainesr/ruby-ucf'
|
43
43
|
s.platform = Gem::Platform::RUBY
|
44
|
-
s.summary =
|
45
|
-
s.description =
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
s.
|
54
|
-
s.
|
55
|
-
s.
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
s.
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
44
|
+
s.summary = 'Universal Container Format (UCF) Ruby Library'
|
45
|
+
s.description =
|
46
|
+
'A Ruby library for working with Universal Container ' \
|
47
|
+
'Format files - a type of EPUB document. See the UCF specification ' \
|
48
|
+
'(https://learn.adobe.com/wiki/display/PDFNAV/Universal+Container+Format) ' \
|
49
|
+
'for details. They are very similar, although not as restrictive, as ' \
|
50
|
+
'the EPUB Open Container Format (OCF) ' \
|
51
|
+
'(http://www.idpf.org/epub/30/spec/epub30-ocf.html).'
|
52
|
+
|
53
|
+
s.license = 'BSD'
|
54
|
+
s.require_paths = ['lib']
|
55
|
+
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
56
|
+
f.match(%r{^(test|spec|features)/})
|
57
|
+
end
|
58
|
+
|
59
|
+
s.metadata = {
|
60
|
+
'bug_tracker_uri' => 'https://github.com/hainesr/ruby-ucf/issues',
|
61
|
+
'changelog_uri' => "https://github.com/hainesr/ruby-ucf/blob/v#{s.version}/Changelog.md",
|
62
|
+
'documentation_uri' => 'https://hainesr.github.io/ruby-ucf',
|
63
|
+
'source_code_uri' => "https://github.com/hainesr/ruby-ucf/tree/v#{s.version}",
|
64
|
+
'rubygems_mfa_required' => 'true'
|
65
|
+
}
|
66
|
+
|
67
|
+
s.required_ruby_version = '>= 3.0'
|
68
|
+
|
69
|
+
s.add_development_dependency 'minitest', '~> 5.25'
|
70
|
+
s.add_development_dependency 'nokogiri', '~> 1.18.9'
|
71
|
+
s.add_development_dependency 'rake', '~> 13.2'
|
72
|
+
s.add_development_dependency 'rdoc', '~> 6.11'
|
73
|
+
s.add_development_dependency 'rubocop', '~> 1.50.0'
|
74
|
+
s.add_development_dependency 'rubocop-minitest', '~> 0.30.0'
|
75
|
+
s.add_development_dependency 'rubocop-performance', '~> 1.17.0'
|
76
|
+
s.add_development_dependency 'rubocop-rake', '~> 0.6.0'
|
77
|
+
s.add_development_dependency 'simplecov', '0.22.0'
|
78
|
+
s.add_development_dependency 'simplecov-lcov', '~> 0.8.0'
|
79
|
+
|
80
|
+
s.add_runtime_dependency 'zip-container', '~> 6.0'
|
66
81
|
end
|