Class: Propshaft::Compressor::Writer
- Inherits:
-
Object
- Object
- Propshaft::Compressor::Writer
show all
- Defined in:
- lib/propshaft/compressor/writer.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(from:, to:, level: 8) ⇒ Writer
Returns a new instance of Writer.
21
22
23
24
25
|
# File 'lib/propshaft/compressor/writer.rb', line 21
def initialize(from:, to:, level: 8)
@from = from
@to = to
@level = level
end
|
Class Method Details
.compress ⇒ Object
17
18
19
|
# File 'lib/propshaft/compressor/writer.rb', line 17
def self.compress(...)
new(...).compress
end
|
Instance Method Details
#build_writer(io) ⇒ Object
41
42
43
|
# File 'lib/propshaft/compressor/writer.rb', line 41
def build_writer(io)
raise 'abstract'
end
|
#compress ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/propshaft/compressor/writer.rb', line 27
def compress
File.open(@from, 'rb') do |from_io|
File.open(@to, 'wb+') do |to_io|
writer = build_writer to_io, from_io.mtime
from_io.each do |blk|
writer.write blk
end
ensure
writer&.close
end
File.utime from_io.atime, from_io.mtime, @to
end
end
|