Skip to content

Instantly share code, notes, and snippets.

@yamasushi
Created July 28, 2012 12:14
Show Gist options
  • Select an option

  • Save yamasushi/3193063 to your computer and use it in GitHub Desktop.

Select an option

Save yamasushi/3193063 to your computer and use it in GitHub Desktop.
ポートをu8vectorでよんでいく。chunkサイズを指定する。
(use gauche.uvector)
(define (call-with-input-chunk port chunk-size size proc)
(let1 chunk (make-u8vector chunk-size)
(cond
[ (eqv? size 0) #t ]
[ (not size)
(until (read-block! chunk port 0 chunk-size) eof-object? => len
(proc (uvector-alias <u8vector> chunk 0 len) ) ; hook
) ]
[ (> size 0)
(let loop [ (total size)
(len (read-block! chunk port 0 (min size chunk-size)) )]
(unless (eof-object? len)
(proc (uvector-alias <u8vector> chunk 0 len)) ; hook
(let1 n (- total len)
(unless (= n 0)
(loop n (read-block! chunk port 0 (min n chunk-size) ) ) ) ) ) ) ]
) ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment