MCPcopy Create free account
hub / github.com/cli/cli / ExtractZip

Function ExtractZip

internal/zip/zip.go:21–31  ·  view source on GitHub ↗

ExtractZip extracts the contents of a zip archive to destDir. Entries that would escape destDir lexically are skipped.

(zr *zip.Reader, destDir *safepaths.Root)

Source from the content-addressed store, hash-verified

19// ExtractZip extracts the contents of a zip archive to destDir.
20// Entries that would escape destDir lexically are skipped.
21func ExtractZip(zr *zip.Reader, destDir *safepaths.Root) error {
22 for _, zf := range zr.File {
23 if err := extractZipFile(zf, destDir); err != nil {
24 if _, ok := errors.AsType[safepaths.PathTraversalError](err); ok {
25 continue
26 }
27 return fmt.Errorf("error extracting %q: %w", zf.Name, err)
28 }
29 }
30 return nil
31}
32
33func extractZipFile(zf *zip.File, dest *safepaths.Root) (extractErr error) {
34 zm := zf.Mode()

Callers 1

Test_extractZipFunction · 0.85

Calls 2

extractZipFileFunction · 0.85
ErrorfMethod · 0.65

Tested by 1

Test_extractZipFunction · 0.68