Class: SwfUtil::SWFCompressor
Instance Method Summary
collapse
#is_compressed?, #read_full_size, #strip_header
Constructor Details
#initialize(from = nil, to = nil) ⇒ SWFCompressor
5
6
7
|
# File 'lib/swfheader/swf-compressor.rb', line 5
def initialize(from=nil,to=nil)
read_file(from,to) if !from.nil? and !to.nil?
end
|
Instance Method Details
#compress(buffer) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/swfheader/swf-compressor.rb', line 18
def compress(buffer)
compressor=Zlib::Deflate.new
data=compressor.deflate((buffer),Zlib::FINISH)
data=buffer[0,8]+data
data[0]=?C
data
end
|
#read_file(file, to) ⇒ Object
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/swfheader/swf-compressor.rb', line 8
def read_file(file,to)
buff=File.open(file,"rb") do |fin|
fin.read
end
raise RuntimeError.new,"The file have already been compressed",caller if is_compressed?(buff[0])
result=compress(buff)
File.open(to,"wb") do |fout|
fout.write(result)
end
end
|