Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renaming the Zip module to RubyZip #145

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion Changelog.md
@@ -1,3 +1,8 @@
1.1.2
=====

* Renamed Zip module to RubyZip.

1.1.1
=====

Expand All @@ -6,7 +11,7 @@
* Fix Zip64 writting support (@mrjamesriley)
* Fix StringIO support (@simonoff)
* Posibility to change default compression level
* Make Zip64 write support optional via configuration
* Make Zip64 write support optional via configuration

1.1.0
=====
Expand Down
42 changes: 16 additions & 26 deletions README.md
Expand Up @@ -5,32 +5,22 @@

rubyzip is a ruby library for reading and writing zip files.

## Important note

Rubyzip interface changed!!! No need to do `require "zip/zip"` and `Zip` prefix in class names removed.

If you have issues with any third-party gems what required old version of rubyzip you can use next workaround:

```ruby
gem 'rubyzip', '>= 1.0.0' # will load new rubyzip version
gem 'zip-zip' # will load compatibility for old rubyzip API.
```
This is a fork of the RubyZip gem to avoid conflicts with other gems using a module named Zip. Basically this is rename of the Zip module to RubyZip to avoid such conflicts.

## Requirements

* Ruby 1.9.2 or greater

## Installation
rubyzip is available on RubyGems, so:

```
gem install rubyzip
gem install rubyzip --source https://github.com/davidhooey/rubyzip.git
```

Or in your Gemfile:

```ruby
gem 'rubyzip'
gem 'rubyzip', :git => 'git@github.com:davidhooey/rubyzip.git'
```

## Usage
Expand All @@ -39,14 +29,14 @@ gem 'rubyzip'

```ruby
require 'rubygems'
require 'zip'
require 'rubyzip'

folder = "Users/me/Desktop/stuff_to_zip"
input_filenames = ['image.jpg', 'description.txt', 'stats.csv']

zipfile_name = "/Users/me/Desktop/archive.zip"

Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
RubyZip::File.open(zipfile_name, RubyZip::File::CREATE) do |zipfile|
input_filenames.each do |filename|
# Two arguments:
# - The name of the file as it will appear in the archive
Expand All @@ -61,12 +51,12 @@ end

```ruby
require 'rubygems'
require 'zip'
require 'rubyzip'

directory = '/Users/me/Desktop/directory_to_zip/'
zipfile_name = '/Users/me/Desktop/recursive_directory.zip'

Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
RubyZip::File.open(zipfile_name, RubyZip::File::CREATE) do |zipfile|
Dir[File.join(directory, '**', '**')].each do |file|
zipfile.add(file.sub(directory, ''), file)
end
Expand All @@ -75,7 +65,7 @@ end

### Save zip archive entries in sorted by name state

To saving zip archives in sorted order like below you need to set `::Zip.sort_entries` to `true`
To saving zip archives in sorted order like below you need to set `::RubyZip.sort_entries` to `true`

```
Vegetable/
Expand All @@ -94,7 +84,7 @@ After this entries in zip archive will be saved in ordered state.
### Reading a Zip file

```ruby
Zip::File.open('foo.zip') do |zip_file|
RubyZip::File.open('foo.zip') do |zip_file|
# Handle entries one by one
zip_file.each do |entry|
# Extract to file/directory/symlink
Expand All @@ -118,7 +108,7 @@ end
Use `write_buffer` instead `open`. Thanks to @jondruse

```ruby
buffer = Zip::OutputStream.write_buffer do |out|
buffer = RubyZip::OutputStream.write_buffer do |out|
@zip_file.entries.each do |e|
unless [DOCUMENT_FILE_PATH, RELS_FILE_PATH].include?(e.name)
out.put_next_entry(e.name)
Expand All @@ -141,35 +131,35 @@ File.open(new_path, "w") {|f| f.write(buffer.string) }
By default, rubyzip will not overwrite files if they already exist inside of the extracted path. To change this behavior, you may specify a configuration option like so:

```ruby
Zip.on_exists_proc = true
RubyZip.on_exists_proc = true
```

If you're using rubyzip with rails, consider placing this snippet of code in an initializer file such as `config/initializers/rubyzip.rb`

Additionally, if you want to configure rubyzip to overwrite existing files while creating a .zip file, you can do so with the following:

```ruby
Zip.continue_on_exists_proc = true
RubyZip.continue_on_exists_proc = true
```

If you want to store non english names and want to open properly file on Windows(pre 7) you need to set next option:

```ruby
Zip.unicode_names = true
RubyZip.unicode_names = true
```

You can set the default compression level like so:

```ruby
Zip.default_compression = Zlib::DEFAULT_COMPRESSION
RubyZip.default_compression = Zlib::DEFAULT_COMPRESSION
```

It defaults to `Zlib::DEFAULT_COMPRESSION`. Possible values are `Zlib::BEST_COMPRESSION`, `Zlib::DEFAULT_COMPRESSION` and `Zlib::NO_COMPRESSION`

All settings in same time

```ruby
Zip.setup do |c|
RubyZip.setup do |c|
c.on_exists_proc = true
c.continue_on_exists_proc = true
c.unicode_names = true
Expand All @@ -180,7 +170,7 @@ All settings in same time
By default Zip64 support is disabled for writing. To enable it do next:

```ruby
Zip.write_zip64_support = true
RubyZip.write_zip64_support = true
```

_NOTE_: If you will enable Zip64 writing then you will need zip extractor with Zip64 support to extract archive.
Expand Down
Binary file added centralEntryHeader.bin
Binary file not shown.
Binary file added compressiontest_best_compression.bin
Binary file not shown.
Binary file added compressiontest_default_compression.bin
Binary file not shown.
Binary file added compressiontest_no_compression.bin
Binary file not shown.
Binary file added deflatertest.bin
Binary file not shown.
46 changes: 23 additions & 23 deletions lib/zip.rb → lib/rubyzip.rb
Expand Up @@ -4,35 +4,35 @@
require 'fileutils'
require 'stringio'
require 'zlib'
require 'zip/dos_time'
require 'zip/ioextras'
require 'rubyzip/dos_time'
require 'rubyzip/ioextras'
require 'rbconfig'
require 'zip/entry'
require 'zip/extra_field'
require 'zip/entry_set'
require 'zip/central_directory'
require 'zip/file'
require 'zip/input_stream'
require 'zip/output_stream'
require 'zip/decompressor'
require 'zip/compressor'
require 'zip/null_decompressor'
require 'zip/null_compressor'
require 'zip/null_input_stream'
require 'zip/pass_thru_compressor'
require 'zip/pass_thru_decompressor'
require 'zip/inflater'
require 'zip/deflater'
require 'zip/streamable_stream'
require 'zip/streamable_directory'
require 'zip/constants'
require 'zip/errors'
require 'rubyzip/entry'
require 'rubyzip/extra_field'
require 'rubyzip/entry_set'
require 'rubyzip/central_directory'
require 'rubyzip/file'
require 'rubyzip/input_stream'
require 'rubyzip/output_stream'
require 'rubyzip/decompressor'
require 'rubyzip/compressor'
require 'rubyzip/null_decompressor'
require 'rubyzip/null_compressor'
require 'rubyzip/null_input_stream'
require 'rubyzip/pass_thru_compressor'
require 'rubyzip/pass_thru_decompressor'
require 'rubyzip/inflater'
require 'rubyzip/deflater'
require 'rubyzip/streamable_stream'
require 'rubyzip/streamable_directory'
require 'rubyzip/constants'
require 'rubyzip/errors'
if defined? JRUBY_VERSION
require 'jruby'
JRuby.objectspace = true
end

module Zip
module RubyZip
extend self
attr_accessor :unicode_names, :on_exists_proc, :continue_on_exists_proc, :sort_entries, :default_compression, :write_zip64_support

Expand Down
@@ -1,4 +1,4 @@
module Zip
module RubyZip
class CentralDirectory
include Enumerable

Expand Down Expand Up @@ -26,7 +26,7 @@ def write_to_stream(io) #:nodoc:
@entry_set.each { |entry| entry.write_c_dir_entry(io) }
eocd_offset = io.tell
cdir_size = eocd_offset - cdir_offset
if ::Zip.write_zip64_support
if ::RubyZip.write_zip64_support
need_zip64_eocd = cdir_offset > 0xFFFFFFFF || cdir_size > 0xFFFFFFFF || @entry_set.size > 0xFFFF
need_zip64_eocd ||= @entry_set.any? { |entry| entry.extra['Zip64'] }
if need_zip64_eocd
Expand Down
2 changes: 1 addition & 1 deletion lib/zip/compressor.rb → lib/rubyzip/compressor.rb
@@ -1,4 +1,4 @@
module Zip
module RubyZip
class Compressor #:nodoc:all
def finish
end
Expand Down
2 changes: 1 addition & 1 deletion lib/zip/constants.rb → lib/rubyzip/constants.rb
@@ -1,4 +1,4 @@
module Zip
module RubyZip
RUNNING_ON_WINDOWS = RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/i

CENTRAL_DIRECTORY_ENTRY_SIGNATURE = 0x02014b50
Expand Down
2 changes: 1 addition & 1 deletion lib/zip/decompressor.rb → lib/rubyzip/decompressor.rb
@@ -1,4 +1,4 @@
module Zip
module RubyZip
class Decompressor #:nodoc:all
CHUNK_SIZE = 32768
def initialize(input_stream)
Expand Down
4 changes: 2 additions & 2 deletions lib/zip/deflater.rb → lib/rubyzip/deflater.rb
@@ -1,7 +1,7 @@
module Zip
module RubyZip
class Deflater < Compressor #:nodoc:all

def initialize(output_stream, level = Zip.default_compression)
def initialize(output_stream, level = RubyZip.default_compression)
super()
@output_stream = output_stream
@zlib_deflater = ::Zlib::Deflate.new(level, -::Zlib::MAX_WBITS)
Expand Down
2 changes: 1 addition & 1 deletion lib/zip/dos_time.rb → lib/rubyzip/dos_time.rb
@@ -1,4 +1,4 @@
module Zip
module RubyZip
class DOSTime < Time #:nodoc:all

#MS-DOS File Date and Time format as used in Interrupt 21H Function 57H:
Expand Down