class T2Server::OutputPort
Represents an output port of a workflow.
Public Instance Methods
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
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
Is there an error associated with this output port?
# File lib/t2-server/port.rb, line 183 def error? @error end
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 288 def reference @refs ||= strip(:reference) end
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 312 def size @sizes ||= strip(:size) end
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 253 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 @structure.stream_value(stream, range) end
Return the total data size of all the data in this output port.
# File lib/t2-server/port.rb, line 320 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
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 300 def type @types ||= strip(:type) end
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 @structure.value(range, &block) else @values ||= strip(:value) end end
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 273 def write_value_to_file(filename, range = nil) return 0 unless depth == 0 @structure.write_value_to_file(filename, range) end
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 358 def zip(param = nil, &block) return nil if depth == 0 @run.zip_output(param, name, &block) end