mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-07 21:37:04 +09:00
GO-1322 Introduce constants
This commit is contained in:
parent
445367a76f
commit
27a18f4081
1 changed files with 11 additions and 4 deletions
|
@ -11,14 +11,21 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
const (
|
||||
argsLenWithFile = 2
|
||||
fileArgNumber = 1
|
||||
stdinSizeOnLinux = 4092
|
||||
bufferSize = 1024
|
||||
)
|
||||
|
||||
func main() {
|
||||
var (
|
||||
err error
|
||||
reader io.Reader
|
||||
file = os.Stdin
|
||||
)
|
||||
if len(os.Args) == 2 {
|
||||
if file, err = os.Open(os.Args[1]); err != nil {
|
||||
if len(os.Args) == argsLenWithFile {
|
||||
if file, err = os.Open(os.Args[fileArgNumber]); err != nil {
|
||||
fmt.Println("Error opening file:", err)
|
||||
return
|
||||
}
|
||||
|
@ -33,7 +40,7 @@ func main() {
|
|||
if err != nil {
|
||||
fmt.Println("Error decoding base64:", err)
|
||||
// On some OS stdin is limited with 4092 bytes
|
||||
if errors.Is(err, base64.CorruptInputError(4092)) {
|
||||
if errors.Is(err, base64.CorruptInputError(stdinSizeOnLinux)) {
|
||||
fmt.Println("Try to pass base64 in a file. Filename should be the argument of the program")
|
||||
}
|
||||
return
|
||||
|
@ -49,7 +56,7 @@ func main() {
|
|||
}
|
||||
|
||||
result := ""
|
||||
buf := make([]byte, 1024)
|
||||
buf := make([]byte, bufferSize)
|
||||
for {
|
||||
n, err := reader.Read(buf)
|
||||
result += string(buf[:n])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue