Allow load-file function to specify the buffer's type

This commit is contained in:
Renaud Casenave-Péré 2014-09-17 08:35:34 +02:00
parent 7eaca6a359
commit 563bd7f0f9

View file

@ -10,16 +10,16 @@
(:export :load-file))
(in-package :stoe.file)
(defun do-load-file (filepath)
(defun do-load-file (filepath type)
"Load the file specified by `filepath' and store it in the object returned."
(with-open-file (stream filepath :direction :input :element-type '(unsigned-byte 8))
(with-open-file (stream filepath :direction :input :element-type type)
(when stream
(let ((buffer (make-array (file-length stream) :element-type '(unsigned-byte 8))))
(let ((buffer (make-array (file-length stream) :element-type type)))
(read-sequence buffer stream)
buffer))))
(defun load-file (filepath callback &key (sync nil))
(defun load-file (filepath &key (sync nil) (type '(unsigned-byte 8)))
"Load the file specified by `filepath' asynchronally unless `sync' is true."
(if sync
(callback (do-load-file filepath))
(jobs:push-job #'do-load-file (list filepath) callback)))
(do-load-file filepath type)
(jobs:push-job #'do-load-file (list filepath type))))