Futil is a simple file utility command-line application written in Go. It provides basic file operations such as counting the number of lines in a file and calculating the checksum of files using various algorithms (MD5, SHA1, SHA256). The tool supports reading from both files and standard input.
- Go: Ensure that Go (1.19 or later) is installed on your machine. You can download it from here.
- Make: Ensure that
makeis installed. On Linux and macOS, it is usually pre-installed. For Windows users, you can installmakevia GNUWin or by using a Windows Subsystem for Linux (WSL).
-
Clone the repository:
git clone https://github.com/Largeb0525/futil.git
-
Build the application using make:
make install
-
Line Count
- Count the number of lines in a specified file or standard input.
- Command:
Example:
futil linecount -f <filename>
futil linecount -f myfile.txt
-
Checksum Calculation
- Calculate the MD5, SHA1, or SHA256 checksum of a file or standard input.
- Command:
Example:
futil checksum -f <filename> --md5|--sha1|--sha256
futil checksum -f myfile.txt --md5
-
Error Handling
- Handles various error cases such as non-existent files, directories, and binary files.
The application is designed using the cobra package to provide an extensible command-line interface (CLI). Each command (such as linecount and checksum) is implemented as a separate module, making the tool easily maintainable and scalable for adding new features in the future.
-
Commands
linecount: Counts the number of lines in a given file or standard input.checksum: Calculates the checksum of a file using the specified algorithm (MD5, SHA1, or SHA256).
-
Binary File Detection
- For both commands, binary file detection is implemented. If the file is binary, the tool will return an error message:
error: Cannot do linecount or checksum for binary file '<filename>'
- For both commands, binary file detection is implemented. If the file is binary, the tool will return an error message:
- Cobra - A library for creating powerful modern CLI applications.
-
Large File Handling: Processing very large files (several GBs or more) may result in high memory usage and slow performance. This can be mitigated by optimizing IO operations, but it's recommended to use the tool for small to medium-sized files. Future versions may include better handling for large files.
-
Binary File Detection: The detection of binary files is done using a simple heuristic (checking for non-printable characters). This method might not be completely accurate for all file types, especially for files containing mixed binary and text content.