From 9a226b8cd4cb55c2e630ee70e3152081410e1544 Mon Sep 17 00:00:00 2001 From: k1574 Date: Thu, 28 Jan 2021 05:39:37 +0500 Subject: [PATCH] cat: block size option added. --- cat/cat.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cat/cat.go b/cat/cat.go index a7aef1c..49bf202 100644 --- a/cat/cat.go +++ b/cat/cat.go @@ -7,6 +7,10 @@ import( "fmt" ) +var( + blockSize int +) + func cat(p string) error { f, e := os.Open(p) if e != nil { @@ -18,7 +22,7 @@ func cat(p string) error { } func fcat(f *os.File) error { - b := make([]byte, 512) + b := make([]byte, blockSize) for { n, e := f.Read(b) if n>0 { @@ -38,8 +42,9 @@ func Run(args []string) int { arg0 := args[0] args = args[1:] flagSet := flag.NewFlagSet(arg0, flag.ExitOnError) + flagSet.IntVar(&blockSize, "bs", 512, "block size") flagSet.Usage = func() { - fmt.Fprintf(os.Stderr, "Usage of %s: %s [files]\n", arg0, arg0) + fmt.Fprintf(os.Stderr, "usage: %s [options] [files]\n", arg0) flagSet.PrintDefaults() } flagSet.Parse(args)