1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-08 05:47:07 +09:00

GO-1322 Fix stacktrace decoder

This commit is contained in:
kirillston 2023-04-25 18:17:59 +02:00 committed by Mikhail Iudin
parent a1c4e01c0a
commit 445367a76f
No known key found for this signature in database
GPG key ID: FAAAA8BAABDFF1C0

View file

@ -5,37 +5,57 @@ import (
"bytes"
"compress/gzip"
"encoding/base64"
"errors"
"fmt"
"io"
"os"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
fmt.Print("Enter base64 encoded string: ")
var (
err error
reader io.Reader
file = os.Stdin
)
if len(os.Args) == 2 {
if file, err = os.Open(os.Args[1]); err != nil {
fmt.Println("Error opening file:", err)
return
}
} else {
fmt.Print("Enter base64 encoded string: ")
}
scanner := bufio.NewScanner(file)
scanner.Scan()
base64Str := scanner.Text()
gzipBytes, err := base64.StdEncoding.DecodeString(base64Str)
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)) {
fmt.Println("Try to pass base64 in a file. Filename should be the argument of the program")
}
return
}
reader, err := gzip.NewReader(bytes.NewReader(gzipBytes))
br := bytes.NewReader(gzipBytes)
zr, err := gzip.NewReader(br)
if err != nil {
fmt.Println("Error creating gzip reader:", err)
return
reader = br
} else {
reader = zr
defer zr.Close()
}
defer reader.Close()
result := ""
buf := make([]byte, 1024)
for {
n, err := reader.Read(buf)
result += string(buf[:n])
if err != nil {
break
}
result += string(buf[:n])
}
fmt.Println(result)