Module: Coursemology::Evaluator::Utils

Defined in:
lib/coursemology/evaluator/utils.rb

Defined Under Namespace

Classes: DockerAttachBlock

Class Method Summary collapse

Class Method Details

.parse_docker_stream(string) ⇒ Array<(String, String, String)>

Parses a Docker attach protocol stream into its constituent protocols.

See docs.docker.com/engine/reference/api/docker_remote_api_v1.19/#attach-to-a-container.

This drops all blocks belonging to streams other than STDIN, STDOUT, or STDERR.

Parameters:

  • string (String)

    The input stream to parse.

Returns:

  • (Array<(String, String, String)>)

    The stdin, stdout, and stderr output.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/coursemology/evaluator/utils.rb', line 14

def self.parse_docker_stream(string)
  result = [''.dup, ''.dup, ''.dup]
  stream = StringIO.new(string)

  while (block = parse_docker_stream_read_block(stream))
    next if block.stream >= result.length
    result[block.stream] << block.bytes
  end

  stream.close
  result
end