class Sprockets::Utils::Gzip
def can_compress?
through a compression algorithm would make them larger.
files as they may already be compressed and running them
You do not want to compress binary
We want to compress any file that is text based.
Private: Returns whether or not an asset can be compressed.
def can_compress? # The "charset" of a mime type is present if the value is # encoded text. We can check this value to see if the asset # can be compressed. # # We also check against our list of non-text compressible mime types @charset || COMPRESSABLE_MIME_TYPES.include?(@content_type) end
def cannot_compress?
Private: Opposite of `can_compress?`.
def cannot_compress? !can_compress? end
def compress(file, target)
Does not modify the target asset.
the same name plus a `.gz` extension in the same folder as the original.
Compresses the target asset's contents and puts it into a file with
Private: Generates a gzipped file based off of reference asset.
def compress(file, target) mtime = Sprockets::PathUtils.stat(target).mtime archiver.call(file, source, mtime) nil end
def initialize(asset, archiver: ZlibArchiver)
def initialize(asset, archiver: ZlibArchiver) @content_type = asset.content_type @source = asset.source @charset = asset.charset @archiver = archiver end