Add a module for file loading / writing

This commit is contained in:
Renaud Casenave-Péré 2014-01-20 23:17:05 +09:00
parent 4a7ecc072c
commit a10a88f6bc
2 changed files with 27 additions and 0 deletions

25
src/file.lisp Normal file
View file

@ -0,0 +1,25 @@
#|
This file is a part of stoe project.
Copyright (c) 2014 Renaud Casenave-Péré (renaud@casenave-pere.fr)
|#
(in-package :cl-user)
(defpackage stoe.file
(:nicknames :file)
(:use :cl)
(:export :load-file))
(in-package :stoe.file)
(defun do-load-file (filepath)
"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))
(when stream
(let ((buffer (make-array (file-length stream) :element-type '(unsigned-byte 8))))
(read-sequence buffer stream)
buffer))))
(defun load-file (filepath callback &key (sync nil))
"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)))

View file

@ -28,6 +28,8 @@
:depends-on ("utils"))
(:file "jobs"
:depends-on ("thread" "containers" "utils"))
(:file "file"
:depends-on ("jobs"))
(:file "stoe"
:depends-on ("utils" "modules")))))
:description "SaintOEngine - A 3d engine in common-lisp"