package cmd import ( "fmt" "golang.flu0r1ne.net/zsu/snap" "os" "io" ) func Cat(params []string) { n_params := len(params) if(n_params == 0) { die.Fatal("Reference file is required") } if(n_params > 2) { die.Fatal("Too many arguments provided") } reference := params[0] snapish := "@" if(n_params > 1) { snapish = params[1] } snapRef := snap.ToRelative(snapish) oracle := snap.GetOracle(reference) path := oracle.PathTo(snapRef) file, err := os.Open(path) if err != nil { die.Fatalf("Could not open snapshot %s\nError: %v", path, err) } defer func() { if err = file.Close(); err != nil { die.Fatalf("Could not close file %s\nError: %v", path, err) } }() buf := make([]byte, 10*1024*1024) //10Ki for { n, err := file.Read(buf) if n > 0 { fmt.Printf("%s", buf[:n]) } if err == io.EOF { break } if err != nil { die.Fatalf("Encountered error while reading file: %v", err) } } }