检查指定文件中是否包含文本
(path, str string)
| 174 | |
| 175 | // 检查指定文件中是否包含文本 |
| 176 | func (fs *fileOperation) CheckFileContainsStr(path, str string) (bool, error) { |
| 177 | b := false |
| 178 | cmp := []byte(str) |
| 179 | f, err := os.Open(path) |
| 180 | if err != nil { |
| 181 | return false, err |
| 182 | } |
| 183 | defer f.Close() |
| 184 | input := bufio.NewScanner(f) |
| 185 | |
| 186 | for input.Scan() { |
| 187 | info := input.Bytes() |
| 188 | if bytes.Contains(info, cmp) { |
| 189 | b = true |
| 190 | break |
| 191 | } |
| 192 | |
| 193 | tokens := bytes.SplitN(input.Bytes(), []byte(" "), 10) |
| 194 | totalSize += float64(len(input.Bytes())) |
| 195 | if len(tokens) < 9 { |
| 196 | continue |
| 197 | } |
| 198 | strconv.ParseInt(string(tokens[8]), 10, 0) |
| 199 | } |
| 200 | totalSize = totalSize / (1 << 20) |
| 201 | return b, nil |
| 202 | } |
no outgoing calls
no test coverage detected