Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
rar: Add back support for multipart rar files (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
jyggen authored and mholt committed Aug 18, 2018
1 parent 85d3d0b commit cca2a8f
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions rar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

0 comments on commit cca2a8f

Please # to comment.