From 077f1efb6f901423a05238fb8c1ab38378e568db Mon Sep 17 00:00:00 2001 From: Joren Date: Fri, 6 Sep 2024 14:36:46 +0200 Subject: [PATCH] Add support for UTF-8 w/ BOM --- downloaders.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/downloaders.go b/downloaders.go index d92b1c6..dd77c35 100644 --- a/downloaders.go +++ b/downloaders.go @@ -24,6 +24,8 @@ func processInputFile(inputFile string) error { return fmt.Errorf("error reading file %s: %v", inputFile, err) } + byteValue = removeBOM(byteValue) + var items Items err = json.Unmarshal(byteValue, &items) if err != nil { @@ -42,6 +44,13 @@ func processInputFile(inputFile string) error { return nil } +func removeBOM(input []byte) []byte { + if len(input) >= 3 && input[0] == 0xEF && input[1] == 0xBB && input[2] == 0xBF { + return input[3:] + } + return input +} + func downloadFile(item Item) error { fmt.Println("Downloading:", item.Filename)