Project

zip_dir

0.0
No commit activity in last 3 years
No release in over 3 years
Zip and unzip directories.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 1.0.0
 Project Readme

ZipDir

Zip and unzip directories.

Installation

Add this line to your application's Gemfile:

gem 'zip_dir'

And then execute:

$ bundle

Or install it yourself as:

$ gem install zip_dir

Usage

#
# Zip
#
zipper = ZipDir::Zipper.new("optional_filename")

zip_file = zipper.generate("some/path/to/directory")
zip_file # => #<Tempfile:/var/folders/6c/s4snqy051jqdpbjw7f7tsn940000gn/T/zipper-20151127-19694-1baaqoi.zip>
zip_file == zipper.file # => true

# to zip multiple directories
zip_file = zipper.generate do |z|
  z.add_path "some/path/to/directory"
  z.add_path "another/path/to/directory" # does a shell "cp -r" operation
end

# to zip __just the paths inside the directory___
zip_file = zipper.generate("some/path/to/directory", root_directory: true)
# for multiple directories again
zip_file = zipper.generate do |z|
  z.add_path "some/path/to/directory", root_directory: true
end

# cleanup temporary directory
zipper.cleanup

#
# Unzip
#
ZipDir::Unzipper.new(zip_file.path).unzip_path # => "/var/folders/6c/s4snqy051jqdpbjw7f7tsn940000gn/T/d20151127-22683-a9vrnv"

Dir Interface

ZipDir::Zipper subclasses ZipDir::Dir, which copies paths into a temporary directory to zip. There are several options for copying files and directories:

ZipDir::Zipper.superclass # => ZipDir::Dir

zip_dir = ZipDir::Dir.new
dir = zip_dir.generate("some/path" options_described_below)
dir = zip_dir.generate do |d|
  d.add_path "some/path", options_described_below
end
dir # => #<Dir:/var/folders/6c/s4snqy051jqdpbjw7f7tsn940000gn/T/d20160330-35335-esnuha>

zip_dir.cleanup
# Directories
{ root_directory: true } # copies each file and directory path within the given directory path
{ flatten_directories: true } # copies all file paths with no directory structure copied (may override files)
{ extension: :gif || ["gif", "txt"] || "*" } # filters file extensions of paths, used with options listed above (:extensions is an alias)
{ glob: "custom_glob" } # copies the paths resulting from the custom glob

# Files and Directories
{ rename: "new_name_with_smart_extension_handling" }

dir_model

Use dir_model to create complex directories to zip.