diff --git a/data/output.txt b/data/output.txt index f5ca075..bc9c22d 100644 Binary files a/data/output.txt and b/data/output.txt differ diff --git a/data/output_decode.txt b/data/output_decode.txt new file mode 100644 index 0000000..9fe467f Binary files /dev/null and b/data/output_decode.txt differ diff --git a/huffman/huffman.go b/huffman/huffman.go index eaff4bc..cf12b7e 100644 --- a/huffman/huffman.go +++ b/huffman/huffman.go @@ -151,5 +151,9 @@ func DeserializeData(data []byte, verbose bool) (string, error) { content := Decode(root, serializedData, int(bitLength), verbose) + if content == "" { + return "", errors.New("failed to decode data") + } + return content, nil } diff --git a/huffman/huffman_util.go b/huffman/huffman_util.go index 7c4040a..1a7116b 100644 --- a/huffman/huffman_util.go +++ b/huffman/huffman_util.go @@ -130,7 +130,6 @@ func bitStringToBytes(s string) []byte { result[byteIndex] |= 1 << bitIndex } } - return result } diff --git a/main.go b/main.go index ae03a74..00f40f8 100644 --- a/main.go +++ b/main.go @@ -15,9 +15,11 @@ func main() { flag.Parse() data, err := os.ReadFile(*inputFile) + if err != nil { log.Fatalf("Failed to read file %s: %v", *inputFile, err) } + var outputData []byte if *decode { diff --git a/todo.txt b/todo.txt index 5afaee3..7748dd6 100644 --- a/todo.txt +++ b/todo.txt @@ -1,4 +1,4 @@ ✔️ add lipgloss to make it look better ✔️ add a serialization function for the table and the encoded data -- use charmbracelet/vhs to make a cool README file +✔️ use charmbracelet/vhs to make a cool README file