Class: Nanite::FileStreaming::FileState
- Defined in:
- lib/nanite/streaming.rb
Overview
FileState represents a file download in progress. It incapsulates the following information:
-
unique operation token
-
domain (namespace for file streaming operations)
-
file IO chunks are written to on receiver’s side
Instance Method Summary collapse
- #handle_packet(packet) ⇒ Object
-
#initialize(token, dest, domain, write, blk) ⇒ FileState
constructor
A new instance of FileState.
Constructor Details
#initialize(token, dest, domain, write, blk) ⇒ FileState
Returns a new instance of FileState.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/nanite/streaming.rb', line 73 def initialize(token, dest, domain, write, blk) @token = token @cb = blk @domain = domain @write = write if write @filename = File.join(Nanite.agent.file_root, dest) @dest = File.open(@filename, 'wb') else @dest = dest end @data = "" end |
Instance Method Details
#handle_packet(packet) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/nanite/streaming.rb', line 89 def handle_packet(packet) case packet when Nanite::FileChunk log.debug "written chunk to #{@dest.inspect}" @data << packet.chunk if @write @dest.write(packet.chunk) end when Nanite::FileEnd log.debug "#{@dest.inspect} receiving is completed" if @write @dest.close end @cb.call(@data, @dest, packet.) end end |