Class: Lemans::Environments::Daytona::FaradayTransfer::UploadIO

Inherits:
Object
  • Object
show all
Defined in:
lib/lemans/environments/daytona/faraday_transfer.rb

Overview

Counts bytes as multipart-post drains the file and surfaces cancellation as an exception, which tears the connection down.

Instance Method Summary collapse

Constructor Details

#initialize(io, remote_path, on_progress:, cancel_event:) ⇒ UploadIO

Returns a new instance of UploadIO.



35
36
37
38
39
40
41
# File 'lib/lemans/environments/daytona/faraday_transfer.rb', line 35

def initialize(io, remote_path, on_progress:, cancel_event:)
  @io = io
  @remote_path = remote_path
  @on_progress = on_progress
  @cancel_event = cancel_event
  @bytes_sent = 0
end

Instance Method Details

#closeObject



58
# File 'lib/lemans/environments/daytona/faraday_transfer.rb', line 58

def close = @io.close

#eof?Boolean

Returns:

  • (Boolean)


57
# File 'lib/lemans/environments/daytona/faraday_transfer.rb', line 57

def eof? = @io.eof?

#lengthObject



55
# File 'lib/lemans/environments/daytona/faraday_transfer.rb', line 55

def length = @io.size

#readObject

Raises:

  • (::Daytona::Sdk::Error)


43
44
45
46
47
48
49
50
51
52
# File 'lib/lemans/environments/daytona/faraday_transfer.rb', line 43

def read(...)
  raise ::Daytona::Sdk::Error, "Upload cancelled: #{@remote_path}" if @cancel_event&.set?

  chunk = @io.read(...)
  if chunk && @on_progress
    @bytes_sent += chunk.bytesize
    @on_progress.call(::Daytona::UploadProgress.new(bytes_sent: @bytes_sent))
  end
  chunk
end

#rewindObject



56
# File 'lib/lemans/environments/daytona/faraday_transfer.rb', line 56

def rewind = @io.rewind

#sizeObject



54
# File 'lib/lemans/environments/daytona/faraday_transfer.rb', line 54

def size = @io.size