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.
13 14 15 16 |
# File 'lib/ftpd/stream.rb', line 13 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.
8 9 10 |
# File 'lib/ftpd/stream.rb', line 8 def byte_count @byte_count end |
#data_type ⇒ Object (readonly)
Returns the value of attribute data_type.
7 8 9 |
# File 'lib/ftpd/stream.rb', line 7 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
22 23 24 25 26 27 28 |
# File 'lib/ftpd/stream.rb', line 22 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
35 36 37 38 39 40 41 42 |
# File 'lib/ftpd/stream.rb', line 35 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 |