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

From: Jed Davis <r6rs>
Date: Wed, 8 Aug 2007 14:29:24 -0400

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)))))
Received on Wed Aug 08 2007 - 14:29:24 UTC

This archive was generated by hypermail 2.3.0 : Wed Oct 23 2024 - 09:15:01 UTC