`StaticAsset`s are used for files that are served verbatim without any processing or concatenation. These are typical images and other binary files.
Returns file contents as its `source`.
# File lib/sprockets/static_asset.rb, line 11 11: def source 12: # File is read everytime to avoid memory bloat of large binary files 13: pathname.open('rb') { |f| f.read } 14: end
Implemented for Rack SendFile support.
# File lib/sprockets/static_asset.rb, line 17 17: def to_path 18: pathname.to_s 19: end
Save asset to disk.
# File lib/sprockets/static_asset.rb, line 22 22: def write_to(filename, options = {}) 23: # Gzip contents if filename has '.gz' 24: options[:compress] ||= File.extname(filename) == '.gz' 25: 26: FileUtils.mkdir_p File.dirname(filename) 27: 28: if options[:compress] 29: # Open file and run it through `Zlib` 30: pathname.open('rb') do |rd| 31: File.open("#{filename}+", 'wb') do |wr| 32: gz = Zlib::GzipWriter.new(wr, Zlib::BEST_COMPRESSION) 33: buf = "" 34: while rd.read(16384, buf) 35: gz.write(buf) 36: end 37: gz.close 38: end 39: end 40: else 41: # If no compression needs to be done, we can just copy it into place. 42: FileUtils.cp(pathname, "#{filename}+") 43: end 44: 45: # Atomic write 46: FileUtils.mv("#{filename}+", filename) 47: 48: # Set mtime correctly 49: File.utime(mtime, mtime, filename) 50: 51: nil 52: ensure 53: # Ensure tmp file gets cleaned up 54: FileUtils.rm("#{filename}+") if File.exist?("#{filename}+") 55: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.