From: ·····@acm.org
Subject: Binary in memory stream
Date: 
Message-ID: <1162667794.763042.156590@h48g2000cwc.googlegroups.com>
Hi,

I have some functions (e.g. read-float) that read binary data.
The argument to these functions is a stream, i.e. they call
read-byte.

So all is well if I'm reading from a file, but sometimes I have an
array that contains the data to read, and I'd like to have read-float
operate on the array.

So, my question is, "How can I create a stream whose data source
is an array (or vector)?"

I'm using SBCL 0.9.18.

I've seen similar threads on this list, but didn't seem to fully find
the
answer.

Many thanks for any help!

Cheers,
David

From: ·······@gmail.com
Subject: Re: Binary in memory stream
Date: 
Message-ID: <1162669233.404352.208730@e3g2000cwe.googlegroups.com>
·····@acm.org wrote:

> So, my question is, "How can I create a stream whose data source
> is an array (or vector)?"

You could try this:

  http://weitz.de/flexi-streams/#in-memory

Cheers,
Edi.
From: Pascal Bourguignon
Subject: Re: Binary in memory stream
Date: 
Message-ID: <87wt6bxbje.fsf@thalassa.informatimago.com>
·····@acm.org writes:
> I have some functions (e.g. read-float) that read binary data.
> The argument to these functions is a stream, i.e. they call
> read-byte.
>
> So all is well if I'm reading from a file, but sometimes I have an
> array that contains the data to read, and I'd like to have read-float
> operate on the array.
>
> So, my question is, "How can I create a stream whose data source
> is an array (or vector)?"

If you want to use CL:READ-BYTE, you'll have to use the non standard
GRAY streams. (SB-GRAY IIRC).

If you can use instead YOUR-OWN:READ-BYTE, it's trivial to implement
such a function to read from a sequence.  See for example BVSTREAM in:
http://darcs.informatimago.com/lisp/common-lisp/stream.lisp

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

ADVISORY: There is an extremely small but nonzero chance that,
through a process known as "tunneling," this product may
spontaneously disappear from its present location and reappear at
any random place in the universe, including your neighbor's
domicile. The manufacturer will not be responsible for any damages
or inconveniences that may result.