PasteRack.org
Paste # 86651
2017-06-15 12:57:24

Fork as a new paste.

Paste viewed 123 times.


Embed:

  1. #lang typed/racket
  2. ;racket helper functions to load files as binary data
  3. (module binfile racket
  4.   (provide (all-defined-out))
  5.  
  6.   (: binfile->list (-> Path-String (Listof Byte)))
  7.   (define (binfile->list path)
  8.     (call-with-input-file* path
  9.       (λ
  10.           ([p : Input-Port])
  11.         (letrec ([loop : (-> Input-Port (Listof Byte) (Listof Byte))
  12.                        (λ ([p   : Input-Port]
  13.                            [lst : (Listof Byte)])
  14.                          (match (read-byte p)
  15.                            [(? byte? b)     (loop p (cons b lst))]
  16.                            [(? eof-object?) lst])) ])
  17.           (loop p '())))))
  18.  
  19.   (: binfile->vector (-> Path-String (Vectorof Byte)))
  20.   (define (binfile->vector path)
  21.     (list->vector (reverse (binfile->list path)))))

=>