Module: ZipFileUtils
- Defined in:
- lib/write_xlsx/zip_file_utils.rb
Class Method Summary collapse
-
.unzip(src, dest, options = {}) ⇒ Object
src zip filename dest destination directory options :fs_encoding=.
-
.zip(src, dest, options = {}) ⇒ Object
src file or directory dest zip filename options :fs_encoding=.
Class Method Details
.unzip(src, dest, options = {}) ⇒ Object
src zip filename dest destination directory options :fs_encoding=
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/write_xlsx/zip_file_utils.rb', line 37 def self.unzip(src, dest, = {}) FileUtils.makedirs(dest) Zip::ZipInputStream.open(src){ |is| loop do entry = is.get_next_entry() break if entry.nil?() dir = File.dirname(entry.name) FileUtils.makedirs(dest+ '/' + dir) path = encode_path(dest + '/' + entry.name, [:fs_encoding]) if(entry.file?()) File.open(path, File::CREAT|File::WRONLY|File::BINARY) do |w| w.puts(is.read()) end else FileUtils.makedirs(path) end end } end |
.zip(src, dest, options = {}) ⇒ Object
src file or directory dest zip filename options :fs_encoding=
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/write_xlsx/zip_file_utils.rb', line 14 def self.zip(src, dest, = {}) src = File.(src) dest = File.(dest) File.unlink(dest) if File.exist?(dest) Zip::ZipFile.open(dest, Zip::ZipFile::CREATE) {|zf| if(File.file?(src)) zf.add(encode_path(File.basename(src), [:fs_encoding]), src) break else each_dir_for(src){ |path| if File.file?(path) zf.add(encode_path(relative(path, src), [:fs_encoding]), path) elsif File.directory?(path) zf.mkdir(encode_path(relative(path, src), [:fs_encoding])) end } end } end |