def data_stream_from options, &block
validate_data!(options, block)
if block_given?
buffer = StringIO.new
yield(buffer)
buffer.rewind
return buffer
end
data = options[:data]
file_opts = ["rb"]
file_opts << { :encoding => "BINARY" } if Object.const_defined?(:Encoding)
case
when data.is_a?(String)
data.force_encoding("BINARY") if data.respond_to?(:force_encoding)
StringIO.new(data)
when data.is_a?(Pathname) then File.open(data.to_s, *file_opts)
when options[:file] then File.open(options[:file], *file_opts)
else data
end
end