Class: Zipline::OutputStream

Inherits:
Zip::OutputStream
  • Object
show all
Defined in:
lib/zipline/output_stream.rb

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ OutputStream

we need to be able to hand out own custom output in order to stream to browser



7
8
9
10
11
12
# File 'lib/zipline/output_stream.rb', line 7

def initialize(io)
  # Create an io stream thing
  super StringIO.new, true
  # Overwrite it with my own
  @output_stream = io
end

Instance Method Details

#current_entryObject

helper to deal with difference between rubyzip 1.0 and 1.1



47
48
49
# File 'lib/zipline/output_stream.rb', line 47

def current_entry
  @currentEntry || @current_entry
end

#finalize_current_entryObject

just reset state, no rewinding required



29
30
31
32
33
34
35
# File 'lib/zipline/output_stream.rb', line 29

def finalize_current_entry
  if current_entry
    entry = current_entry
    super
    write_local_footer(entry)
  end
end

#put_next_entry(entry_name, size) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/zipline/output_stream.rb', line 18

def put_next_entry(entry_name, size)
  new_entry = Zip::Entry.new(@file_name, entry_name)
  new_entry.size = size

  #THIS IS THE MAGIC, tells zip to look after data for size, crc
  new_entry.gp_flags = new_entry.gp_flags | 0x0008

  super(new_entry)
end

#streamObject



14
15
16
# File 'lib/zipline/output_stream.rb', line 14

def stream
  @output_stream
end

#update_local_headersObject

never need to do this because we set correct sizes up front



42
43
44
# File 'lib/zipline/output_stream.rb', line 42

def update_local_headers
  nil
end


37
38
39
# File 'lib/zipline/output_stream.rb', line 37

def write_local_footer(entry)
  @output_stream << [ 0x08074b50, entry.crc, entry.compressed_size, entry.size].pack('VVVV')
end