Class: Pantry::Communication::FileService::SendingFile

Inherits:
UploadInfo
  • Object
show all
Defined in:
lib/pantry/communication/file_service/file_progress.rb

Overview

Sending-side version of UploadInfo

Instance Attribute Summary collapse

Attributes inherited from UploadInfo

#file_uuid, #receiver_uuid

Instance Method Summary collapse

Methods inherited from UploadInfo

#wait_for_finish

Constructor Details

#initialize(file_path, receiver_uuid, file_uuid) ⇒ SendingFile

Returns a new instance of SendingFile.



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pantry/communication/file_service/file_progress.rb', line 34

def initialize(file_path, receiver_uuid, file_uuid)
  super()
  @path = file_path
  @file_uuid = file_uuid
  @file = File.open(@path, "r")

  @receiver_uuid = receiver_uuid

  @file_size = @file.size
  @total_bytes_sent = 0

  Pantry.ui.progress_start(@file_size)
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



32
33
34
# File 'lib/pantry/communication/file_service/file_progress.rb', line 32

def file
  @file
end

#pathObject (readonly)

Returns the value of attribute path.



32
33
34
# File 'lib/pantry/communication/file_service/file_progress.rb', line 32

def path
  @path
end

Instance Method Details

#finished!Object



56
57
58
59
60
61
# File 'lib/pantry/communication/file_service/file_progress.rb', line 56

def finished!
  Pantry.ui.progress_finish

  @file.close
  super
end

#finished?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/pantry/communication/file_service/file_progress.rb', line 63

def finished?
  @total_bytes_sent == @file_size || @file.closed?
end

#read(offset, bytes_to_read) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/pantry/communication/file_service/file_progress.rb', line 48

def read(offset, bytes_to_read)
  @total_bytes_sent += bytes_to_read
  Pantry.ui.progress_step(bytes_to_read)

  @file.seek(offset)
  @file.read(bytes_to_read)
end