From 0b56746a61bf2384d97863cf929a29dab87e3d36 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Sun, 9 Feb 2014 18:29:16 +0700 Subject: [PATCH] Mod (experimental) `Compressable-LZMA2` to use new :skip-header? mode, add :headerless-meta assertion --- src/taoensso/nippy.clj | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/taoensso/nippy.clj b/src/taoensso/nippy.clj index 3d72a0c8..0c696063 100644 --- a/src/taoensso/nippy.clj +++ b/src/taoensso/nippy.clj @@ -498,6 +498,10 @@ :as opts}]] (let [headerless-meta (merge headerless-meta (:legacy-opts opts)) ; Deprecated + _ (assert (or (nil? headerless-meta) + (head-meta-id headerless-meta)) + "Bad :headerless-meta (should be nil or a valid `head-meta` value)") + ex (fn [msg & [e]] (throw (Exception. (str "Thaw failed: " msg) e))) try-thaw-data (fn [data-ba {:keys [compressed? encrypted?] :as _head-or-headerless-meta}] @@ -595,8 +599,7 @@ (defrecord Compressable-LZMA2 [value]) (extend-freeze Compressable-LZMA2 128 [x out] - (let [[_ ^bytes ba] (-> (freeze (:value x) {:compressor nil}) - (utils/ba-split 4)) + (let [ba (freeze (:value x) {:skip-header? true :compressor nil}) ba-len (alength ba) compress? (> ba-len 1024)] (.writeBoolean out compress?) @@ -607,8 +610,10 @@ (extend-thaw 128 [in] (let [compressed? (.readBoolean in) ba (read-bytes in)] - (thaw (wrap-header ba {:compressed? compressed? :encrypted? false}) - {:compressor compression/lzma2-compressor}))) + (thaw ba {:compressor compression/lzma2-compressor + :headerless-meta {:version 1 + :compressed? compressed? + :encrypted? false}}))) (comment (->> (apply str (repeatedly 1000 rand))