stream_count 1.0.1 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1630a60b67967f609872ed5ac5bf769f2a2a2a32
4
- data.tar.gz: 73bf07a9f594ba8f76f7595ea27db5429fc0b6f8
3
+ metadata.gz: e06b612521f474af7ab35d785e301215a7612959
4
+ data.tar.gz: 06178c8259dc2e4eab1ca2a4fca2392afd383728
5
5
  SHA512:
6
- metadata.gz: a363ca4d0df7945165a01b809a7ddc8985ecb35b582ccd27536242331897c379c86e109b2152d1e678bf07fa9248ef75126a5e8f626e3078eeb91a6825ff2e36
7
- data.tar.gz: 0bf14585ed966b63e2f8f461e3c40fc31f6704646eb3cd49cc81087cc3559d03d923bbc8651b8d169ce087d4f6d83d64ac78ff806cd0d630f519ff406d661f7d
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 = 1024
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, throttle: false)
18
+ output(bytes: bytes, lines: lines)
19
19
  while (data = io.read(BUFFER_SIZE))
20
- $stdout.print(data)
20
+ $stdout.write(data)
21
21
  bytes += data.size
22
22
  lines += data.count($/)
23
- output(bytes: bytes, lines: lines, throttle: true)
23
+ throttler { output(bytes: bytes, lines: lines) }
24
24
  end
25
- output(bytes: bytes, lines: lines, throttle: false)
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:, throttle: true)
31
- throttler(force: !throttle) do
32
- msg = "\e[1G\e[2K%s seconds | %s bytes [ %s kb/sec ] | %s lines [ %s lines/sec ]"
33
- duration = Time.now.to_f - @start_time
34
- if duration > 0
35
- $stderr.print(msg % [number_with_delimiter(duration.to_i),
36
- number_with_delimiter(bytes),
37
- number_with_delimiter((bytes / duration / 1024).to_i),
38
- number_with_delimiter(lines),
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(force:, threshold: TICK_DURATION, &block)
42
+ def throttler(threshold: TICK_DURATION)
45
43
  @last_tick ||= Time.now.to_f
46
- if force || Time.now.to_f > (@last_tick + threshold)
47
- block.call
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
@@ -1,3 +1,3 @@
1
1
  module StreamCount
2
- VERSION = '1.0.1'.freeze
2
+ VERSION = '1.0.2'.freeze
3
3
  end
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.1
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-25 00:00:00.000000000 Z
11
+ date: 2017-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler