rmega 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0861e3b68280695813f70b8ee46e63e7dc66084c
4
- data.tar.gz: c3cc58126f747db8807c3e0cdd811b961c006a64
3
+ metadata.gz: c5220ae63878c82e2e72cb324a5277347dfebee7
4
+ data.tar.gz: 0055c65dcaca525127fe46a228885eb84100a8c7
5
5
  SHA512:
6
- metadata.gz: 9df582d7a167366705ca029154fea91c8333e33f0a200ac8b87cf2af1233f30c98decf18fe3064b2859d063427ae81453d28c78750084f08aaa834c35ef87508
7
- data.tar.gz: a70d8d931a432b73f3f6d2b40939d0bdda2ed34e644a083f44f83360eeb8d27b5c1a47bcf42240e15d85d24c061b5c21de1f6df9a3b0a66f3904bd1620e2de0f
6
+ metadata.gz: 8051f36840c086b719974538d37b770824663a26ce84177316b0945b9acf6a8ba311668164a0ab23e3b1377a1f18a642b49669d167b43244ac1f7ffde5261ad8
7
+ data.tar.gz: eb1cbced4fa134640d631cceca5d03c400bfb1c88499fbc768310f74fbeea09ae416875627fd2e397b9c4025bca17c0f0175646039b842a1a6efe02e4d9b1913
data/.travis.yml CHANGED
@@ -6,4 +6,5 @@ rvm:
6
6
  - 2.0
7
7
  - 2.1
8
8
  - 2.2
9
+ - 2.4
9
10
  - ruby-head
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 0.2.4
2
+
3
+ ### Changes
4
+ * \#25 Fix connection reset on file upload
5
+ * \#24 Speed up aes_cbc_mac func
6
+
7
+ ## 0.2.3
8
+
9
+ ### Changes
10
+ * Fixed reading options from the configuration file (~/.rmega)
11
+ * The max number of parallel threads is now 8
12
+
13
+ ### New Features
14
+ * If `rmega-dl` receive a local file as the main args, that file is treated as a text file that must contains a list of mega links
15
+ * The download progress bar now distinguishes between allocate, verify and download phase
16
+
1
17
  ## 0.2.2
2
18
 
3
19
  ### Changes
data/README.md CHANGED
@@ -88,7 +88,7 @@ end
88
88
  folder.download("~/Downloads/my_folder")
89
89
 
90
90
  # Download a file by url
91
- publid_url = 'https://mega.co.nz/#!MAkg2Iab!bc9Y2U6d93IlRRKVYpcC9hLZjS4G278OPdH6nTFPDNQ'
91
+ public_url = 'https://mega.co.nz/#!MAkg2Iab!bc9Y2U6d93IlRRKVYpcC9hLZjS4G278OPdH6nTFPDNQ'
92
92
  Rmega.download(public_url, '~/Downloads')
93
93
  ```
94
94
 
data/bin/rmega-dl CHANGED
@@ -18,6 +18,7 @@ OptionParser.new do |opts|
18
18
  opts.banner << "Examples:\n"
19
19
  opts.banner << "\t#{File.basename(__FILE__)} 'https://mega.nz/#!aBkHBKLX!n4kqzbJooqc3o_s96PZjN1tEJzQ4QQwskHf7YqKa'\n"
20
20
  opts.banner << "\t#{File.basename(__FILE__)} https://www.reddit.com/r/megalinks\n"
21
+ opts.banner << "\t#{File.basename(__FILE__)} mylinks.txt\n"
21
22
  opts.banner << "\t#{File.basename(__FILE__)} /remote/docs/myfile.txt -u email@localhost\n"
22
23
  opts.banner << "Options:"
23
24
 
@@ -36,14 +37,31 @@ cli_rescue do
36
37
  raise("Node not found - #{cli_options[:url]}") unless node
37
38
  node.download(cli_options[:output] || Dir.pwd)
38
39
  else
39
- urls = [cli_options[:url]]
40
+ urls = []
40
41
 
41
- unless mega_url?(cli_options[:url])
42
- html = Rmega::Session.new.http_get_content(cli_options[:url])
43
- urls = html.scan(Rmega::Nodes::Factory::URL_REGEXP).flatten.uniq
44
- raise("Nothing to download") if urls.empty?
42
+ if mega_url?(cli_options[:url])
43
+ # a valid MEGA urls
44
+ urls = [cli_options[:url]]
45
+ else
46
+ # A text file with a list of MEGA urls (considering only files < 1 Mb)
47
+ if File.exists?(cli_options[:url])
48
+ if File.size(cli_options[:url]) < 1_000_000
49
+ File.open(cli_options[:url], "rb") do |file|
50
+ file.each_line do |line|
51
+ line.strip!
52
+ urls << line if mega_url?(line)
53
+ end
54
+ end
55
+ end
56
+ else
57
+ # A link to a web page with some MEGA urls in its body
58
+ html = Rmega::Session.new.http_get_content(cli_options[:url])
59
+ urls = html.scan(Rmega::Nodes::Factory::URL_REGEXP).flatten.uniq
60
+ end
45
61
  end
46
62
 
63
+ raise("Nothing to download") if urls.empty?
64
+
47
65
  urls.each_with_index do |url, index|
48
66
  node = Rmega::Nodes::Factory.build_from_url(url)
49
67
  print "[#{index+1}/#{urls.size}] " if urls.size > 1
data/lib/rmega/cli.rb CHANGED
@@ -6,7 +6,7 @@ module Rmega
6
6
  module CLI
7
7
  module Helpers
8
8
  def cli_options
9
- $cli_options ||= {}
9
+ $cli_options ||= read_configuration_file
10
10
  end
11
11
 
12
12
  def cli_prompt_password
@@ -27,12 +27,14 @@ module Rmega
27
27
  end
28
28
 
29
29
  def read_configuration_file
30
- return unless File.exists?(configuration_filepath)
31
- cli_options = YAML.load_file(configuration_filepath)
32
- cli_options.keys.each { |k| cli_options[k.to_sym] = cli_options.delete(k) }
33
- puts "Loaded configuration file #{configuration_filepath}" if cli_options[:debug]
30
+ return {} unless File.exists?(configuration_filepath)
31
+
32
+ opts = YAML.load_file(configuration_filepath)
33
+ opts.keys.each { |k| opts[k.to_sym] = opts.delete(k) } # symbolize_keys!
34
+
35
+ return opts
34
36
  rescue Exception => ex
35
- raise(ex) if cli_options[:debug]
37
+ raise(ex)
36
38
  end
37
39
 
38
40
  def apply_cli_options
@@ -44,8 +46,16 @@ module Rmega
44
46
  end
45
47
 
46
48
  def apply_opt_parser_options(opts)
47
- opts.on("-t NUM", "--thread_pool_size", "Number of threads to use") { |n|
48
- cli_options[:thread_pool_size] = n.to_i
49
+ opts.on("-t NUM", "--thread_pool_size", "Number of threads to use [1-8], default and recommended is #{Rmega.options.thread_pool_size}") { |num|
50
+ num = num.to_i
51
+
52
+ if num <= 0
53
+ num = 1
54
+ elsif num > 8
55
+ num = 8
56
+ end
57
+
58
+ cli_options[:thread_pool_size] = num
49
59
  }
50
60
 
51
61
  opts.on("--proxy-addr ADDRESS", "Http proxy address") { |value|
@@ -71,7 +81,7 @@ module Rmega
71
81
  opts.on("-v", "--version", "Print the version number") {
72
82
  puts Rmega::VERSION
73
83
  puts Rmega::HOMEPAGE
74
- exit!(0)
84
+ exit(0)
75
85
  }
76
86
  end
77
87
 
@@ -99,7 +109,6 @@ module Rmega
99
109
  end
100
110
 
101
111
  def cli_rescue
102
- read_configuration_file
103
112
  apply_cli_options
104
113
  yield
105
114
  rescue Interrupt
@@ -28,18 +28,21 @@ module Rmega
28
28
  cipher.iv = iv if iv
29
29
  cipher.key = key
30
30
 
31
- n = 0
32
- mac = nil
31
+ # n = 0
32
+ # mac = nil
33
33
 
34
- loop do
35
- block = data[n..n+15]
36
- break if !block or block.empty?
37
- block << "\x0"*(16-block.size) if block.size < 16
38
- n += 16
39
- mac = cipher.update(block)
40
- end
34
+ # loop do
35
+ # block = data[n..n+15]
36
+ # break if !block or block.empty?
37
+ # block << "\x0"*(16-block.size) if block.size < 16
38
+ # n += 16
39
+ # mac = cipher.update(block)
40
+ # end
41
41
 
42
- return mac
42
+ # return mac
43
+
44
+ block = data + "\x0" * ((16 - data.bytesize % 16) % 16)
45
+ return cipher.update(block)[-16..-1]
43
46
  end
44
47
  end
45
48
  end
data/lib/rmega/net.rb CHANGED
@@ -18,7 +18,7 @@ module Rmega
18
18
  def http_get_content(url)
19
19
  uri = URI(url)
20
20
  req = ::Net::HTTP::Get.new(uri.request_uri)
21
- return send_http_request(uri, req).body
21
+ return net_http(uri).request(req).body
22
22
  end
23
23
 
24
24
  def http_post(url, data)
@@ -26,30 +26,36 @@ module Rmega
26
26
  req = ::Net::HTTP::Post.new(uri.request_uri)
27
27
  req.body = data
28
28
  logger.debug("REQ POST #{url} #{cut_string(data)}")
29
- response = send_http_request(uri, req)
29
+
30
+ # if you don't use Net::Http#start it will not keep the socket open even if you set
31
+ # the connection header BUT setting the connection header to 'keep-alive' its enough
32
+ # to fool MEGA servers and don't let them reset your connection!
33
+ req['Connection'] = 'keep-alive'
34
+
35
+ response = net_http(uri).request(req)
30
36
  logger.debug("REP #{response.code} #{cut_string(response.body)}")
31
37
  return response
32
38
  end
33
39
 
34
40
  private
35
41
 
36
- def send_http_request(uri, req)
42
+ def net_http(uri)
37
43
  http = ::Net::HTTP.new(uri.host, uri.port)
38
44
  http.use_ssl = true if uri.scheme == 'https'
39
- apply_http_options(http)
40
- return http.request(req)
41
- end
42
45
 
43
- def apply_http_options(http)
46
+ # apply common http options
44
47
  http.proxy_from_env = false if options.http_proxy_address
45
48
 
46
49
  options.marshal_dump.each do |name, value|
47
50
  setter_method = name.to_s.split('http_')[1]
48
51
  http.__send__("#{setter_method}=", value) if setter_method and value
49
52
  end
53
+
54
+ return http
50
55
  end
51
56
 
52
57
  def cut_string(string, max = 50)
58
+ return "<binary data, #{string.size} bytes>" if string.encoding == ::Encoding::ASCII_8BIT
53
59
  string.size <= max ? string : string[0..max-1]+"..."
54
60
  end
55
61
  end
@@ -69,7 +69,7 @@ module Rmega
69
69
  path = ::File.expand_path(path)
70
70
  path = Dir.exists?(path) ? ::File.join(path, name) : path
71
71
 
72
- progress = Progress.new(filesize, caption: 'Download', filename: self.name)
72
+ progress = Progress.new(filesize, caption: 'Allocate', filename: self.name)
73
73
  pool = Pool.new
74
74
 
75
75
  @resumed_download = allocated?(path)
@@ -84,12 +84,12 @@ module Rmega
84
84
 
85
85
  if data
86
86
  chunk_macs[start] = calculate_chunck_mac(data) if options.file_integrity_check
87
- progress.increment(size, real: false)
87
+ progress.increment(size, real: false, caption: "Verify")
88
88
  else
89
89
  data = decrypt_chunk(start, download_chunk(start, size))
90
90
  chunk_macs[start] = calculate_chunck_mac(data) if options.file_integrity_check
91
91
  write_chunk(start, data)
92
- progress.increment(size)
92
+ progress.increment(size, caption: "Download")
93
93
  end
94
94
  end
95
95
  end
@@ -72,6 +72,7 @@ module Rmega
72
72
 
73
73
  def increment(bytes, options = {})
74
74
  @mutex.synchronize do
75
+ @caption = options[:caption] if options[:caption]
75
76
  @bytes += bytes
76
77
  @real_bytes += bytes unless options[:real] == false
77
78
  show
data/lib/rmega/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Rmega
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.4"
3
3
  HOMEPAGE = "https://github.com/topac/rmega"
4
4
  end
data/lib/rmega.rb CHANGED
@@ -7,6 +7,7 @@ require 'base64'
7
7
  require 'openssl'
8
8
  require 'digest/md5'
9
9
  require 'json'
10
+ require 'securerandom'
10
11
 
11
12
  # Used only in specs
12
13
  require 'yaml'
@@ -8,7 +8,7 @@ describe 'File upload' do
8
8
  @storage = login
9
9
  end
10
10
 
11
- [12, 6_000].each do |size|
11
+ [12, 6_000, 2_000_000].each do |size|
12
12
 
13
13
  context "when a file (#{size} bytes) is uploaded" do
14
14
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmega
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - topac
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-02 00:00:00.000000000 Z
11
+ date: 2018-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  version: '0'
140
140
  requirements: []
141
141
  rubyforge_project:
142
- rubygems_version: 2.4.6
142
+ rubygems_version: 2.6.12
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: mega.co.nz ruby api