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.



1289
1290
1291
1292
1293
# File 'lib/zip/zip.rb', line 1289

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

Instance Method Details

#get_input_streamObject



1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
# File 'lib/zip/zip.rb', line 1307

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



1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
# File 'lib/zip/zip.rb', line 1295

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



1323
1324
1325
1326
# File 'lib/zip/zip.rb', line 1323

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