Class: Furnace::SWF::File

Inherits:
BinData::Record
  • Object
show all
Defined in:
lib/furnace-swf/swf/file.rb

Instance Method Summary collapse

Instance Method Details

#do_read(io) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/furnace-swf/swf/file.rb', line 8

def do_read(io)
  instantiate_all_objs

  header = find_obj_for_name(:header)
  stream = find_obj_for_name(:stream)

  header.do_read(io)

  case header.signature.to_s
  when 'FWS'
    stream.do_read io
  when 'CWS'
    uncompressed = Zlib::Inflate.inflate(io.read_all_bytes)
    stream.do_read BinData::IO.new(StringIO.new(uncompressed))
  else
    raise ArgumentError, "invalid signature"
  end
end

#do_write(io) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/furnace-swf/swf/file.rb', line 27

def do_write(io)
  instantiate_all_objs

  header = find_obj_for_name(:header)
  stream = find_obj_for_name(:stream)

  header.signature   = 'FWS'
  header.file_length = header.num_bytes + stream.real_num_bytes

  header.do_write(io)
  stream.do_write(io)
end