zget 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/zput +0 -0
- data/lib/zget/command/zget.rb +9 -1
- data/lib/zget/file_handler.rb +19 -2
- data/lib/zget/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8412a5e29c87313f3ca871dcea9e46a946e561f
|
4
|
+
data.tar.gz: 437166bd8f02d16a15ba06e2af78d9f527563fc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e0affe16488be33258b8e2c81631e616a95e56e64907905ffe851882acc8cd9080f9210fac450fe78041dcf597a716f09cf06a0a1576629c897a531c4a27d46
|
7
|
+
data.tar.gz: d93d7d9c3f2e7d87be00be6411d0c86450224f19d5d589886b06bd3184946586306f9bedda8810c11adfe4f21e91dcf6e04b11cacdfaa6b73eb53b316253d2c1
|
data/exe/zput
CHANGED
File without changes
|
data/lib/zget/command/zget.rb
CHANGED
@@ -2,7 +2,15 @@ module Zget
|
|
2
2
|
class Zget < Command
|
3
3
|
attr_reader :file_or_alias, :output
|
4
4
|
|
5
|
+
CONTENT_LENGTH_PROC = ->(content_length) { @content_length = content_length }
|
6
|
+
PROGRESS_PROC = ->(size) do
|
7
|
+
percentage = size * 100 / @content_length
|
8
|
+
print "\rDownloading: #{percentage}%"
|
9
|
+
puts "\n" if percentage == 100
|
10
|
+
end
|
11
|
+
|
5
12
|
def initialize(file_or_alias: nil, output: nil)
|
13
|
+
@content_length = 0
|
6
14
|
@file_or_alias = file_or_alias
|
7
15
|
@output = output
|
8
16
|
end
|
@@ -25,7 +33,7 @@ module Zget
|
|
25
33
|
|
26
34
|
unless service.nil?
|
27
35
|
DNSSD.resolve! service do |r|
|
28
|
-
open url(r) do |f|
|
36
|
+
open url(r), content_length_proc: CONTENT_LENGTH_PROC, progress_proc: PROGRESS_PROC do |f|
|
29
37
|
filename = output || f.meta["content-disposition"].split(";").last.split("=").last
|
30
38
|
File.write filename, f.read
|
31
39
|
end
|
data/lib/zget/file_handler.rb
CHANGED
@@ -1,8 +1,25 @@
|
|
1
1
|
module Zget
|
2
2
|
# We want this server to shutdown as soon as the file is downloaded
|
3
3
|
class FileHandler < WEBrick::HTTPServlet::DefaultFileHandler
|
4
|
-
|
5
|
-
|
4
|
+
# We want to trick `Kernel::open` in order to display the upload progress.
|
5
|
+
# We do so by reading the file in chunks rather than the whole file.
|
6
|
+
# Why trick `Kernel::open`? See: https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpservlet/filehandler.rb#L61
|
7
|
+
def open(path, mode)
|
8
|
+
st = File::stat(@local_path)
|
9
|
+
Kernel.open(path, mode) do |io|
|
10
|
+
data = ""
|
11
|
+
while d = io.read(1024 * 8)
|
12
|
+
data << d
|
13
|
+
percentage = data.size * 100 / st.size
|
14
|
+
print "\rUploading: #{percentage}%"
|
15
|
+
puts "\n" if percentage == 100
|
16
|
+
end
|
17
|
+
data
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def do_GET(req, res)
|
22
|
+
res["Content-Disposition"] = "inline; filename=#{File.basename @local_path}"
|
6
23
|
super
|
7
24
|
@server.shutdown
|
8
25
|
end
|
data/lib/zget/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zget
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patricio Mac Adden
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
116
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.6.
|
117
|
+
rubygems_version: 2.6.11
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: Write a short summary, because Rubygems requires one.
|