dodb/src/util.lisp

27 lines
820 B
Common Lisp

(defpackage :util
(:use :common-lisp)
(:nicknames :ut)
(:export :write-object-to-file
:read-file
:read-object-from-file))
(in-package util)
(defun read-file (infile)
(with-open-file (instream infile
:direction :input
:if-does-not-exist nil)
(when instream
(let ((string (make-string (file-length instream))))
(read-sequence string instream)
string))))
(defun read-object-from-file (infile)
(read-from-string (read-file infile)))
(defun write-object-to-file (object outfile)
(with-open-file (my-file outfile
:direction :output
:if-exists :supersede
:if-does-not-exist :create)
(format my-file "~&~S~&" object)))