package main

import (
	"errors"
	"fmt"
	"os"
)

func fileLen(filename string) (int, error) {
	const blockSize = 128
	file, err := os.Open(filename)
	if err != nil {
		fmt.Println("Could not open file!")
		return 0, err
	}
	defer file.Close()
	dataBlock := make([]byte, blockSize)
	totalCount := 0
	for {
		count, err := file.Read(dataBlock)
		if err != nil {
			return 0, err
		}
		totalCount += count
		if count < blockSize {
			break
		}
	}
	return totalCount, nil
}

func main() {
	if len(os.Args) < 2 {
		err := errors.New("Program doesn't have any arguments. Please pass argument")
		fmt.Println(err)
		return
	}
	fileSize, err := fileLen(os.Args[1])
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(fileSize)
}
