Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not gzip assets that are already gzipped #57

Merged
merged 1 commit into from
Jun 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/sprockets/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ def stale?(environment)
# Save asset to disk.
def write_to(filename, options = {})
# Gzip contents if filename has '.gz'
options[:compress] ||= File.extname(filename) == '.gz'
unless options.key?(:compress)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way I think there was a bug here. You couldn't pass compress: false

options[:compress] = File.extname(filename) == '.gz' && File.extname(logical_path) != '.gz'
end

FileUtils.mkdir_p File.dirname(filename)

Expand Down
4 changes: 3 additions & 1 deletion lib/sprockets/static_asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def to_path
# Save asset to disk.
def write_to(filename, options = {})
# Gzip contents if filename has '.gz'
options[:compress] ||= File.extname(filename) == '.gz'
unless options.key?(:compress)
options[:compress] = File.extname(filename) == '.gz' && File.extname(logical_path) != '.gz'
end

FileUtils.mkdir_p File.dirname(filename)

Expand Down
Binary file added test/fixtures/asset/archive.tar.gz
Binary file not shown.
13 changes: 13 additions & 0 deletions test/test_asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ def self.test(name, &block)
assert !File.exist?(target)
end
end

test "do not gzip assets that are already gzipped" do
@asset = @env.find_asset('archive.tar.gz')
target = fixture_path('asset/tmp.tar.gz')
begin
@asset.write_to(target)
assert File.exist?(target)
assert_equal Digest::MD5.hexdigest(@asset.to_s), Digest::MD5.hexdigest(File.read(target))
ensure
FileUtils.rm(target) if File.exist?(target)
assert !File.exist?(target)
end
end
end

module FreshnessTests
Expand Down