diff -r 1edf5cd93bb9 src/prevalence.lisp
--- a/src/prevalence.lisp	Sun Jul 26 11:10:13 2009 +0200
+++ b/src/prevalence.lisp	Fri Sep 25 03:53:30 2009 +0400
@@ -103,7 +103,11 @@
    (transaction-hook ;; type function
                      :accessor get-transaction-hook
                      :initarg :transaction-hook
-                     :initform #'identity))
+                     :initform #'identity)
+   (external-format ;; external encoding for file operations
+                    :reader get-external-format
+                    :initarg :external-format
+                    :initform :utf-8))
   (:documentation "Base Prevalence system implementation object"))
 
 (defclass guarded-prevalence-system (prevalence-system)
@@ -156,7 +160,8 @@
       (setf transaction-log-stream (open (get-transaction-log system)
 					 :direction :output
 					 :if-does-not-exist :create
-					 :if-exists :append)))))
+					 :if-exists :append
+                                         :external-format (get-external-format system))))))
 
 (defmethod close-open-streams ((system prevalence-system) &key abort)
   "Close all open stream associated with system (optionally aborting operations in progress)"
@@ -242,7 +247,7 @@
                                                           :type (get-file-extension system))
                                            snapshot)))
     (with-open-file (out snapshot
-			 :direction :output :if-does-not-exist :create :if-exists :supersede)
+			 :direction :output :if-does-not-exist :create :if-exists :supersede :external-format (get-external-format system))
       (funcall (get-serializer system) (get-root-objects system) out (get-serialization-state system)))
     (when (probe-file transaction-log)
       (copy-file transaction-log (merge-pathnames (make-pathname :name (get-transaction-log-filename system timetag)
@@ -273,7 +278,7 @@
   (clrhash (get-root-objects system))
   (close-open-streams system)
   (when (probe-file (get-snapshot system))
-    (with-open-file (in (get-snapshot system) :direction :input)
+    (with-open-file (in (get-snapshot system) :direction :input :external-format (get-external-format system))
       (setf (get-root-objects system) (funcall (get-deserializer system) in (get-serialization-state system)))))
   (when (probe-file (get-transaction-log system))
     (let ((position 0))
@@ -284,7 +289,7 @@
                                   condition)
                           (truncate-file (get-transaction-log system) position)
                           (return-from restore))))
-	(with-open-file (in (get-transaction-log system) :direction :input)
+	(with-open-file (in (get-transaction-log system) :direction :input :external-format (get-external-format system))
 	  (loop
 	   (let ((transaction (funcall (get-deserializer system) in (get-serialization-state system))))
 	     (setf position (file-position in))
@@ -310,7 +315,7 @@
 (defmethod backup ((system guarded-prevalence-system) &key directory)
   "Do a backup on a system controlled by a guard"
   (funcall (get-guard system)
-           #'(lambda () (call-next-method system directory))))
+           #'(lambda () (call-next-method system :directory directory))))
 
 (defmethod restore ((system guarded-prevalence-system))
   "Restore a system controlled by a guard"
@@ -343,8 +348,8 @@
 	(buffer (make-string 4096))
 	(index 0)
 	(read-count 0))
-    (with-open-file (in file :direction :input)
-      (with-open-file (out tmp-file :direction :output :if-exists :overwrite :if-does-not-exist :create)
+    (with-open-file (in file :direction :input :external-format (get-external-format system))
+      (with-open-file (out tmp-file :direction :output :if-exists :overwrite :if-does-not-exist :create :external-format (get-external-format system))
 	(when (> position (file-length in)) (return-from truncate-file))
 	(loop
 	 (when (= index position) (return))
diff -r 1edf5cd93bb9 src/serialization/sexp.lisp
--- a/src/serialization/sexp.lisp	Sun Jul 26 11:10:13 2009 +0200
+++ b/src/serialization/sexp.lisp	Fri Sep 25 03:53:30 2009 +0400
@@ -145,8 +145,9 @@
                     (write-string " . " stream)
                     (serialize-sexp-internal (slot-value object slot) stream serialization-state)
                     (write-string ")" stream))
-                serializable-slots))
-	(write-string " ) )" stream)))))
+                serializable-slots)
+          (write-string " )" stream))
+	(write-string " )" stream)))))
 
 ;;; objects
 (defmethod serialize-sexp-internal ((object standard-object) stream serialization-state)
diff -r 1edf5cd93bb9 test/cl-prevalence-test.asd
--- a/test/cl-prevalence-test.asd	Sun Jul 26 11:10:13 2009 +0200
+++ b/test/cl-prevalence-test.asd	Fri Sep 25 03:53:30 2009 +0400
@@ -14,5 +14,6 @@
      (:file "test-managed-prevalence")
      (:file "test-master-slave")
      (:file "test-serialization")
+     (:file "test-external-format")
      )
     :depends-on (:cl-prevalence :fiveam))
\ No newline at end of file
diff -r 1edf5cd93bb9 test/test-external-format.lisp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/test-external-format.lisp	Fri Sep 25 03:53:30 2009 +0400
@@ -0,0 +1,70 @@
+
+(in-package :cl-prevalence-test)
+
+(def-suite test-external-format :in cl-prevalence-test)
+
+(in-suite test-external-format)
+
+(defparameter *test-system-directory* (pathname "/tmp/test-external-format/"))
+
+(defun make-prevalence-system-w/format (external-format)
+  (let ((directory *test-system-directory*))
+    (make-instance 'prevalence-system
+                   :directory directory
+                   :serializer #'s-serialization:serialize-sexp
+                   :deserializer #'s-serialization:deserialize-sexp
+                   :file-extension "lisp"
+                   :external-format external-format)))
+
+(defvar *test-system* nil)
+
+(test test-start/utf-8
+ "Create a new clean prevalence system for testing purposes"
+  (let ((directory *test-system-directory*))
+    ;; Throw away any .lisp files that we find: we want to start from scratch
+    (when (probe-file directory)
+      (dolist (pathname (directory (merge-pathnames "*.lisp" directory)))
+        (delete-file pathname)))
+    (setf *test-system* (make-prevalence-system-w/format :utf-8))
+    (is-true *test-system*)))
+
+(defvar *test-string/utf-8* (coerce '(#\CYRILLIC_CAPITAL_LETTER_E
+                                      #\CYRILLIC_SMALL_LETTER_TE
+                                      #\CYRILLIC_SMALL_LETTER_O
+                                      #\Space
+                                      #\CYRILLIC_SMALL_LETTER_TE
+                                      #\CYRILLIC_SMALL_LETTER_IE
+                                      #\CYRILLIC_SMALL_LETTER_ES
+                                      #\CYRILLIC_SMALL_LETTER_TE)
+                                    'string))
+
+(defun tx-set-string (store string)
+  (setf (get-root-object store :string) string))
+
+(defun get-string ()
+  (get-root-object *test-system* :string))
+
+(test test-save/utf-8
+  (is (null (get-string)))
+  (execute-transaction (tx-set-string *test-system* *test-string/utf-8*))
+  (is (equal (get-string) *test-string/utf-8*)))
+
+(test test-snapshot/utf-8
+  (snapshot *test-system*))
+
+(test test-start-2/utf-8
+  "Create a new prevalence system again"
+  (setf *test-system* (make-prevalence-system-w/format :utf-8))
+  (is-true *test-system*))
+
+(test test-restored/utf-8
+  (is (equal (get-string) *test-string/utf-8*)))
+
+(test test-start/latin-1
+  "Create a new prevalence system again with other charset"
+  (setf *test-system* (make-prevalence-system-w/format :latin-1))
+  (is-true *test-system*))
+
+(test test-restored/latin-1
+  (is-false (equal (get-string) *test-string/utf-8*)))
+  
