Class: Zip::ZipStreamableStream

Inherits:
ZipEntry show all
Defined in:
lib/zip/zip.rb

Overview

nodoc:all

Constant Summary

Constants inherited from ZipEntry

Zip::ZipEntry::CDIR_ENTRY_STATIC_HEADER_LENGTH, Zip::ZipEntry::CENTRAL_DIRECTORY_ENTRY_SIGNATURE, Zip::ZipEntry::DEFLATED, Zip::ZipEntry::LOCAL_ENTRY_SIGNATURE, Zip::ZipEntry::LOCAL_ENTRY_STATIC_HEADER_LENGTH, Zip::ZipEntry::STORED

Instance Attribute Summary

Attributes inherited from ZipEntry

#comment, #compressed_size, #compression_method, #crc, #externalFileAttributes, #extra, #fstype, #localHeaderOffset, #name, #size, #zipfile

Instance Method Summary collapse

Methods inherited from ZipEntry

#<=>, #==, #cdir_header_size, #directory?, #file?, #get_raw_input_stream, #local_entry_offset, #local_header_size, #next_header_offset, #parent_as_string, read_c_dir_entry, #read_c_dir_entry, read_local_entry, #read_local_entry, #time, #time=, #to_s, #write_c_dir_entry, #write_local_entry

Constructor Details

#initialize(entry) ⇒ ZipStreamableStream

Returns a new instance of ZipStreamableStream.



1124
1125
1126
1127
1128
# File 'lib/zip/zip.rb', line 1124

def initialize(entry)
  super(entry)
  @tempFile = Tempfile.new(File.basename(name), File.dirname(zipfile))
  @tempFile.binmode
end

Instance Method Details

#get_input_streamObject



1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
# File 'lib/zip/zip.rb', line 1142

def get_input_stream
  if ! @tempFile.closed?
    raise StandardError, "cannot open entry for reading while its open for writing - #{name}"
  end
  @tempFile.open # reopens tempfile from top
  if block_given?
    begin
      yield(@tempFile)
    ensure
      @tempFile.close
    end
  else
    @tempFile
  end
end

#get_output_streamObject



1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
# File 'lib/zip/zip.rb', line 1130

def get_output_stream
  if block_given?
    begin
      yield(@tempFile)
    ensure
      @tempFile.close
    end
  else
    @tempFile
  end
end

#write_to_zip_output_stream(aZipOutputStream) ⇒ Object



1158
1159
1160
1161
# File 'lib/zip/zip.rb', line 1158

def write_to_zip_output_stream(aZipOutputStream)
  aZipOutputStream.put_next_entry(self)
  aZipOutputStream << get_input_stream { |is| is.read }
end