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



51
52
53
# File 'lib/zipline/output_stream.rb', line 51

def current_entry
  @currentEntry || @current_entry
end

#finalize_current_entryObject

just reset state, no rewinding required



33
34
35
36
37
38
39
# File 'lib/zipline/output_stream.rb', line 33

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
27
28
29
30
# File 'lib/zipline/output_stream.rb', line 18

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

  #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)

  # Uncompressed size in the local file header must be zero when bit 3
  # of the general purpose flags is set, so set the size after the header
  # has been written.
  new_entry.size = size
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



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

def update_local_headers
  nil
end


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

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