epzip 0.7.1 → 0.8.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/VERSION +1 -1
- data/epzip.gemspec +2 -2
- data/lib/epzip.rb +20 -32
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
data/epzip.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{epzip}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.8.0"
|
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-10-
|
12
|
+
s.date = %q{2010-10-06}
|
13
13
|
s.description = %q{epzip is EPUB packing tool. It's just only to do 'zip.'}
|
14
14
|
s.email = %q{takahashimm@gmail.com}
|
15
15
|
s.executables = ["epunzip", "epzip"]
|
data/lib/epzip.rb
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
|
1
|
+
require 'fileutils'
|
2
|
+
require 'tmpdir'
|
4
3
|
class Epzip
|
5
4
|
MIMETYPE_FILENAME = 'mimetype'
|
5
|
+
|
6
|
+
@@zip_cmd_path = 'zip'
|
7
|
+
@@unzip_cmd_path = 'unzip'
|
8
|
+
|
9
|
+
def self.zip_cmd_path=(cmd); @@zip_cmd_path = cmd end
|
10
|
+
def self.zip_cmd_path; @@zip_cmd_path end
|
11
|
+
def self.unzip_cmd_path=(cmd); @@unzip_cmd_path = cmd end
|
12
|
+
def self.unzip_cmd_path; @@unzip_cmd_path end
|
6
13
|
|
7
14
|
def self.zip(epubdir, epubfile = nil)
|
8
15
|
if !File.exists? epubdir
|
@@ -10,26 +17,21 @@ class Epzip
|
|
10
17
|
end
|
11
18
|
|
12
19
|
epubfile ||= epubdir+".epub"
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
f.put_next_entry(MIMETYPE_FILENAME, nil, nil, Zip::ZipEntry::STORED)
|
17
|
-
f << "application/epub+zip"
|
18
|
-
puts MIMETYPE_FILENAME
|
20
|
+
|
21
|
+
Dir.mktmpdir do |tmpdir|
|
22
|
+
tmpfile = "#{tmpdir}/tmp.epub"
|
19
23
|
|
20
24
|
Dir.chdir(epubdir) do
|
21
|
-
|
22
|
-
|
23
|
-
next if !File.file? dir
|
24
|
-
puts dir
|
25
|
-
f.put_next_entry dir
|
26
|
-
f << File.read(dir)
|
25
|
+
File.open(MIMETYPE_FILENAME, "w") do |f|
|
26
|
+
f.write("application/epub+zip")
|
27
27
|
end
|
28
|
+
system("#{@@zip_cmd_path} -0X #{tmpfile} #{MIMETYPE_FILENAME}")
|
29
|
+
system("#{@@zip_cmd_path} -Xr9D #{tmpfile} * -x #{MIMETYPE_FILENAME}")
|
28
30
|
end
|
29
|
-
end
|
30
31
|
|
32
|
+
FileUtils.cp(tmpfile, epubfile)
|
33
|
+
end
|
31
34
|
epubfile
|
32
|
-
|
33
35
|
end
|
34
36
|
|
35
37
|
def self.unzip(epubfile, epubdir = nil)
|
@@ -39,21 +41,7 @@ class Epzip
|
|
39
41
|
epubdir = Dir.pwd
|
40
42
|
end
|
41
43
|
|
42
|
-
|
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
|
-
|
44
|
+
system("#{@@unzip_cmd_path} #{epubfile} -d #{epubdir}")
|
57
45
|
end
|
58
46
|
|
59
47
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 8
|
8
|
+
- 0
|
9
|
+
version: 0.8.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Masayoshi Takahashi
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-10-
|
17
|
+
date: 2010-10-06 00:00:00 +09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|