5

I have a function which output some binary data to a stream. But the stream is abstract, which means the stream can be a file stream, or some other streams. But the stream must be a binary stream which support write-byte function. I searched but not found the answer.

What I want to do is, I have a function which will convert some data to a gif. But I donot want to output the data to a file, I want to output it to something in memory.

Thanks.

kevin lynx
  • 785
  • 9
  • 17

2 Answers2

3

The flexi-streams library provides, among other things, in-memory binary streams.

Ramarren
  • 2,510
  • 1
  • 15
  • 11
  • "It also supplies in-memory binary streams which are similar to string streams. " seems it's what i want. I'll read the documentation for more information. Thanks. – kevin lynx Sep 16 '11 at 08:51
  • Thanks, with-output-to-sequence in flexi-streams solve my problem. – kevin lynx Sep 16 '11 at 09:11
2

"File in memory" - is just a byte array. So all you need is to read your data from stream and write it to one-dimensional array (vector). For more information on arrays in CL see this.

ffriend
  • 27,562
  • 13
  • 91
  • 132
  • No, that's not what i want. What i want is write some data to an array(or something else). But the 'write' function needs a stream object. Thanks anyway. – kevin lynx Sep 16 '11 at 08:50
  • @kevin lynx: So what's the problem to create this function? Read all bytes from stream to a list and supply this list as `:initial-contents` to `make-array`. – ffriend Sep 16 '11 at 09:02