Re: [r6rs-discuss] Mixed binary and ascii data in a single file

2007-08-08 Thread Mike Sperber

Bradley Lucier <[EMAIL PROTECTED]> writes:

> If you turn off buffering in gambit, you can switch between using  
> "read" and using "read-u8" without problems.

There was fairly extensive discussion on this on the r6rs-sdiscuss
mailing list.  Look for the "Stateful codecs and inefficient
transcoding" subject header on:

http://lists.r6rs.org/pipermail/r6rs-discuss/2006-October/thread.html

-- 
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla

___
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss


Re: [r6rs-discuss] Mixed binary and ascii data in a single file

2007-08-08 Thread Bradley Lucier

On Aug 8, 2007, at 4:03 PM, Alan Watson wrote:

> Astronomical FITS files also have an ASCII header followed by  
> binary data. One option is to treat the file as binary and grab the  
> header character by character. Another is to open the file twice,  
> once as an ASCII text stream and once as a binary stream, read the  
> header from the text stream, calculate the length of the header in  
> bytes, offset the binary stream to the start of the binary data,  
> and finally read the data from the binary stream.

Thanks for your reply.  Now that you remind me, I remember that I've  
worked with FITS files, too, in the now-distant past.

The r6rs solutions seem fairly clumsy compared to what is available  
in Gambit (and perhaps in other implementations), where you can  
change the buffering of a port after it has been opened.  (Or at  
least, you can safely change it from unbuffered to buffered after it  
has been opened.)

Brad

___
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss


Re: [r6rs-discuss] Mixed binary and ascii data in a single file

2007-08-08 Thread Alan Watson
Astronomical FITS files also have an ASCII header followed by binary 
data. One option is to treat the file as binary and grab the header 
character by character. Another is to open the file twice, once as an 
ASCII text stream and once as a binary stream, read the header from the 
text stream, calculate the length of the header in bytes, offset the 
binary stream to the start of the binary data, and finally read the data 
from the binary stream.

Regards,

Alan

___
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss


Re: [r6rs-discuss] Mixed binary and ascii data in a single file

2007-08-08 Thread Jed Davis
On Wed, Aug 08, 2007 at 01:44:05PM -0400, Bradley Lucier wrote:
> 
> And a meta-question is: Leaving aside how these things are done in  
> Gambit, how can I achieve what I want to do (mixed ASCII and binary  
> data, buffered reads of the binary data) in (rnrs io ports (6))?

You could read the ASCII text in binary mode, matching delimiters by
their byte value (after all, the encoding is fixed), and then either
interpret the bytes as-is or store them in a bytevector and transcode
that to a string.

And I was going to propose that an "unbuffered" wrapper port could be
created with the facilities provided, like this:

  (define (unbuffered-binary-input-port inner-port)
(make-custom-binary-input-port #f
  (lambda (bv off len) (bytevector-u8-set! bv off (read-u8 inner-port)) 1)
  (lambda () (port-position inner-port))
  (lambda (pos) (port-set-position! inner-port pos))
  #f))

But, as I can see no guarantee that the implementation will not call
the read! procedure more than is minimally necessary for operations
performed on the custom port, I must conclude that that may not work.

-- 
(let ((C call-with-current-continuation)) (apply (lambda (x y) (x y)) (map
((lambda (r) ((C C) (lambda (s) (r (lambda l (apply (s s) l))  (lambda
(f) (lambda (l) (if (null? l) C (lambda (k) (display (car l)) ((f (cdr l))
(C k)))'((#\J #\d #\D #\v #\s) (#\e #\space #\a #\i #\newline)

___
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss