c3d 0.3.5 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/checker.rb DELETED
@@ -1,44 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'cgi'
5
- require 'openssl'
6
-
7
- def require_gem(name)
8
- require(name)
9
- rescue LoadError
10
- abort "[ERROR] Missing the '#{name}' gem, install it with 'gem install #{name}'"
11
- end
12
-
13
- require_gem 'bencode'
14
- require_gem 'base32'
15
- require_gem 'rack/utils'
16
-
17
- # We cannot trust .torrent file data
18
- ARGF.set_encoding 'BINARY'
19
-
20
- # Read torrent from STDIN / ARGV filepath
21
- torrent_data = ARGF.read
22
-
23
- # Parse the torrent data
24
- torrent = BEncode.load(torrent_data)
25
-
26
- # Calculate the info_hash (actually, info_sha1 *is* the info_hash)
27
- info_hash = torrent["info"].bencode
28
- info_sha1 = OpenSSL::Digest::SHA1.digest(info_hash)
29
-
30
- # Build the magnet link
31
- params = {}
32
- params[:xt] = "urn:btih:" << Base32.encode(info_sha1)
33
- params[:dn] = CGI.escape(torrent["info"]["name"])
34
-
35
- # params[:tr] = [] << to complement DHT we can add trackers too
36
- magnet_uri = "magnet:?xt=#{params.delete(:xt)}"
37
- magnet_uri << "&" << Rack::Utils.build_query(params)
38
-
39
- puts "Magnet URI for #{params[:dn]}:"
40
- puts " #{magnet_uri}"
41
-
42
-
43
- # magnet:?xt=urn:btih:048ea0d1a27f702ba5e8f7890915d4d6a2454e20&dn=cdae42af3e2d9b7f208f8ec3
44
- # magnet:?xt=urn:btih:048ea0d1a27f702ba5e8f7890915d4d6a2454e20&dn=cdae42af3e2d9b7f208f8ec3
data/spec/checker2.rb DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bencode'
4
- require 'digest/sha1'
5
- require 'base32'
6
-
7
- t = BEncode.load_file(ARGV[0])
8
- f = BEncode.load_file(ARGV[1])
9
- puts t
10
- puts f