Created
October 5, 2021 18:34
-
-
Save packrat386/9377d1eee33c1da092904e6238507399 to your computer and use it in GitHub Desktop.
Fill up your disk and tell you when it's full
This file contains 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
package main | |
import ( | |
"crypto/rand" | |
"encoding/hex" | |
"fmt" | |
"io" | |
"os" | |
) | |
func uuid() string { | |
id := make([]byte, 16) | |
io.ReadFull(rand.Reader, id) | |
id[6] &= 0x0F // clear version | |
id[6] |= 0x40 // set version to 4 (random uuid) | |
id[8] &= 0x3F // clear variant | |
id[8] |= 0x80 // set to IETF variant | |
return hex.EncodeToString(id) | |
} | |
func main() { | |
oneKB := make([]byte, 1000) | |
io.ReadFull(rand.Reader, oneKB) | |
count := 0 | |
for { | |
if count%1000 == 0 { | |
fmt.Printf("MB #%d\n", count/1000) | |
} | |
err := os.WriteFile(uuid(), oneKB, 0666) | |
if err != nil { | |
fmt.Printf("Errored at count '%d': %s\n", count, err) | |
os.Exit(1) | |
} | |
count++ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment