Extract constant IO_DEFAULT_BUFFER_SIZE

This commit is contained in:
Claudia 2020-09-02 18:14:56 +02:00
parent 246db8a134
commit 09d7889ed8
No known key found for this signature in database
GPG Key ID: 246AC3C0F10BE51F

View File

@ -1,6 +1,9 @@
# frozen_string_literal: true
module Utils
IO_DEFAULT_BUFFER_SIZE = 4096
private_constant :IO_DEFAULT_BUFFER_SIZE
def self.popen_read(*args, **options, &block)
popen(args, "rb", options, &block)
end
@ -18,7 +21,7 @@ module Utils
# Before we yield to the block, capture as much output as we can
loop do
output += pipe.read_nonblock(4096)
output += pipe.read_nonblock(IO_DEFAULT_BUFFER_SIZE)
rescue IO::WaitReadable, EOFError
break
end