IO::StreamSourceIOStream

module Stream

Provides buffered IO streams with consistent read, write, and transport semantics.

Nested

Definitions

def self.Duplex(input, output = nil, **options)

Construct a buffered stream from either one duplex IO-like object or two separate endpoints.

Signature

parameter input IO

The duplex IO object, or the readable endpoint.

parameter output IO | Nil

The writable endpoint, when distinct from the readable endpoint.

parameter options Hash

Additional options passed to the buffered stream wrapper.

returns IO::Stream::Buffered

A buffered stream wrapping the supplied transport.

Implementation

def self.Duplex(input, output = nil, **options)
	if output
		Buffered.wrap(Duplex.new(input, output), **options)
	else
		::IO.Stream(input)
	end
end

BLOCK_SIZE = ENV.fetch("IO_STREAM_BLOCK_SIZE", 1024*256).to_i

The default block size for IO buffers. Defaults to 256KB (optimized for modern SSDs and networks).

MINIMUM_READ_SIZE = ENV.fetch("IO_STREAM_MINIMUM_READ_SIZE", BLOCK_SIZE).to_i

The minimum read size for efficient I/O operations. Defaults to the same as BLOCK_SIZE.

MAXIMUM_READ_SIZE = ENV.fetch("IO_STREAM_MAXIMUM_READ_SIZE", MINIMUM_READ_SIZE * 64).to_i

The maximum read size for a single read operation. This limit exists because:

  1. System calls like read() cannot handle requests larger than SSIZE_MAX
  2. Very large reads can cause memory pressure and poor interactive performance
  3. Most socket buffers and pipe capacities are much smaller anyway On 64-bit systems SSIZE_MAX is ~8.8 million MB, on 32-bit it's ~2GB. Our default of 16MB provides a good balance of throughput and responsiveness, and is page aligned. It is also a multiple of the minimum read size, so that we can read in chunks without exceeding the maximum.

MINIMUM_WRITE_SIZE = ENV.fetch("IO_STREAM_MINIMUM_WRITE_SIZE", BLOCK_SIZE).to_i

The minimum write size before flushing. Defaults to 64KB.