From cca2a8fc8f8dea245b687933f0282bc9c7b121c0 Mon Sep 17 00:00:00 2001 From: Jonas Stendahl Date: Sat, 18 Aug 2018 17:39:41 +0200 Subject: [PATCH] rar: Add back support for multipart rar files (#72) --- rar.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/rar.go b/rar.go index 86f8a63d..3ff61da6 100644 --- a/rar.go +++ b/rar.go @@ -64,6 +64,22 @@ func (rarFormat) Read(input io.Reader, destination string) error { return fmt.Errorf("read: failed to create reader: %v", err) } + return extract(rr, destination) +} + +// Open extracts the RAR file at source and puts the contents +// into destination. +func (rarFormat) Open(source, destination string) error { + rf, err := rardecode.OpenReader(source, "") + if err != nil { + return fmt.Errorf("%s: failed to open file: %v", source, err) + } + defer rf.Close() + + return extract(&rf.Reader, destination) +} + +func extract(rr *rardecode.Reader, destination string) error { for { header, err := rr.Next() if err == io.EOF { @@ -102,15 +118,3 @@ func (rarFormat) Read(input io.Reader, destination string) error { return nil } - -// Open extracts the RAR file at source and puts the contents -// into destination. -func (rarFormat) Open(source, destination string) error { - rf, err := os.Open(source) - if err != nil { - return fmt.Errorf("%s: failed to open file: %v", source, err) - } - defer rf.Close() - - return Rar.Read(rf, destination) -}