Class: OCI::ObjectStorage::Transfer::Multipart::Internal::FilePartIOWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/oci/object_storage/transfer/multipart/internal/file_part_io_wrapper.rb

Overview

An IO-like interface over a part of a file which will participate in a multipart upload. This allows us to upload a given segment of the file as an “upload part” of a multipart upload.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, offset:, part_size:) ⇒ FilePartIOWrapper

Creates a new FilePartIOWrapper

Parameters:

  • source (String, File, Tempfile)

    The source file, or a path to it

  • offset (Integer)

    The zero-based position in the file to start reading from

  • part_size (Integer)

    The number of bytes to read from the file



37
38
39
40
41
42
43
44
45
46
# File 'lib/oci/object_storage/transfer/multipart/internal/file_part_io_wrapper.rb', line 37

def initialize(source:, offset:, part_size:)
  @source = source
  @offset = offset
  @part_size = part_size

  @first_byte = offset
  @last_byte = offset + part_size

  @file_handle = nil
end

Instance Attribute Details

#first_byteInteger (readonly)

The position of the first byte to start reading from. Synonym for offset

Returns:

  • (Integer)


26
27
28
# File 'lib/oci/object_storage/transfer/multipart/internal/file_part_io_wrapper.rb', line 26

def first_byte
  @first_byte
end

#last_byteInteger (readonly)

The position of the last byte we'll read to (exclusive). Calculated as offset + part_size

Returns:

  • (Integer)


30
31
32
# File 'lib/oci/object_storage/transfer/multipart/internal/file_part_io_wrapper.rb', line 30

def last_byte
  @last_byte
end

#offsetInteger (readonly)

The zero-based position in the file to start reading from

Returns:

  • (Integer)


18
19
20
# File 'lib/oci/object_storage/transfer/multipart/internal/file_part_io_wrapper.rb', line 18

def offset
  @offset
end

#part_sizeInteger (readonly)

The number of bytes to read from the file

Returns:

  • (Integer)


22
23
24
# File 'lib/oci/object_storage/transfer/multipart/internal/file_part_io_wrapper.rb', line 22

def part_size
  @part_size
end

#sourceString, ... (readonly)

The source file, identified by either a File/Tempfile object or a path to the file

Returns:

  • (String, File, Tempfile)


14
15
16
# File 'lib/oci/object_storage/transfer/multipart/internal/file_part_io_wrapper.rb', line 14

def source
  @source
end

Instance Method Details

#closeObject



48
49
50
# File 'lib/oci/object_storage/transfer/multipart/internal/file_part_io_wrapper.rb', line 48

def close
  @file_handle.close if @file_handle
end

#read(bytes = nil, output_buffer = nil) ⇒ Object



52
53
54
55
# File 'lib/oci/object_storage/transfer/multipart/internal/file_part_io_wrapper.rb', line 52

def read(bytes = nil, output_buffer = nil)
  open_file unless @file_handle
  read_internal(bytes, output_buffer)
end

#rewindObject



65
66
67
68
69
70
71
# File 'lib/oci/object_storage/transfer/multipart/internal/file_part_io_wrapper.rb', line 65

def rewind
  if @file_handle
    @file_handle.seek(@first_byte)
    @position = @first_byte
  end
  0
end

#sizeObject



61
62
63
# File 'lib/oci/object_storage/transfer/multipart/internal/file_part_io_wrapper.rb', line 61

def size
  @part_size
end

#write(_content) ⇒ Object



57
58
59
# File 'lib/oci/object_storage/transfer/multipart/internal/file_part_io_wrapper.rb', line 57

def write(_content)
  raise 'FilePartIOWrapper does not support writing'
end