hardfiles- Unnamed repository; edit this file 'description' to name the repository. |
git clone git://git.acid.vegas/-c.git |
Log | Files | Refs | Archive | README | LICENSE |
commit 2f2090929c1cb070979e08b0284a433a99b72dcd
parent 7cc0152d3eb97b184d3080554a1091955d2fe253 Author: acidvegas <acid.vegas@acid.vegas> Date: Wed, 27 Dec 2023 15:11:13 -0500 Improved Scramble function efficency Diffstat:
|
1 file changed, 10 insertions(+), 12 deletions(-) |
diff --git a/main.go b/main.go @@ -61,22 +61,20 @@ func Shred(path string) error { } func Scramble(path string, size int64) error { - var i int64 - for i = 0; i < 7; i++ { // 7 iterations - file, err := os.OpenFile(path, os.O_RDWR, 0) - if err != nil { + file, err := os.OpenFile(path, os.O_RDWR, 0) + if err != nil { + return err + } + defer file.Close() + + for i := 0; i < 7; i++ { // 7 iterations + buff := make([]byte, size) + if _, err := rand.Read(buff); err != nil { return err } - defer file.Close() - - offset, err := file.Seek(0, 0) - if err != nil { + if _, err := file.WriteAt(buff, 0); err != nil { return err } - buff := make([]byte, size) - rand.Read(buff) - file.WriteAt(buff, offset) - file.Close() } return nil } |