lib/s3/right_s3_interface.rb
# Incrementally list the contents of a bucket. Yields the following hash to a block:
#  s3.incrementally_list_bucket('my_awesome_bucket', { 'prefix'=>'t', 'marker'=>'', 'max-keys'=>5, delimiter=>'' }) yields  
#   {
#     :name => 'bucketname',
#     :prefix => 'subfolder/',
#     :marker => 'fileN.jpg',
#     :max_keys => 234,
#     :delimiter => '/',
#     :is_truncated => true,
#     :next_marker => 'fileX.jpg',
#     :contents => [
#       { :key => "file1",
#         :last_modified => "2007-05-18T07:00:59.000Z",
#         :e_tag => "000000000059075b964b07152d234b70",
#         :size => 3,
#         :storage_class => "STANDARD",
#         :owner_id => "00000000009314cc309ffe736daa2b264357476c7fea6efb2c3347ac3ab2792a",
#         :owner_display_name => "root"
#       }, { :key, ...}, ... {:key, ...}
#     ]
#     :common_prefixes => [
#       "prefix1",
#       "prefix2",
#       ...,
#       "prefixN"
#     ]
#   }
Incrementally list the contents of a bucket.
Incrementally list the contents of a bucket .
def incrementally_list_bucket(bucket, options={}, headers={}, &block)
      internal_options = options.right_symbolize_keys
      begin 
        internal_bucket = bucket.dup
        internal_bucket  += '?'+internal_options.map{|k, v| "#{k.to_s}=#{CGI::escape v.to_s}"}.join('&') unless internal_options.right_blank?
        req_hash = generate_rest_request('GET', headers.merge(:url=>internal_bucket))
        response = request_info(req_hash, S3ImprovedListBucketParser.new(:logger => @logger))
        there_are_more_keys = response[:is_truncated]
        if(there_are_more_keys)
          internal_options[:marker] = decide_marker(response)
          total_results = response[:contents].length + response[:common_prefixes].length
          internal_options[:'max-keys'] ? (internal_options[:'max-keys'] -= total_results) : nil 
        end
        yield response
      end while there_are_more_keys && under_max_keys(internal_options)
      true
    rescue
      on_exception
    end
def incrementally_list_bucket ( bucket , options = { } , headers = { } , & block ) internal_options = options . right_symbolize_keys begin internal_bucket = bucket . dup internal_bucket += '?' + internal_options . map { | k , v | "#{k.to_s}=#{CGI::escape v.to_s}" } . join ( '&' ) unless internal_options . right_blank? req_hash = generate_rest_request ( 'GET' , headers . merge ( :url => internal_bucket ) ) response = request_info ( req_hash , S3ImprovedListBucketParser . new ( :logger => @logger ) ) there_are_more_keys = response [ :is_truncated ] if ( there_are_more_keys ) internal_options [ :marker ] = decide_marker ( response ) total_results = response [ :contents ] . length + response [ :common_prefixes ] . length internal_options [ :' max-keys ' ] ? ( internal_options [ :' max-keys ' ] -= total_results ) : nil end yield response end while there_are_more_keys && under_max_keys ( internal_options ) true rescue on_exception end
Incrementally list the contents of a bucket.
Incrementally list the contents of a bucket .
bucket
<not_specific>
options
<not_specific>
headers
<not_specific>
block
<not_specific>