Project

send_zip

0.0
No commit activity in last 3 years
No release in over 3 years
Similar interface to "send_file" of Rails.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0

Runtime

~> 0.2.3
 Project Readme

send_zip

Gem Version

This gem enables Rails(or any Rack based app) to send the files with being zipped dynamically. Features are:

  • Downloading starts immediately, so you don't need to wait until files are compeltely zipped. It's nice for downloading large sized files.
  • Can zip a file, files, or folder. Zipped folder keeps the directory structure.
  • Can set the encoding of file name in the zip. Now only UTF-8 and Shift-JIS are supported.

This gem is based on zipping.

Getting Started

Add the following line to your Gemfile:

gem 'send_zip'

Usage

In your controller, include SendZip

class DownloadController < ApplicationController
  include SendZip

  ...
end

then you can use send_zip with the argument of file path.

def download
  send_zip '/path/to/file'
end

You can set an array of files

send_zip ['/path/to/file', '/path/to/another']

or folder

send_zip '/path/to/folder'

Options

Some options are available like send_file.

send_zip '/path/to/file', filename: 'foo.zip', buffer_size: 1024
Option Description Default
:filename Filename File.basename(path) + '.zip'
:type MIME-Type 'application/zip'
:disposition 'attachment'
:buffer_size 1048576
:encoding Filename encoding type. Now :utf8 and :shift_jis :utf8

Notice

WEBrick is not compatible with HTTP Streaming. Use Puma, Unicorn, thin, etc. I recommend puma.

Rails Sample

Rails4 with Puma. Rails sample


Copyright Nekojarashi Inc.