Duck typing for input object. Also fix NoMethodError for #type.

There're many objects which are IO-like and respond_to :read. Also there's no #type method for any object.