+(defgeneric pixbuf-save (pixbuf dest type &rest options))
+
+(defmethod pixbuf-save (pixbuf (filename string) type &rest options)
+ (multiple-value-bind (ok-p gerror)
+ (multiple-value-call #'%pixbuf-savev
+ pixbuf filename (string-downcase type)
+ (%pixbuf-save-options options))
+ (unless ok-p
+ (signal-gerror gerror))))
+
+(defmethod pixbuf-save (pixbuf (pathname pathname) type &rest options)
+ (apply #'pixbuf-save pixbuf (namestring (translate-logical-pathname pathname))
+ type options))
+
+(define-callback stream-write-func boolean
+ ((data pointer) (length gsize) (gerror pointer) (stream-id pointer-data))
+ (block stream-write
+ (handler-case
+ (let ((stream (find-user-data stream-id)))
+ (write-sequence
+ (map-c-vector 'vector 'identity data '(unsigned-byte 8) length)
+ stream))
+ (serious-condition (condition)
+ (gerror-set-in-callback gerror (file-error-domain)
+ (enum-int :failed 'file-error-enum) (princ-to-string condition))
+ (return-from stream-write nil)))
+ t))
+
+(defbinding %pixbuf-save-to-callbackv (pixbuf stream type keys values) boolean
+ (pixbuf pixbuf)
+ (stream-write-func callback)
+ (stream pointer-data)
+ (type string)
+ (keys strings)
+ (values strings)
+ (nil (or null gerror) :out))
+
+(defmethod pixbuf-save (pixbuf (stream stream) type &rest options)
+ (let ((stream-id (register-user-data stream)))
+ (unwind-protect
+ (multiple-value-bind (ok-p gerror)
+ (multiple-value-call #'%pixbuf-save-to-callbackv
+ pixbuf stream-id (string-downcase type)
+ (%pixbuf-save-options options))
+ (unless ok-p
+ (signal-gerror gerror)))
+ (destroy-user-data stream-id))))
+
+
+;; (defbinding pixbuf-new-from-xpm-data () (referenced pixbuf)
+;; (data (vector string)))