From 4f256b1bbf290508361dce85e4273208a39118b5 Mon Sep 17 00:00:00 2001 From: Charles Jackson Date: Wed, 21 Apr 2021 22:54:11 -0500 Subject: [PATCH] Add a function to dump yaml to file --- package.lisp | 2 +- stringify.lisp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package.lisp b/package.lisp index 84d4eee..24359bb 100755 --- a/package.lisp +++ b/package.lisp @@ -21,4 +21,4 @@ #:convert-node #:convert-scalar #:convert-sequence #:convert-mapping #:convert-sequence-to-list #:convert-mapping-to-hashtable ;; for serialization - #:stringify)) + #:stringify #:dump-file)) diff --git a/stringify.lisp b/stringify.lisp index 2de236a..e885557 100644 --- a/stringify.lisp +++ b/stringify.lisp @@ -117,3 +117,11 @@ This relies on the parser parsing yaml null as :null instead of nil." :else :collect (format nil "~a: ~a" key (stringify value))))))) + +;;; dump to file +(defun dump-file (yaml path &key if-exists (if-does-not-exist :create)) + (with-open-file (out path + :direction :output + :if-exists if-exists + :if-does-not-exist if-does-not-exist) + (write-sequence (stringify yaml) out)))