Class: Ftpd::Stream
- Inherits:
-
Object
- Object
- Ftpd::Stream
- Defined in:
- lib/ftpd/stream.rb
Constant Summary collapse
- CHUNK_SIZE =
100kb
1024 * 100
Instance Attribute Summary collapse
-
#byte_count ⇒ Object
readonly
Returns the value of attribute byte_count.
-
#data_type ⇒ Object
readonly
Returns the value of attribute data_type.
Instance Method Summary collapse
-
#initialize(io, data_type) ⇒ Stream
constructor
A new instance of Stream.
-
#read ⇒ String, NilClass
Read and convert a chunk of up to CHUNK_SIZE from the stream.
-
#write(io) ⇒ Object
Convert and write a chunk of up to CHUNK_SIZE to the stream from the provided IO object.
Constructor Details
#initialize(io, data_type) ⇒ Stream
Returns a new instance of Stream.
15 16 17 18 |
# File 'lib/ftpd/stream.rb', line 15 def initialize(io, data_type) @io, @data_type = io, data_type @byte_count = 0 end |
Instance Attribute Details
#byte_count ⇒ Object (readonly)
Returns the value of attribute byte_count.
10 11 12 |
# File 'lib/ftpd/stream.rb', line 10 def byte_count @byte_count end |
#data_type ⇒ Object (readonly)
Returns the value of attribute data_type.
9 10 11 |
# File 'lib/ftpd/stream.rb', line 9 def data_type @data_type end |
Instance Method Details
#read ⇒ String, NilClass
Read and convert a chunk of up to CHUNK_SIZE from the stream
24 25 26 27 28 29 30 |
# File 'lib/ftpd/stream.rb', line 24 def read chunk = converted_chunk(@io) return unless chunk chunk = nvt_ascii_to_unix(chunk) if data_type == 'A' record_bytes(chunk) chunk end |
#write(io) ⇒ Object
Convert and write a chunk of up to CHUNK_SIZE to the stream from the provided IO object
37 38 39 40 41 42 43 44 |
# File 'lib/ftpd/stream.rb', line 37 def write(io) while chunk = converted_chunk(io) chunk = unix_to_nvt_ascii(chunk) if data_type == 'A' result = @io.write(chunk) record_bytes(chunk) result end end |