Method: VirtFS::VIO.copy_stream

Defined in:
lib/virtfs/v_io.rb

.copy_stream(from, to, max_length = nil, offset = 0) ⇒ Object

Copy stream from source to destination

Parameters:

  • from (String)

    file stream to copy

  • to (String)

    file stream to copy to

  • max_length (Integer) (defaults to: nil)

    max number of bytes to copy

  • offset (Integer) (defaults to: 0)

    position to start coying from



72
73
74
75
76
77
78
79
# File 'lib/virtfs/v_io.rb', line 72

def copy_stream(from, to, max_length = nil, offset = 0) # rubocop:disable CyclomaticComplexity
  from_file = from.is_a?(VIO) ? from : VFile.open(from, "rb")
  to_file   = to.is_a?(VIO)   ? to   : VFile.open(to, "wb") # rubocop:disable SpaceAroundOperators
  return copy_from_to(from_file, to_file, max_length, offset)
ensure
  from_file.close unless from_file.nil? || from.is_a?(VIO)
  to_file.close   unless to_file.nil?   || to.is_a?(VIO)    # rubocop:disable SpaceAroundOperators
end