Skip to content
This repository has been archived by the owner on Oct 29, 2023. It is now read-only.

Commit

Permalink
add: random utf8 file generation
Browse files Browse the repository at this point in the history
  • Loading branch information
rgprajeen committed Apr 22, 2023
1 parent 5eb12fe commit f5cc8b2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/spawn/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/prajeenrg/spawn/pkg/image"
"github.com/prajeenrg/spawn/pkg/text"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -50,5 +51,19 @@ func main() {
return nil
},
},
{
Name: "text",
Usage: "generate dummy text files",
Flags: []cli.Flag{
&cli.StringFlag{Name: "file", Aliases: []string{"f"}, Required: true},
&cli.UintFlag{Name: "size", Aliases: []string{"s"}, Value: 100},
},
Action: func(ctx *cli.Context) error {
name := ctx.String("file")
size := ctx.Uint("size")
text.MakeDummyFile(name, size)
return nil
},
},
}
}
19 changes: 19 additions & 0 deletions pkg/text/text.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package text

import (
"log"

"github.com/prajeenrg/spawn/pkg/util"
)

func MakeDummyFile(name string, size uint) {
file := util.CreateFile(name)
defer file.Close()

_, b := util.GetRandomBytes(size)
_, err := file.Write(b)

if err != nil {
log.Fatalf("Writing to %s failed", name)
}
}

0 comments on commit f5cc8b2

Please sign in to comment.