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



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

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)


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

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)


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

def last_byte
  @last_byte
end

#offsetInteger (readonly)

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

Returns:

  • (Integer)


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

def offset
  @offset
end

#part_sizeInteger (readonly)

The number of bytes to read from the file

Returns:

  • (Integer)


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

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)


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

def source
  @source
end

Instance Method Details

#closeObject



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

def close
  @file_handle.close if @file_handle
end

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



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

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

#rewindObject



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

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

#sizeObject



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

def size
  @part_size
end

#write(_content) ⇒ Object



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

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