Module: IO::Stream

Defined in:
lib/io/stream.rb,
lib/io/stream/generic.rb,
lib/io/stream/version.rb,
lib/io/stream/buffered.rb,
lib/io/stream/readable.rb,
lib/io/stream/writable.rb,
lib/io/stream/string_buffer.rb,
lib/io/stream/connection_reset_error.rb

Overview

Released under the MIT License. Copyright, 2023-2025, by Samuel Williams.

Defined Under Namespace

Modules: Readable, Writable Classes: Buffered, ConnectionResetError, Generic, StringBuffer

Constant Summary collapse

VERSION =
"0.11.1"
BLOCK_SIZE =

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

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

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

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

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.

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

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

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