crasher added by sethalves on Sat May 17 05:23:08 2014

#! /bin/sh
#| -*- scheme -*-
exec csi -s $0 "$@"
|#

;; dd if=/dev/zero of=/tmp/ok bs=3075 count=1

(use srfi-4)
(use ports)


(define (make-delimited-textual-input-port port len)
  (let loop ((i 0)
             (segments '()))
    (define (return-result)
      ;; (display "len=")
      ;; (write (length segments))
      ;; (newline)
      (open-input-string (apply string-append (reverse segments))))
    (if (= i len)
        (return-result)
        (let* ((to-read (if (> (+ i 25) len) (- len i) 25))
               (seg (read-string to-read port)))
          (cond ((eof-object? seg) (return-result))
                (else
                 (loop (+ i (string-length seg))
                       (cons seg segments))))))))


(let* ((bv (make-u8vector 1024))
       (read-port (open-input-file "/tmp/ok"))
       (pd (make-delimited-textual-input-port read-port 3075)))

  (let loop ()
    (let ((got (read-u8vector! #f bv pd)))
      (display got)
      (newline)
      (if (> got 0) (loop)))))