       serialized-map
       (fn [_ path body]
         (println "exporting:" path)
-        (spit path body))))
+        (with-open [out (io/output-stream path)]
+          (let [buf ^bytes (as-byte-array body)]
+            (.write out buf 0 (alength buf)))))))
   ([serialized-map f]
      (doseq [[id {:keys [path body]}] serialized-map]
        (when (and path body)

    (.setMethod zip ZipOutputStream/DEFLATED)
    (doseq [[id {:keys [path body]}] serialized-map]
      (when (and path body)
        (let [buf (as-byte-array body)]
          (doto zip
            (.putNextEntry (ZipEntry. path))
            (.write buf 0 (alength buf)))))))
  serialized-map)


  (assoc-in scene [:__config :mesh-streamer] f))

(defn configure-mesh-collector
  "Configures the scene to use given fn as mesh collector during
  serialization. The fn needs to accept the scene as single arg and
  return a map of:

    {mesh-id {:path export-path :body mesh}

  The :body value must satisfy the PAsByteArray protocol defined in
  this namespace."
  [scene f]
  (assoc-in scene [:__config :mesh-collector] f))

