7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/epzip.rb', line 7
def self.zip(epubdir, epubfile = nil)
if !File.exists? epubdir
raise ArgumentError, "No such directory -- #{epubdir}"
end
epubfile ||= epubdir+".epub"
Zip::ZipOutputStream.open(epubfile) do |f|
f.put_next_entry(MIMETYPE_FILENAME, nil, nil, Zip::ZipEntry::STORED)
f << "application/epub+zip"
puts MIMETYPE_FILENAME
Dir.chdir(epubdir) do
Dir.glob("**/*") do |dir|
next if dir == MIMETYPE_FILENAME
next if !File.file? dir
puts dir
f.put_next_entry dir
f << File.read(dir)
end
end
end
epubfile
end
|