Created
October 22, 2019 18:56
-
-
Save mikeananev/58f07184b9be431ae4a3980ac3c5e22f to your computer and use it in GitHub Desktop.
secure delete file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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