Skip to content

Instantly share code, notes, and snippets.

@rohitpaulk
Last active March 17, 2020 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rohitpaulk/b67df434521772fdef56a5ba9f0acc69 to your computer and use it in GitHub Desktop.
Save rohitpaulk/b67df434521772fdef56a5ba9f0acc69 to your computer and use it in GitHub Desktop.
Write a huge file in Go
package main
import (
"fmt"
"os"
"strings"
)
func main() {
f, err := os.Create("/tmp/dat2")
if err != nil {
panic(err)
}
defer f.Close()
fmt.Println("Writing data...")
gbs := 30 // How many GBs you want to write
kb := strings.Repeat("1234567890", 100) // 10 bytes * 100 = 1KB string
mb := strings.Repeat(kb, 1000) // 1000 bytes * 1KB = 1MB string
for i := 0; i < gbs*1000; i++ {
_, err := f.Write([]byte(mb))
if err != nil {
panic(err)
}
if i%100 == 0 {
fmt.Printf("Wrote %d/%dk MBs\n", i, gbs)
}
}
fmt.Println("Writing done.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment