Skip to content

Instantly share code, notes, and snippets.

@mikeananev
Created October 22, 2019 18:56
Show Gist options
  • Select an option

  • Save mikeananev/58f07184b9be431ae4a3980ac3c5e22f to your computer and use it in GitHub Desktop.

Select an option

Save mikeananev/58f07184b9be431ae4a3980ac3c5e22f to your computer and use it in GitHub Desktop.
secure delete file
(require '[clojure.java.io :as io])
(defn secure-delete-file
"fill file content with mask 0x55AA and then delete it.
return nil."
[^String fname]
(let [length (.length (io/file fname))
buf-len 4096
w (quot length buf-len)
r (rem length buf-len)
buf (byte-array (take buf-len (cycle [0x55 0xAA])))]
(with-open [out (io/output-stream (io/file fname))]
(dotimes [n w]
(.write out buf))
(.write out (byte-array (take r (cycle [0x55 0xAA])))))
(io/delete-file (io/file fname))
nil))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment