Skip to content

Documentation


Documentation / @blazetrails/activesupport / StringIO

Class: StringIO<S> ​

Defined in: packages/ruby-compat/dist/string-io.d.ts:21

Ruby's StringIO (stdlib), the readable/writable in-memory IO that XmlMini._parse_file (activesupport/lib/active_support/xml_mini.rb:180-186) and Rack::MockRequest hand to their callers. Only the members Ruby code in this repo sends are ported.

The buffer holds bytes, so size, read's length and write's return value count bytes exactly as Ruby's do. A StringIO opened on an ASCII-8BIT String, a Uint8Array, answers its whole-buffer reads as one, and every other answers them as the UTF-8 text the bytes spell; read's length arm answers a Uint8Array whatever the buffer, as strio_read (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1539) tags it ASCII-8BIT.

No Rails Equivalent ​

PERMANENT — Ruby stdlib, not Rails: StringIO (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1432) ships with the interpreter, so no Rails file defines it and no port can remove the need for it while _parse_file and Rack::MockRequest hand callers an IO.

Type Parameters ​

Type ParameterDefault type
S extends string | Uint8Arraystring

Constructors ​

Constructor ​

new StringIO<S>(string?): StringIO<S>

Defined in: packages/ruby-compat/dist/string-io.d.ts:23

Parameters ​

ParameterType
string?S

Returns ​

StringIO<S>

Properties ​

print ​

print: (this, ...args) => null

Defined in: packages/ruby-compat/dist/string-io.d.ts:71

rb_io_print (vendor/ruby/v3.3.11/io.c:8715) with $, nil: each argument's to_s, written with no separator, answering nil. Shared by IO#print and StringIO#print the way puts is.

Parameters ​

ParameterType
thisGenericWritable
...argsunknown[]

Returns ​

null

No Rails Equivalent ​

PERMANENT — Ruby core IO#print (vendor/ruby/v3.3.11/io.c:8715).

No Rails Equivalent ​

PERMANENT — Ruby stdlib, not Rails: IO::generic_writable#print (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1956 aliases it to rb_io_print, vendor/ruby/v3.3.11/io.c:8715).


puts ​

puts: (this, ...args) => null

Defined in: packages/ruby-compat/dist/string-io.d.ts:65

IO::generic_writable#puts (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1530 aliases it to rb_io_puts, vendor/ruby/v3.3.11/io.c:8947), which is how Rack::Session::Abstract::Persisted#commit_session writes to rack.errors. One body, shared with IO#puts — see ./io.js.

rb_io_puts (vendor/ruby/v3.3.11/io.c:8947), reached both as IO#puts (io.c:15459) and, through IO::generic_writable, as StringIO#puts (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1530) — one body, two receivers, which is why it lives here rather than beside StringIO.

Parameters ​

ParameterType
thisGenericWritable
...argsunknown[]

Returns ​

null

No Rails Equivalent ​

PERMANENT — Ruby core IO#puts (vendor/ruby/v3.3.11/io.c:8947).

No Rails Equivalent ​

PERMANENT — Ruby stdlib, not Rails: IO::generic_writable#puts (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1530).

Accessors ​

pos ​

Get Signature ​

get pos(): number

Defined in: packages/ruby-compat/dist/string-io.d.ts:85

strio_get_pos (vendor/ruby/v3.3.11/ext/stringio/stringio.c:940), the offset rewind puts back to zero.

No Rails Equivalent ​

PERMANENT — Ruby stdlib StringIO#pos (vendor/ruby/v3.3.11/ext/stringio/stringio.c:940).

Returns ​

number

Methods ​

append() ​

append(str): this

Defined in: packages/ruby-compat/dist/string-io.d.ts:55

IO::generic_writable#<< (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1955strio_addstr, which is rb_io_addstr, vendor/ruby/v3.3.11/io.c:2323-2327).

Parameters ​

ParameterType
strstring | Uint8Array<ArrayBufferLike>

Returns ​

this

No Rails Equivalent ​

PERMANENT


binmode() ​

binmode(): this

Defined in: packages/ruby-compat/dist/string-io.d.ts:96

strio_binmode (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1863) — it records ASCII-8BIT on the stream and, when the StringIO is writable, associates it with the buffer String, then answers the StringIO, whose whole-buffer reads then answer a Uint8Array (see the class comment).

Returns ​

this

No Rails Equivalent ​

PERMANENT — Ruby stdlib StringIO#binmode (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1879).


close() ​

close(): void

Defined in: packages/ruby-compat/dist/string-io.d.ts:149

Returns ​

void


closeRead() ​

closeRead(): null

Defined in: packages/ruby-compat/dist/string-io.d.ts:154

Returns ​

null

No Rails Equivalent ​

PERMANENT — Ruby stdlib StringIO#close_read (vendor/ruby/v3.3.11/ext/stringio/stringio.c:520).


closeWrite() ​

closeWrite(): null

Defined in: packages/ruby-compat/dist/string-io.d.ts:159

Returns ​

null

No Rails Equivalent ​

PERMANENT — Ruby stdlib StringIO#close_write (vendor/ruby/v3.3.11/ext/stringio/stringio.c:541).


each() ​

each(block): this

Defined in: packages/ruby-compat/dist/string-io.d.ts:147

strio_each (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1366) with no separator argument: yields each remaining line and leaves the stream at EOF.

Parameters ​

ParameterType
block(line) => void

Returns ​

this

No Rails Equivalent ​

PERMANENT


flush() ​

flush(): this

Defined in: packages/ruby-compat/dist/string-io.d.ts:77

Returns ​

this

No Rails Equivalent ​

PERMANENT — Ruby stdlib, not Rails: strio_flush (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1891) returns the StringIO itself, which is how Rack::ShowExceptions#call flushes rack.errors.


gets() ​

gets(): S | null

Defined in: packages/ruby-compat/dist/string-io.d.ts:140

strio_gets (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1322) with no separator argument: the next line, newline included, or nil at EOF.

Returns ​

S | null

No Rails Equivalent ​

PERMANENT


initializeCopy() ​

initializeCopy(orig): this

Defined in: packages/ruby-compat/dist/string-io.d.ts:31

strio_copy (vendor/ruby/v3.3.11/ext/stringio/stringio.c:620), bound to initialize_copy (:1869): the copy shares the original's struct, so both read and write one buffer and one position.

Parameters ​

ParameterType
origStringIO<S>

Returns ​

this

No Rails Equivalent ​

PERMANENT — Ruby stdlib, not Rails: StringIO#initialize_copy.


isClosed() ​

isClosed(): boolean

Defined in: packages/ruby-compat/dist/string-io.d.ts:164

Returns ​

boolean

No Rails Equivalent ​

PERMANENT — Ruby stdlib StringIO#closed? (vendor/ruby/v3.3.11/ext/stringio/stringio.c:559).


isEof() ​

isEof(): boolean

Defined in: packages/ruby-compat/dist/string-io.d.ts:148

Returns ​

boolean


read() ​

Call Signature ​

read(): S

Defined in: packages/ruby-compat/dist/string-io.d.ts:46

strio_read (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1539). The str buffer of its two-argument form (stringio.c:1548-1552) receives the bytes, and at EOF Ruby empties it with rb_str_resize(str, 0) (stringio.c:1561) before answering nil.

A Uint8Array cannot be resized, so — exactly as IO.read already does for io_read's identical str argument (vendor/ruby/v3.3.11/io.c:3800) — it is filled up to its own length instead, and zero-filled where Ruby truncates. That deviation is recorded once there; this is the same fact about the same buffer.

Returns ​

S

Call Signature ​

read(length, str?): Uint8Array<ArrayBufferLike> | null

Defined in: packages/ruby-compat/dist/string-io.d.ts:47

strio_read (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1539). The str buffer of its two-argument form (stringio.c:1548-1552) receives the bytes, and at EOF Ruby empties it with rb_str_resize(str, 0) (stringio.c:1561) before answering nil.

A Uint8Array cannot be resized, so — exactly as IO.read already does for io_read's identical str argument (vendor/ruby/v3.3.11/io.c:3800) — it is filled up to its own length instead, and zero-filled where Ruby truncates. That deviation is recorded once there; this is the same fact about the same buffer.

Parameters ​
ParameterType
lengthnumber
str?Uint8Array<ArrayBufferLike> | null
Returns ​

Uint8Array<ArrayBufferLike> | null


readpartial() ​

readpartial(maxlen, outbuf?): Uint8Array

Defined in: packages/ruby-compat/dist/string-io.d.ts:133

strio_sysread (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1664), which StringIO#readpartial is defined as (stringio.c:1949): read with a rb_eof_error() (vendor/ruby/v3.3.11/io.c:756) where that answers nil — the member Rack::Test::UploadedFile#append_to (vendor/rack-test/v2.2.0/lib/rack/test/uploaded_file.rb:64) walks a StringIO body with.

Parameters ​

ParameterType
maxlennumber
outbuf?Uint8Array<ArrayBufferLike> | null

Returns ​

Uint8Array

No Rails Equivalent ​

PERMANENT — Ruby stdlib StringIO#readpartial (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1949).


rewind() ​

rewind(): number

Defined in: packages/ruby-compat/dist/string-io.d.ts:86

Returns ​

number


setEncoding() ​

setEncoding(extEnc): this

Defined in: packages/ruby-compat/dist/string-io.d.ts:120

strio_set_encoding (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1801) in its one-argument form — the encoding is recorded on the stream and, when the StringIO is writable, associated with the buffer String (stringio.c:1823-1826); it answers the StringIO. int_enc and opt are ignored by MRI itself (stringio.c:1796-1797), so neither is ported.

Associated with BINARY, the buffer's whole-buffer reads answer a Uint8Array (see the class comment), and the recorded encoding is what Rack::Test::Utils.build_file_part's set_encoding(Encoding::BINARY) (vendor/rack-test/v2.2.0/lib/rack/test/utils.rb:148) is asking for.

rb_find_encoding (vendor/ruby/v3.3.11/encoding.c:325-332) answers a NULL rb_encoding * for a name that resolves to UNSPECIFIED_ENCODING — the internal alias while Encoding.default_internal is unset — and strio_set_encoding then falls through the mode-string path to no encoding at all, which the stream reports as ASCII-8BIT (verified against ruby 3.3: StringIO.new("x").set_encoding("internal") .external_encoding is #<Encoding:ASCII-8BIT>).

Parameters ​

ParameterType
extEncstring | Encoding

Returns ​

this

No Rails Equivalent ​

PERMANENT — Ruby stdlib StringIO#set_encoding (vendor/ruby/v3.3.11/ext/stringio/stringio.c:1801).


size() ​

size(): number

Defined in: packages/ruby-compat/dist/string-io.d.ts:33

Returns ​

number


string() ​

string(): S

Defined in: packages/ruby-compat/dist/string-io.d.ts:32

Returns ​

S


write() ​

write(string): number

Defined in: packages/ruby-compat/dist/string-io.d.ts:48

Parameters ​

ParameterType
stringstring | Uint8Array<ArrayBufferLike>

Returns ​

number