-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Pull API/Options from user perspective. Simplify progress han…
…dling
- Loading branch information
1 parent
9c57501
commit 6da9d44
Showing
5 changed files
with
92 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package transporter | ||
|
||
import ( | ||
"github.com/google/go-containerregistry/pkg/name" | ||
v1 "github.com/google/go-containerregistry/pkg/v1" | ||
"github.com/mobileinf/geranos/pkg/layout" | ||
) | ||
|
||
func ReadManifest(src string, opt ...Option) (*v1.Manifest, error) { | ||
opts := makeOptions(opt...) | ||
ref, err := name.ParseReference(src, name.StrictValidation) | ||
if err != nil { | ||
return nil, err | ||
} | ||
lm := layout.NewMapper(opts.imagesPath, opts.dirimageOptions...) | ||
return lm.ReadManifest(ref) | ||
} | ||
|
||
func ReadDigest(src string, opt ...Option) (v1.Hash, error) { | ||
opts := makeOptions(opt...) | ||
ref, err := name.ParseReference(src, name.StrictValidation) | ||
if err != nil { | ||
return v1.Hash{}, err | ||
} | ||
lm := layout.NewMapper(opts.imagesPath, opts.dirimageOptions...) | ||
return lm.ReadDigest(ref) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package transporter | ||
|
||
import ( | ||
"fmt" | ||
"github.com/mobileinf/geranos/pkg/dirimage" | ||
"strings" | ||
) | ||
|
||
type ProgressUpdate dirimage.ProgressUpdate | ||
|
||
func PrintProgress(progress <-chan ProgressUpdate) { | ||
updateProgress := func(progress int64) { | ||
buffer := new(strings.Builder) | ||
fmt.Fprintf(buffer, "\rProgress: [%-100s] %d%%", strings.Repeat("=", int(progress)), progress) | ||
fmt.Print(buffer.String()) | ||
} | ||
last := int64(0) | ||
for p := range progress { | ||
current := 100 * p.BytesProcessed / p.BytesTotal | ||
if current != last { | ||
updateProgress(current) | ||
} | ||
last = current | ||
} | ||
fmt.Printf("\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters