zip-container 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,59 @@
1
+ = Changes log for the ZIP Container Ruby Gem
2
+
3
+ == Version 0.8.0
4
+
5
+ * Abstract out all the underlying zip functionality and turn this library
6
+ into a basic ZIP Container provider.
7
+
8
+ == Version 0.5.0
9
+
10
+ * Add support for managed entries in the container.
11
+ * Verify and "optional" functionality for ManagedEntry.
12
+ * Use reserved and managed entry mixins for managed directories.
13
+ * Better initialization of managed entry support.
14
+ * Fix creation of subclassed Container objects.
15
+ * Add extra tests for managed entries.
16
+ * Make file validation more flexible.
17
+ * Fix the source of failing validation messages.
18
+
19
+ == Version 0.1.0
20
+
21
+ * Improvements to the reserved names code to allow sub-classing.
22
+ * Move exceptions to a new source file.
23
+ * Use a base class for UCF exceptions.
24
+ * Standardize the MalformedUCFError exception messages.
25
+ * Add an exception for clashes with reserved names.
26
+ * Implement Container#add to avoid using reserved names.
27
+ * Raise an exception if renaming to a reserved name.
28
+ * Implement Container#mkdir to avoid using reserved names.
29
+ * Make sure testing reserved names copes with trailing slashes.
30
+ * Fake up the connection to ZipFileSystem.
31
+ * Implement Container#get_output_stream to respect reserved names.
32
+ * Can now set comments on the UCF document.
33
+ * Implement the close and commit methods.
34
+ * Forward the commit_required? method.
35
+ * Separate the opening and checking of a UCF document.
36
+ * Documentation improvements and cleanup.
37
+
38
+ == Version 0.0.2
39
+
40
+ * Update the main ReadMe file.
41
+ * Add support for multiple reserved names and fix checks.
42
+ * Ensure UCF document is closed after verifying it.
43
+ * Expose the "each" method for enumerating UCF entries.
44
+ * Expose the "size" method to count UCF entries.
45
+ * Add an example program to list UCF contents.
46
+ * Add a method to directly iterate over UCF entries.
47
+
48
+ == Version 0.0.1
49
+
50
+ * Very basic UCF facilities complete (plus examples).
51
+ * Two ways of verifying UCF files.
52
+ * API documentation added.
53
+ * Add tests.
54
+
55
+ == About this Changes file
56
+
57
+ This file is, at least in part, generated by the following command:
58
+
59
+ $ git log --pretty=format:"* %s" --reverse --no-merges <commit-hash>..
@@ -0,0 +1,29 @@
1
+ Copyright (c) 2013 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.
@@ -0,0 +1,85 @@
1
+ # Copyright (c) 2013 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 'rubygems'
34
+ require 'rake'
35
+ require 'rake/clean'
36
+ require 'rake/testtask'
37
+ require 'rdoc/task'
38
+ require 'jeweler'
39
+
40
+ # we need to add lib to the path because we're not installed yet!
41
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "lib")
42
+ require 'zip-container'
43
+
44
+ task :default => [:test]
45
+
46
+ Jeweler::Tasks.new do |s|
47
+ s.name = "zip-container"
48
+ s.version = ZipContainer::Version::STRING
49
+ s.authors = ["Robert Haines"]
50
+ s.email = ["support@mygrid.org.uk"]
51
+ s.homepage = "http://mygrid.github.io/ruby-zip-container/"
52
+ s.platform = Gem::Platform::RUBY
53
+ s.summary = "A ZIP Container for use by OCF and UCF implementations"
54
+ s.description = "A Ruby library for working with ZIP Container "\
55
+ "Format files. See "\
56
+ "http://www.idpf.org/epub/30/spec/epub30-ocf.html for the OCF "\
57
+ "specification and "\
58
+ "https://learn.adobe.com/wiki/display/PDFNAV/Universal+Container+Format "\
59
+ "for the UCF specification."
60
+ s.require_path = "lib"
61
+ s.test_file = "test/ts_container.rb"
62
+ s.has_rdoc = true
63
+ s.extra_rdoc_files = ["ReadMe.rdoc", "Licence.rdoc", "Changes.rdoc"]
64
+ s.rdoc_options = ["-N", "--tab-width=2", "--main=ReadMe.rdoc"]
65
+ s.add_development_dependency('rake', '~> 10.0.4')
66
+ s.add_development_dependency('rdoc', '~> 4.0.1')
67
+ s.add_development_dependency('jeweler', '~> 1.8.4')
68
+ s.add_runtime_dependency('rubyzip', '~> 0.9.9')
69
+ end
70
+
71
+ Rake::TestTask.new do |t|
72
+ t.libs << "test"
73
+ t.test_files = FileList['test/ts_container.rb']
74
+ t.verbose = true
75
+ end
76
+
77
+ RDoc::Task.new do |r|
78
+ r.main = "ReadMe.rdoc"
79
+ lib = Dir.glob("lib/**/*.rb")
80
+ r.rdoc_files.include("ReadMe.rdoc", "Licence.rdoc", "Changes.rdoc", lib)
81
+ r.options << "-t ZIP Container Format Ruby Library version " +
82
+ "#{ZipContainer::Version::STRING}"
83
+ r.options << "-N"
84
+ r.options << "--tab-width=2"
85
+ end
@@ -0,0 +1,34 @@
1
+ = ZIP Container Format Ruby Library
2
+
3
+ Authors:: Robert Haines
4
+ Contact:: mailto:support@mygrid.org.uk
5
+ Homepage:: http://mygrid.github.io/ruby-zip-container
6
+ Source code:: https://github.com/myGrid/ruby-zip-container
7
+ Licence:: BSD (See Licence file or http://www.opensource.org/licenses/bsd-license.php)
8
+ Copyright:: (c) 2013 The University of Manchester, UK
9
+
10
+ {<img src="https://codeclimate.com/github/myGrid/ruby-zip-container.png" />}[https://codeclimate.com/github/myGrid/ruby-zip-container]
11
+
12
+ == Synopsis
13
+
14
+ This is a Ruby library for working with ZIP Container files. See the
15
+ {ODF}[http://www.idpf.org/epub/30/spec/epub30-ocf.html] and
16
+ {UDF}[https://learn.adobe.com/wiki/display/PDFNAV/Universal+Container+Format]
17
+ specifications for more details.
18
+
19
+ <b>This library is a work in progress!</b> Until we release version 1.0.0 you
20
+ can expect the API to change in incompatible ways, although we will try to
21
+ keep this to an absolute minimum. Once version 1.0.0 is released we will be
22
+ following the principles of {Semantic Versioning}[http://semver.org/] for our
23
+ version numbering scheme.
24
+
25
+ There are some examples of how to use the library provided in the examples
26
+ directory. See the contents of the tests directory for even more.
27
+
28
+ == What this library can not do yet
29
+
30
+ The basic requirements of a ZIP Container are all implemented but memory
31
+ resident ZIP Container files are not yet supported. Presently all operations
32
+ are performed on files that are resident on disk as the underlying
33
+ {rubyzip library}[https://github.com/aussiegeek/rubyzip] currently
34
+ {cannot do anything else}[https://github.com/aussiegeek/rubyzip/issues/74].
@@ -0,0 +1,61 @@
1
+ # Copyright (c) 2013 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 'rubygems'
34
+ require 'zip-container'
35
+
36
+ ZIP_FILE = "example.zip"
37
+ file = ARGV.length > 0 ? ARGV[0] : ZIP_FILE
38
+
39
+ File.delete(file) if File.exists?(file)
40
+
41
+ begin
42
+ ZipContainer::Container.create(file, "application/epub+zip") do |c|
43
+
44
+ # Add a cheery greeting file from a string.
45
+ c.file.open("greeting.txt", "w") do |f|
46
+ f.puts "Hello, World!"
47
+ end
48
+
49
+ # Create a subdirectory.
50
+ c.dir.mkdir("dir")
51
+
52
+ # Copy this example code in straight from a file.
53
+ c.add("dir/code.rb", __FILE__)
54
+
55
+ # Add a explanation of this file.
56
+ c.comment = "This is an example Container file!"
57
+ end
58
+ rescue ZipContainer::MalformedZipContainerError, Zip::ZipError => err
59
+ puts err.to_s
60
+ exit 1
61
+ end
@@ -0,0 +1,44 @@
1
+ # Copyright (c) 2013 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 'rubygems'
34
+ require 'zip-container'
35
+
36
+ ZIP_FILE = "example.zip"
37
+ file = ARGV.length > 0 ? ARGV[0] : ZIP_FILE
38
+
39
+ begin
40
+ ZipContainer::Container.verify!(file)
41
+ rescue ZipContainer::MalformedZipContainerError, Zip::ZipError => err
42
+ puts err.to_s
43
+ exit 1
44
+ end
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (c) 2013 The University of Manchester, UK.
3
+ #
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # * Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ #
12
+ # * Redistributions in binary form must reproduce the above copyright notice,
13
+ # this list of conditions and the following disclaimer in the documentation
14
+ # and/or other materials provided with the distribution.
15
+ #
16
+ # * Neither the names of The University of Manchester nor the names of its
17
+ # contributors may be used to endorse or promote products derived from this
18
+ # software without specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ # POSSIBILITY OF SUCH DAMAGE.
31
+ #
32
+ # Author: Robert Haines
33
+
34
+ require 'rubygems'
35
+ require 'zip-container'
36
+
37
+ def usage
38
+ puts "zip-container-info zip-container-file"
39
+ exit 1
40
+ end
41
+
42
+ usage unless ARGV.length == 1
43
+
44
+ container_file = ARGV[0]
45
+
46
+ begin
47
+ container = ZipContainer::Container.open(container_file)
48
+ rescue ZipContainer::MalformedZipContainerError, Zip::ZipError => err
49
+ puts err.to_s
50
+ exit 1
51
+ end
52
+
53
+ puts "Archive: #{container.to_s}"
54
+ puts "Container file size: #{File.size(container_file)} bytes, "\
55
+ "number of entries: #{container.size}"
56
+
57
+ total_size = 0
58
+ total_comp = 0
59
+
60
+ container.each do |entry|
61
+ total_size += entry.size
62
+ total_comp += entry.compressed_size
63
+ comp = entry.compression_method == 0 ? "stor" : "defN"
64
+ size = entry.size.to_s.rjust(8)
65
+ puts "#{size} #{comp} #{entry.time} #{entry.name}"
66
+ end
67
+
68
+ ratio = ((total_size - total_comp) / total_size.to_f) * 100
69
+ puts "%d files, %d bytes uncompressed, %d bytes compressed: %.1f%%" %
70
+ [container.size, total_size, total_comp, ratio]
@@ -0,0 +1,60 @@
1
+ # Copyright (c) 2013 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 'yaml'
34
+ require 'zip-container/exceptions'
35
+ require 'zip-container/entries/reserved'
36
+ require 'zip-container/entries/managed'
37
+ require 'zip-container/entries/entry'
38
+ require 'zip-container/entries/file'
39
+ require 'zip-container/entries/directory'
40
+ require 'zip-container/container'
41
+
42
+ # This is a ruby library to read and write ZIP Container Format files. See the
43
+ # ZipContainer::Container class for more information.
44
+ #
45
+ # See the {OCF}[http://www.idpf.org/epub/30/spec/epub30-ocf.html] and
46
+ # {UCF}[https://learn.adobe.com/wiki/display/PDFNAV/Universal+Container+Format]
47
+ # specifications for more details.
48
+ module ZipContainer
49
+
50
+ # Library version information.
51
+ module Version
52
+ # Version information in a Hash
53
+ INFO = YAML.load_file(File.join(File.dirname(__FILE__), "..",
54
+ "version.yml"))
55
+
56
+ # Version number as a String
57
+ STRING = [:major, :minor, :patch].map {|d| INFO[d]}.compact.join('.')
58
+ end
59
+
60
+ end