class T2Server::OutputPort

Represents an output port of a workflow.

Public Instance Methods

[int] → obj click to toggle source

This call provides access to the underlying structure of the OutputPort. It can only be used for ports of depth >= 1. For singleton ports, use #value instead.

Example usage - To get part of a value from an output port with depth 3: port[0].value(10…100)

# File lib/t2-server/port.rb, line 211
def [](i)
  return @structure if depth == 0
  @structure[i]
end
empty? → true or false click to toggle source

Is this output port empty?

Note that if the output port holds a list then it is not considered empty, even if that list is empty. This is because the port itself is not empty, there is a list there! A separate test should be performed to see if that list is empty or not.

# File lib/t2-server/port.rb, line 196
def empty?
  # Funnily enough, an empty list does *not* make a port empty!
  return false if @structure.instance_of? Array
  @structure.empty?
end
error? → true or false click to toggle source

Is there an error associated with this output port?

# File lib/t2-server/port.rb, line 183
def error?
  @error
end
reference → string click to toggle source
reference → array

Get URI references to the data values of this output port as strings.

For a singleton output a single uri is returned. For lists an array of uris is returned. For an individual reference from a list use ‘port[].reference’.

# File lib/t2-server/port.rb, line 301
def reference
  @refs ||= strip(:reference)
end
size → fixnum click to toggle source
size → array

Get the data size of the data value in this output port.

For a singleton output a single size is returned. For lists an array of sizes is returned. For an individual size from a list use ‘port[].size’.

# File lib/t2-server/port.rb, line 325
def size
  @sizes ||= strip(:size)
end
stream_value(stream) → fixnum click to toggle source
stream_value(stream, range) → fixnum

Stream a singleton port value directly to another stream and return the number of bytes written. If a range is supplied then only that range of data is streamed from the server. The stream passed in may be anything that provides a write method; instances of IO and File, for example. No data is cached by this method.

To stream parts of a list port, use T2Server::PortValue#stream_value on the list item directly:

run.output_port("port_name")[0].stream_value(stream)
# File lib/t2-server/port.rb, line 258
def stream_value(stream, range = nil)
  return 0 unless depth == 0
  raise ArgumentError,
    "Stream passed in must provide a write method" unless
      stream.respond_to? :write

  if range.nil?
    @structure.stream_value(stream)
  else
    @structure.stream_value(stream, range)
  end
end
total_size → fixnum click to toggle source

Return the total data size of all the data in this output port.

# File lib/t2-server/port.rb, line 333
def total_size
  return @total_size if @total_size
  if @structure.instance_of? Array
    return 0 if @structure.empty?
    @total_size = strip(:size).flatten.inject { |sum, i| sum + i }
  else
    @total_size = size
  end
end
type → string click to toggle source
type → array

Get the mime type of the data value in this output port.

For a singleton output a single type is returned. For lists an array of types is returned. For an individual type from a list use ‘port[].type’.

# File lib/t2-server/port.rb, line 313
def type
  @types ||= strip(:type)
end
value → binary blob click to toggle source
value(range) → binary blob
value {|chunk| ...}
value(range) {|chunk| ...}
value → array

For singleton outputs download or stream the data (or part of it) held by the output port. Please see the documentation for T2Server::PortValue#value for full details.

For list outputs all data values are downloaded into memory and returned in an Array structure that mirrors the structure of the output port. Do not use this form if the output port has large amounts of data! To get part of a value from a list use something like:

run.output_port("port_name")[0].value(0..100)
# File lib/t2-server/port.rb, line 232
def value(range = nil, &block)
  if depth == 0
    if range.nil?
      @structure.value(&block)
    else
      @structure.value(range, &block)
    end
  else
    @values = strip(:value) if @values.nil?
    @values
  end
end
write_value_to_file(filename) → fixnum click to toggle source
write_value_to_file(filename, range) → fixnum

Stream a singleton port value to a file and return the number of bytes written. If a range is supplied then only that range of data is downloaded from the server.

To save parts of a list port to a file, use T2Server::PortValue#write_value_to_file on the list item directly:

run.output_port("port_name")[0].write_value_to_file
# File lib/t2-server/port.rb, line 282
def write_value_to_file(filename, range = nil)
  return 0 unless depth == 0

  if range.nil?
    @structure.write_value_to_file(filename)
  else
    @structure.write_value_to_file(filename, range)
  end
end
zip → binary blob click to toggle source
zip(filename) → fixnum
zip(stream) → fixnum
zip {|chunk| ...}

Get the data in this output port directly from the server in zip format.

This method does not work with singleton ports. Taverna Server cannot currently return zip files of singleton ports on their own. If you wish to get a singleton port in a zip file then you can use T2Server::Run#zip_output which will return all outputs in a single file.

If this method is called on a singleton port it will return nil and streaming from it will return nothing.

Calling this method with no parameters will simply return a blob of zipped data. Providing a filename will stream the data directly to that file and return the number of bytes written. Passing in an object that has a write method (for example, an instance of File or IO) will stream the zip data directly to that object and return the number of bytes that were streamed. Passing in a block will allow access to the underlying data stream:

port.zip do |chunk|
  print chunk
end

Raises RunStateError if the run has not finished running.

# File lib/t2-server/port.rb, line 371
def zip(param = nil, &block)
  return nil if depth == 0
  @run.zip_output(param, name, &block)
end