Class: Rake::Pipeline::Web::Filters::GzipFilter
- Inherits:
-
Filter
- Object
- Filter
- Rake::Pipeline::Web::Filters::GzipFilter
- Includes:
- FilterWithDependencies
- Defined in:
- lib/rake-pipeline-web-filters/gzip_filter.rb
Overview
A filter that gzips input files using zlib
Instance Method Summary collapse
-
#generate_output(inputs, output) ⇒ Object
Implement the #generate_output method required by the Filter API.
-
#initialize(&block) ⇒ GzipFilter
constructor
A new instance of GzipFilter.
Constructor Details
#initialize(&block) ⇒ GzipFilter
Returns a new instance of GzipFilter.
25 26 27 28 |
# File 'lib/rake-pipeline-web-filters/gzip_filter.rb', line 25 def initialize(&block) block ||= proc { |input| input.sub(/\.(.*)$/, '.\1.gz') } super(&block) end |
Instance Method Details
#generate_output(inputs, output) ⇒ Object
Implement the #generate_output method required by the Filter API. Compresses each input file with Zlib.GzipWriter.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rake-pipeline-web-filters/gzip_filter.rb', line 39 def generate_output(inputs, output) inputs.each do |input| # gzip input file to stream fakefile = StringIO.new gz = Zlib::GzipWriter.new(fakefile) gz.write(input.read) gz.close # send gzipped contents to output output.write fakefile.string end end |