Class: Ftpd::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/ftpd/stream.rb

Constant Summary collapse

CHUNK_SIZE =

100kb

1024 * 100

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, data_type) ⇒ Stream

Returns a new instance of Stream.

Parameters:

  • io (IO)

    The stream to read from or write to

  • data_type (String)

    The FTP data type of the 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_countObject (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_typeObject (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

#readString, NilClass

Read and convert a chunk of up to CHUNK_SIZE from the stream

Returns:

  • (String)

    if any bytes remain to read from the stream

  • (NilClass)

    if no bytes remain



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

Parameters:

  • io (IO)

    The data to be written to the stream



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