stream_count 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stream_count.rb +17 -19
- data/lib/stream_count/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e06b612521f474af7ab35d785e301215a7612959
|
4
|
+
data.tar.gz: 06178c8259dc2e4eab1ca2a4fca2392afd383728
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b77bd06013b9f90202be3d016bb61de30fa1896ed818db2dab9672a12955f31970c865a0bc0f3b68164378e761494712e57397f12b284b178ac3705f5baacb03
|
7
|
+
data.tar.gz: a3de1e997078b534de2b071062deec9f1bf2b3208a1108b9e43269121130040915c0e17c96bb20bdfb178131659b64f3709d6a415e8947d25bbea3b3c67c597d
|
data/lib/stream_count.rb
CHANGED
@@ -7,7 +7,7 @@ require 'stream_count/version'
|
|
7
7
|
module StreamCount
|
8
8
|
module_function
|
9
9
|
|
10
|
-
BUFFER_SIZE =
|
10
|
+
BUFFER_SIZE = 10240
|
11
11
|
TICK_DURATION = 0.2
|
12
12
|
|
13
13
|
# Do the work
|
@@ -15,36 +15,34 @@ module StreamCount
|
|
15
15
|
@start_time = Time.now.to_f
|
16
16
|
bytes = 0
|
17
17
|
lines = 0
|
18
|
-
output(bytes: bytes, lines: lines
|
18
|
+
output(bytes: bytes, lines: lines)
|
19
19
|
while (data = io.read(BUFFER_SIZE))
|
20
|
-
$stdout.
|
20
|
+
$stdout.write(data)
|
21
21
|
bytes += data.size
|
22
22
|
lines += data.count($/)
|
23
|
-
output(bytes: bytes, lines: lines
|
23
|
+
throttler { output(bytes: bytes, lines: lines) }
|
24
24
|
end
|
25
|
-
output(bytes: bytes, lines: lines
|
25
|
+
output(bytes: bytes, lines: lines)
|
26
26
|
end
|
27
27
|
|
28
28
|
# output formatted stats to stderr.
|
29
29
|
# Using throttle will limit how often we print to stderr to 5/second.
|
30
|
-
def output(bytes:, lines
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
number_with_delimiter((lines / duration).to_i)])
|
40
|
-
end
|
30
|
+
def output(bytes:, lines:)
|
31
|
+
msg = "\e[1G\e[2K%s seconds | %s bytes [ %s kb/sec ] | %s lines [ %s lines/sec ]"
|
32
|
+
duration = Time.now.to_f - @start_time
|
33
|
+
if duration > 0
|
34
|
+
$stderr.print(msg % [number_with_delimiter(duration.to_i),
|
35
|
+
number_with_delimiter(bytes),
|
36
|
+
number_with_delimiter((bytes / duration / 1024).to_i),
|
37
|
+
number_with_delimiter(lines),
|
38
|
+
number_with_delimiter((lines / duration).to_i)])
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
44
|
-
def throttler(
|
42
|
+
def throttler(threshold: TICK_DURATION)
|
45
43
|
@last_tick ||= Time.now.to_f
|
46
|
-
if
|
47
|
-
|
44
|
+
if Time.now.to_f > (@last_tick + threshold)
|
45
|
+
yield
|
48
46
|
@last_tick = Time.now.to_f
|
49
47
|
end
|
50
48
|
end
|
data/lib/stream_count/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stream_count
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Pierce
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|