Skip to content

Commit

Permalink
load cmd support gzip and bzip2
Browse files Browse the repository at this point in the history
Signed-off-by: ye.sijun <[email protected]>
  • Loading branch information
junnplus committed Dec 2, 2021
1 parent f92d4d9 commit cdf7710
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/nerdctl/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
package main

import (
"bufio"
"bytes"
"compress/bzip2"
"compress/gzip"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -68,6 +72,16 @@ func loadAction(cmd *cobra.Command, args []string) error {
in = f
}

inbuf := bufio.NewReader(in)
buff, _ := inbuf.Peek(3)
if bytes.HasPrefix(buff, []byte("\x1f\x8b")) {
in, _ = gzip.NewReader(inbuf)
} else if bytes.HasPrefix(buff, []byte("\x42\x5a\x68")) {
in = bzip2.NewReader(inbuf)
} else {
in = inbuf
}

allPlatforms, err := cmd.Flags().GetBool("all-platforms")
if err != nil {
return err
Expand Down

0 comments on commit cdf7710

Please sign in to comment.