in-memory implementation of IO class

N

Nathan Beyer

Is there an implementation of the IO class that operates on in-memory
byte arrays (or other data structure)? I haven't seen anything in the
core/stdlib.
 
J

James Gray

Is there an implementation of the IO class that operates on in-memory
byte arrays (or other data structure)? I haven't seen anything in the
core/stdlib.

Yes, see the standard StringIO library.

James Edward Gray II
 
N

Nathan Beyer

Yes, see the standard StringIO library.

James Edward Gray II

Excuse my ignorance -- I'm just getting into Ruby, but isn't the
StringIO for working with character data? Is there no distinction
between characters and bytes? I was assuming that StringIO and String
would cause some form of character encoding/decoding processing to
kick in.

Thanks
- Nathan
 
P

pharrington

Excuse my ignorance -- I'm just getting into Ruby, but isn't the
StringIO for working with character data? Is there no distinction
between characters and bytes? I was assuming that StringIO and String
would cause some form of character encoding/decoding processing to
kick in.

Thanks
- Nathan

I would think this is what the #bytes, #each_byte, #readbyte, etc
methods are for. But I've never actually used StringIO *myself*, so I
can't say for sure. (However, the fact that Rack and ActionPack both
use StringIO for processing requests says its safe for raw data)
 
E

Eric Hodel

Excuse my ignorance -- I'm just getting into Ruby, but isn't the
StringIO for working with character data? Is there no distinction
between characters and bytes? I was assuming that StringIO and String
would cause some form of character encoding/decoding processing to
kick in.

In ruby 1.8 no. In ruby 1.9 set the encoding to binary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,169
Messages
2,570,920
Members
47,463
Latest member
FinleyMoye

Latest Threads

Top