epzip 0.6.2 → 0.7.1

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.
Files changed (7) hide show
  1. data/README.rdoc +9 -1
  2. data/VERSION +1 -1
  3. data/bin/epunzip +30 -0
  4. data/bin/epzip +2 -2
  5. data/epzip.gemspec +6 -6
  6. data/lib/epzip.rb +25 -0
  7. metadata +11 -6
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = epzip
2
2
 
3
- epzip is EPUB packing tool. It's just only doing 'zip.' :)
3
+ epzip(eunzip) is EPUB packing tool. It's just only doing 'zip' and 'unzip'. :)
4
4
 
5
5
  == usage
6
6
 
@@ -12,6 +12,14 @@ and other assets.
12
12
  'filename' is EPUB filename that will be created. If no filename,
13
13
  dir + ".epub" is used.
14
14
 
15
+ $ epunzip <filename> [targetdir]
16
+
17
+ 'filename' is EPUB filename that will be extracted.
18
+
19
+ 'targetdir' is EPUB resource directory to be extracted into. If no targetdir,
20
+ current directory is used.
21
+
22
+
15
23
 
16
24
  == Note on Patches/Pull Requests
17
25
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.2
1
+ 0.7.1
data/bin/epunzip ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'rubygems'
5
+ require 'epzip'
6
+
7
+ def error_and_exit(msg)
8
+ STDERR.puts msg
9
+ exit
10
+ end
11
+
12
+ def usage()
13
+ error_and_exit "usage: epunzip <filename> [targetdir]"
14
+ end
15
+
16
+ if !(ARGV.size == 1 or ARGV.size == 2)
17
+ usage
18
+ end
19
+
20
+ file = ARGV.shift
21
+ if !File.exists? file
22
+ error_and_exit "No such file: #{file}"
23
+ end
24
+
25
+ dir = ARGV.shift
26
+ if dir and File.exists? dir
27
+ error_and_exit "Directory already exists: #{dir}"
28
+ end
29
+
30
+ Epzip.unzip(file, dir)
data/bin/epzip CHANGED
@@ -19,12 +19,12 @@ end
19
19
 
20
20
  dir = ARGV.shift
21
21
  if !File.exists? dir
22
- error "No such directory: #{dir}"
22
+ error_and_exit "No such directory: #{dir}"
23
23
  end
24
24
 
25
25
  file = ARGV.shift
26
26
  if file and File.exists? file
27
- error "File already exists: #{file}"
27
+ error_and_exit "File already exists: #{file}"
28
28
  end
29
29
 
30
30
  Epzip.zip(dir, file)
data/epzip.gemspec CHANGED
@@ -5,15 +5,14 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{epzip}
8
- s.version = "0.6.2"
8
+ s.version = "0.7.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Masayoshi Takahashi"]
12
- s.date = %q{2010-07-16}
13
- s.default_executable = %q{epzip}
12
+ s.date = %q{2010-10-03}
14
13
  s.description = %q{epzip is EPUB packing tool. It's just only to do 'zip.'}
15
14
  s.email = %q{takahashimm@gmail.com}
16
- s.executables = ["epzip"]
15
+ s.executables = ["epunzip", "epzip"]
17
16
  s.extra_rdoc_files = [
18
17
  "LICENSE",
19
18
  "README.rdoc"
@@ -25,6 +24,7 @@ Gem::Specification.new do |s|
25
24
  "README.rdoc",
26
25
  "Rakefile",
27
26
  "VERSION",
27
+ "bin/epunzip",
28
28
  "bin/epzip",
29
29
  "epzip.gemspec",
30
30
  "lib/epzip.rb",
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
34
34
  s.homepage = %q{http://github.com/takahashim/epzip}
35
35
  s.rdoc_options = ["--charset=UTF-8"]
36
36
  s.require_paths = ["lib"]
37
- s.rubygems_version = %q{1.3.6}
37
+ s.rubygems_version = %q{1.3.7}
38
38
  s.summary = %q{simple EPUB packing tool}
39
39
  s.test_files = [
40
40
  "test/helper.rb",
@@ -45,7 +45,7 @@ Gem::Specification.new do |s|
45
45
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
46
  s.specification_version = 3
47
47
 
48
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
49
  s.add_runtime_dependency(%q<rubyzip>, [">= 0.9.4"])
50
50
  else
51
51
  s.add_dependency(%q<rubyzip>, [">= 0.9.4"])
data/lib/epzip.rb CHANGED
@@ -31,4 +31,29 @@ class Epzip
31
31
  epubfile
32
32
 
33
33
  end
34
+
35
+ def self.unzip(epubfile, epubdir = nil)
36
+ if epubdir
37
+ FileUtils.mkdir_p(epubdir)
38
+ else
39
+ epubdir = Dir.pwd
40
+ end
41
+
42
+ Zip::ZipInputStream.open(epubfile) do |f|
43
+ while entry = f.get_next_entry
44
+ next if entry.directory?
45
+ next if entry.name[-1] == "/"
46
+ sep = "/"
47
+ if entry.name[0] == "/"
48
+ sep = ""
49
+ end
50
+ filepath = epubdir + sep + entry.name
51
+ dir = File.dirname(filepath)
52
+ FileUtils.mkdir_p(dir)
53
+ entry.extract(filepath)
54
+ end
55
+ end
56
+
57
+ end
58
+
34
59
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 6
8
- - 2
9
- version: 0.6.2
7
+ - 7
8
+ - 1
9
+ version: 0.7.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Masayoshi Takahashi
@@ -14,13 +14,14 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-16 00:00:00 +09:00
18
- default_executable: epzip
17
+ date: 2010-10-03 00:00:00 +09:00
18
+ default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rubyzip
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
24
25
  requirements:
25
26
  - - ">="
26
27
  - !ruby/object:Gem::Version
@@ -34,6 +35,7 @@ dependencies:
34
35
  description: epzip is EPUB packing tool. It's just only to do 'zip.'
35
36
  email: takahashimm@gmail.com
36
37
  executables:
38
+ - epunzip
37
39
  - epzip
38
40
  extensions: []
39
41
 
@@ -47,6 +49,7 @@ files:
47
49
  - README.rdoc
48
50
  - Rakefile
49
51
  - VERSION
52
+ - bin/epunzip
50
53
  - bin/epzip
51
54
  - epzip.gemspec
52
55
  - lib/epzip.rb
@@ -62,6 +65,7 @@ rdoc_options:
62
65
  require_paths:
63
66
  - lib
64
67
  required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
65
69
  requirements:
66
70
  - - ">="
67
71
  - !ruby/object:Gem::Version
@@ -69,6 +73,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
73
  - 0
70
74
  version: "0"
71
75
  required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
72
77
  requirements:
73
78
  - - ">="
74
79
  - !ruby/object:Gem::Version
@@ -78,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
83
  requirements: []
79
84
 
80
85
  rubyforge_project:
81
- rubygems_version: 1.3.6
86
+ rubygems_version: 1.3.7
82
87
  signing_key:
83
88
  specification_version: 3
84
89
  summary: simple EPUB packing tool