Sha256: d3991199d4f7bec25e90a315358d0ff72489b2466eb8c1051217e667aff1def8

Contents?: true

Size: 1.96 KB

Versions: 56

Compression:

Stored size: 1.96 KB

Contents

module AWS
  module S3
    # Objects on S3 can be distributed via the BitTorrent file sharing protocol. 
    #
    # You can get a torrent file for an object by calling <tt>torrent_for</tt>:
    #
    #   S3Object.torrent_for 'kiss.jpg', 'marcel'
    #
    # Or just call the <tt>torrent</tt> method if you already have the object:
    #
    #   song = S3Object.find 'kiss.jpg', 'marcel'
    #   song.torrent
    #
    # Calling <tt>grant_torrent_access_to</tt> on a object will allow anyone to anonymously
    # fetch the torrent file for that object:
    #
    #   S3Object.grant_torrent_access_to 'kiss.jpg', 'marcel'
    #
    # Anonymous requests to
    #
    #   http://s3.amazonaws.com/marcel/kiss.jpg?torrent
    #
    # will serve up the torrent file for that object.
    module BitTorrent
      def self.included(klass) #:nodoc:
        klass.extend ClassMethods
      end
      
      # Adds methods to S3Object for accessing the torrent of a given object.
      module ClassMethods
        # Returns the torrent file for the object with the given <tt>key</tt>.
        def torrent_for(key, bucket = nil)
          get(path!(bucket, key) << '?torrent').body
        end
        alias_method :torrent, :torrent_for
        
        # Grants access to the object with the given <tt>key</tt> to be accessible as a torrent.
        def grant_torrent_access_to(key, bucket = nil)
          policy = acl(key, bucket)
          return true if policy.grants.include?(:public_read)
          policy.grants << ACL::Grant.grant(:public_read)
          acl(key, bucket, policy)
        end
        alias_method :grant_torrent_access, :grant_torrent_access_to
      end
      
      # Returns the torrent file for the object.
      def torrent
        self.class.torrent_for(key, bucket.name)
      end
      
      # Grants torrent access publicly to anyone who requests it on this object.
      def grant_torrent_access
        self.class.grant_torrent_access_to(key, bucket.name)
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 24 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/aws-s3-0.6.3/lib/aws/s3/bittorrent.rb
croaker-aws-s3-0.5.2.20090127001 lib/aws/s3/bittorrent.rb
croaker-aws-s3-0.5.2.20090127002 lib/aws/s3/bittorrent.rb
dbourguignon-aws-s3-0.6.3 lib/aws/s3/bittorrent.rb
eisokant-aws-s3-0.4.1 lib/aws/s3/bittorrent.rb
isaacfeliu-aws-s3-0.4.0 lib/aws/s3/bittorrent.rb
isaacfeliu-aws-s3-0.4.1 lib/aws/s3/bittorrent.rb
ryanking-aws-s3-0.5.1.200811101723 lib/aws/s3/bittorrent.rb
sml-aws-s3-0.5.1.1225474505 lib/aws/s3/bittorrent.rb
sml-aws-s3-0.5.1.1226533772 lib/aws/s3/bittorrent.rb
stephenh-s3fsr-1.0 lib/aws-matt/s3/bittorrent.rb
stephenh-s3fsr-1.1 lib/aws-matt/s3/bittorrent.rb
stephenh-s3fsr-1.2 lib/aws-matt/s3/bittorrent.rb
stephenh-s3fsr-1.3 lib/aws-matt/s3/bittorrent.rb
s3fsr-1.12 lib/aws-matt/s3/bittorrent.rb
s3fsr-1.11 lib/aws-matt/s3/bittorrent.rb
s3fsr-1.10 lib/aws-matt/s3/bittorrent.rb
aws-s3-instructure-0.6.2.1352914936 lib/aws/s3/bittorrent.rb
aws-s3-0.6.3 lib/aws/s3/bittorrent.rb
mb-aws-s3-0.6.2 lib/aws/s3/bittorrent.rb