func read() error { if len(os.Args) < 3 { return errors.New("not enough args") } path := os.Args[2] if regexp.MustCompile("\\.txt\\.lz4$").MatchString(path) { buf, err := common.ReadCompressedFile(path) if err != nil { return err } os.Stdout.Write(buf) } else { return errors.New("invalid file") } return nil }
func readLogFile(path string) ([]byte, error) { var buf []byte path = LogExtension.ReplaceAllString(path, "") buf, err := common.ReadCompressedFile(path + ".txt") if os.IsNotExist(err) { f, err := os.Open(path + ".txt") if os.IsNotExist(err) { return nil, ErrNotFound } buf, err = ioutil.ReadAll(f) if err != nil { return nil, err } } else if err != nil { return nil, err } return buf, nil }
func nicks() error { if len(os.Args) < 3 { return errors.New("not enough args") } path := os.Args[2] var data []byte data, err := common.ReadCompressedFile(path) if os.IsNotExist(err) { f, err := os.Open(path) if err != nil { return err } data, err = ioutil.ReadAll(f) if err != nil { return err } } else if err != nil { return err } r := bufio.NewReaderSize(bytes.NewReader(data), len(data)) nick := regexp.MustCompile("^\\[[^\\]]+\\]\\s*([a-zA-Z0-9\\_\\-]+):") nicks := common.NickList{} for { line, err := r.ReadSlice('\n') if err != nil { if err != io.EOF { return err } break } if ok := nick.Match(line); ok { match := nick.FindSubmatch(line) nicks.Add(string(match[1])) } } if err := nicks.WriteTo(regexp.MustCompile("\\.txt(\\.lz4)?$").ReplaceAllString(path, ".nicks")); err != nil { return err } return nil }