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

Commit

Permalink
Add ArchiveAsync support to CompressedArchive
Browse files Browse the repository at this point in the history
  • Loading branch information
ncw committed Feb 7, 2023
1 parent fedac4a commit ef94c8d
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions formats.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,23 @@ func (caf CompressedArchive) Archive(ctx context.Context, output io.Writer, file
return caf.Archival.Archive(ctx, output, files)
}

// ArchiveAsync adds files to the output archive while compressing the result asynchronously.
func (caf CompressedArchive) ArchiveAsync(ctx context.Context, output io.Writer, jobs <-chan ArchiveAsyncJob) error {
do, ok := caf.Archival.(ArchiverAsync)
if !ok {
return fmt.Errorf("%s archive does not support async writing", caf.Name())
}
if caf.Compression != nil {
wc, err := caf.Compression.OpenWriter(output)
if err != nil {
return err
}
defer wc.Close()
output = wc
}
return do.ArchiveAsync(ctx, output, jobs)
}

// Extract reads files out of an archive while decompressing the results.
func (caf CompressedArchive) Extract(ctx context.Context, sourceArchive io.Reader, pathsInArchive []string, handleFile FileHandler) error {
if caf.Compression != nil {
Expand Down Expand Up @@ -358,7 +375,8 @@ var formats = make(map[string]Format)

// Interface guards
var (
_ Format = (*CompressedArchive)(nil)
_ Archiver = (*CompressedArchive)(nil)
_ Extractor = (*CompressedArchive)(nil)
_ Format = (*CompressedArchive)(nil)
_ Archiver = (*CompressedArchive)(nil)
_ ArchiverAsync = (*CompressedArchive)(nil)
_ Extractor = (*CompressedArchive)(nil)
)

0 comments on commit ef94c8d

Please sign in to comment.