Skip to content

Sends the files with being zipped dynamically. Similar interface to "send_file" of Rails.

License

Notifications You must be signed in to change notification settings

nekojarashi/send_zip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Sends the files with being zipped dynamically. Similar interface to "send_file" of Rails.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages