List returns all files under the specified path to calculate the signature
()
| 189 | |
| 190 | // List returns all files under the specified path to calculate the signature |
| 191 | func (s *Scanner) List() ([]*Result, error) { |
| 192 | res := make([]*Result, 0) |
| 193 | if IsFile(s.Path) { |
| 194 | md5, err := Md5(s.Path) |
| 195 | if err != nil { |
| 196 | return nil, err |
| 197 | } |
| 198 | res = append(res, &Result{ |
| 199 | Index: 1, |
| 200 | Path: s.Path, |
| 201 | Code: md5, |
| 202 | }) |
| 203 | return res, nil |
| 204 | } |
| 205 | |
| 206 | if files, err := Files(s.Path); err != nil { |
| 207 | return nil, err |
| 208 | } else { |
| 209 | for i, v := range files { |
| 210 | if md5, err := Md5(v); err != nil { |
| 211 | return nil, err |
| 212 | } else { |
| 213 | res = append(res, &Result{ |
| 214 | Index: i + 1, |
| 215 | Path: v, |
| 216 | Code: md5, |
| 217 | }) |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | return res, nil |
| 222 | } |
| 223 | |
| 224 | // HexDump convert path content to hexadecimal |
| 225 | func (s *Scanner) HexDump() (string, error) { |