Class: Zip::StreamableStream
- Defined in:
- lib/zip/streamable_stream.rb
Overview
:nodoc:all
Constant Summary
Constants inherited from Entry
Entry::COMPRESSION_LEVEL_FAST_GPFLAG, Entry::COMPRESSION_LEVEL_MAX_GPFLAG, Entry::COMPRESSION_LEVEL_SUPERFAST_GPFLAG, Entry::DEFLATED, Entry::EFS, Entry::STORED
Instance Attribute Summary
Attributes inherited from Entry
#comment, #compressed_size, #compression_level, #crc, #external_file_attributes, #extra, #filepath, #follow_symlinks, #fstype, #gp_flags, #internal_file_attributes, #local_header_offset, #name, #restore_ownership, #restore_permissions, #restore_times, #size, #unix_gid, #unix_perms, #unix_uid
Instance Method Summary collapse
- #clean_up ⇒ Object
- #get_input_stream ⇒ Object
- #get_output_stream ⇒ Object
-
#initialize(entry) ⇒ StreamableStream
constructor
A new instance of StreamableStream.
- #write_to_zip_output_stream(output_stream) ⇒ Object
Methods inherited from Entry
#<=>, #==, #absolute_time?, #atime, #atime=, #calculate_local_header_size, #cdir_header_size, #check_c_dir_entry_comment_size, #check_c_dir_entry_signature, #check_c_dir_entry_static_header_length, #check_name, #comment_size, #compression_method, #compression_method=, #ctime, #ctime=, #encrypted?, #extra_size, #extract, #file_stat, #file_type_is?, #ftype, #gather_fileinfo_from_srcpath, #get_extra_attributes_from_path, #get_raw_input_stream, #incomplete?, #local_entry_offset, #name_is_directory?, #name_safe?, #name_size, #next_header_offset, #pack_c_dir_entry, #pack_local_entry, #parent_as_string, #read_c_dir_entry, read_c_dir_entry, #read_extra_field, read_local_entry, #read_local_entry, #set_default_vars_values, #set_extra_attributes_on_path, #set_ftype_from_c_dir_entry, #set_unix_attributes_on_path, #time, #time=, #to_s, #unpack_c_dir_entry, #unpack_local_entry, #verify_local_header_size!, #write_c_dir_entry, #write_local_entry, #zip64?
Methods included from Dirtyable
Constructor Details
#initialize(entry) ⇒ StreamableStream
Returns a new instance of StreamableStream.
5 6 7 8 9 |
# File 'lib/zip/streamable_stream.rb', line 5 def initialize(entry) super(entry) @temp_file = Tempfile.new(::File.basename(name)) @temp_file.binmode end |
Instance Method Details
#clean_up ⇒ Object
46 47 48 49 |
# File 'lib/zip/streamable_stream.rb', line 46 def clean_up super @temp_file.unlink end |
#get_input_stream ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/zip/streamable_stream.rb', line 23 def get_input_stream unless @temp_file.closed? raise StandardError, "cannot open entry for reading while its open for writing - #{name}" end @temp_file.open # reopens tempfile from top @temp_file.binmode if block_given? begin yield(@temp_file) ensure @temp_file.close end else @temp_file end end |
#get_output_stream ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/zip/streamable_stream.rb', line 11 def get_output_stream if block_given? begin yield(@temp_file) ensure @temp_file.close end else @temp_file end end |
#write_to_zip_output_stream(output_stream) ⇒ Object
41 42 43 44 |
# File 'lib/zip/streamable_stream.rb', line 41 def write_to_zip_output_stream(output_stream) output_stream.put_next_entry(self) get_input_stream { |is| ::Zip::IOExtras.copy_stream(output_stream, is) } end |