Skip to content

Commit

Permalink
Add bzip2 decompression capability, remove unnecessary MRT Reader closes
Browse files Browse the repository at this point in the history
  • Loading branch information
vista- authored and fujita committed Jun 13, 2024
1 parent 21c157a commit abc1152
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cmd/gobgp/mrt.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package main

import (
"compress/bzip2"
"compress/gzip"
"fmt"
"io"
Expand All @@ -33,20 +34,21 @@ import (
)

func injectMrt() error {
var reader io.ReadCloser
var reader io.Reader
fileReader, err := os.Open(mrtOpts.Filename)
if err != nil {
return fmt.Errorf("failed to open file: %s", err)
}
defer fileReader.Close()

if strings.HasSuffix(mrtOpts.Filename, ".gz") {
gzReader, err := gzip.NewReader(fileReader)
if err != nil {
return fmt.Errorf("failed to open gzip file: %s", err)
}
defer gzReader.Close()
reader = gzReader
} else if strings.HasSuffix(mrtOpts.Filename, ".bz2") {
bz2Reader := bzip2.NewReader(fileReader)
reader = bz2Reader
} else {
reader = fileReader
}
Expand Down

0 comments on commit abc1152

Please sign in to comment.