Skip to content

Commit

Permalink
Improved Scramble function efficency
Browse files Browse the repository at this point in the history
  • Loading branch information
acidvegas committed Dec 27, 2023
1 parent 7cc0152 commit 2f20909
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 2f20909

Please sign in to comment.