Improved Scramble function efficency

This commit is contained in:
Dionysus 2023-12-27 15:11:13 -05:00
parent 7cc0152d3e
commit 2f2090929c
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE

24
main.go
View File

@ -61,22 +61,20 @@ func Shred(path string) error {
} }
func Scramble(path string, size int64) error { func Scramble(path string, size int64) error {
var i int64 file, err := os.OpenFile(path, os.O_RDWR, 0)
for i = 0; i < 7; i++ { // 7 iterations if err != nil {
file, err := os.OpenFile(path, os.O_RDWR, 0) return err
if err != nil { }
return err defer file.Close()
}
defer file.Close()
offset, err := file.Seek(0, 0) for i := 0; i < 7; i++ { // 7 iterations
if err != nil { buff := make([]byte, size)
if _, err := rand.Read(buff); err != nil {
return err
}
if _, err := file.WriteAt(buff, 0); err != nil {
return err return err
} }
buff := make([]byte, size)
rand.Read(buff)
file.WriteAt(buff, offset)
file.Close()
} }
return nil return nil
} }