lib/aws/s3/s3_object.rb in aws-sdk-1.0.2 vs lib/aws/s3/s3_object.rb in aws-sdk-1.0.3

- old
+ new

@@ -72,10 +72,18 @@ other.kind_of?(S3Object) and other.bucket == bucket and other.key == key end alias_method :eql?, :== + def exists? + head + rescue Errors::NoSuchKey => e + false + else + true + end + # Performs a HEAD request against this object and returns an object # with useful information about the object, including: # # * metadata (hash of user-supplied key-value pairs) # * content_length (integer, number of bytes) @@ -101,10 +109,17 @@ # @return [String] Returns the object's ETag def etag head.etag end + # Returns the object's last modified time. + # + # @return [Time] Returns the object's last modified time. + def last_modified + head.last_modified + end + # @return [Integer] Size of the object in bytes. def content_length head.content_length end @@ -486,17 +501,27 @@ # #=> 'some data' # # @param [Hash] options # @option options [String] :version_id Reads data from a # specific version of this object. - # @option options [Time] :if_unmodified_since Causes #read - # to return nil if the object was modified since the - # given time. - # @option options [Time] :if_modified_since Causes #read - # to return nil unless the object was modified since the - # given time. - # @option options [String] :if_match If specified, the method - # will return nil (and not fetch any data) unless the object ETag + # + # @option options [Time] :if_unmodified_since If specified, the + # method will raise + # <tt>AWS::S3::Errors::PreconditionFailed</tt> unless the + # object has not been modified since the given time. + # + # @option options [Time] :if_modified_since If specified, the + # method will raise <tt>AWS::S3::Errors::NotModified</tt> if + # the object has not been modified since the given time. + # + # @option options [String] :if_match If specified, the method + # will raise <tt>AWS::S3::Errors::PreconditionFailed</tt> + # unless the object ETag matches the provided value. + # + # @option options [String] :if_none_match If specified, the + # method will raise <tt>AWS::S3::Errors::NotModified</tt> if + # the object ETag matches the provided value. + # # @option options [Range] :range A byte range to read data from def read(options = {}, &blk) options[:bucket_name] = bucket.name options[:key] = key client.get_object(options).data