forked from containers/storage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Giuseppe Scrivano <[email protected]>
- Loading branch information
Showing
2 changed files
with
50 additions
and
8 deletions.
There are no files selected for viewing
19 changes: 11 additions & 8 deletions
19
pkg/archive/archive_zstd.go → pkg/archive/archive_zstd_cgo.go
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 |
---|---|---|
@@ -1,41 +1,44 @@ | ||
// +build linux,cgo | ||
|
||
package archive | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/klauspost/compress/zstd" | ||
zstd "github.com/valyala/gozstd" | ||
) | ||
|
||
type wrapperZstdDecoder struct { | ||
decoder *zstd.Decoder | ||
decoder *zstd.Reader | ||
} | ||
|
||
func (w *wrapperZstdDecoder) Close() error { | ||
w.decoder.Close() | ||
w.decoder.Release() | ||
return nil | ||
} | ||
|
||
func (w *wrapperZstdDecoder) DecodeAll(input, dst []byte) ([]byte, error) { | ||
return w.decoder.DecodeAll(input, dst) | ||
return zstd.Decompress(dst, input) | ||
} | ||
|
||
func (w *wrapperZstdDecoder) Read(p []byte) (int, error) { | ||
return w.decoder.Read(p) | ||
} | ||
|
||
func (w *wrapperZstdDecoder) Reset(r io.Reader) error { | ||
return w.decoder.Reset(r) | ||
w.decoder.Reset(r, nil) | ||
return nil | ||
} | ||
|
||
func (w *wrapperZstdDecoder) WriteTo(wr io.Writer) (int64, error) { | ||
return w.decoder.WriteTo(wr) | ||
} | ||
|
||
func zstdReader(buf io.Reader) (io.ReadCloser, error) { | ||
decoder, err := zstd.NewReader(buf) | ||
return &wrapperZstdDecoder{decoder: decoder}, err | ||
decoder := zstd.NewReader(buf) | ||
return &wrapperZstdDecoder{decoder: decoder}, nil | ||
} | ||
|
||
func zstdWriter(dest io.Writer) (io.WriteCloser, error) { | ||
return zstd.NewWriter(dest) | ||
return zstd.NewWriter(dest), nil | ||
} |
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,39 @@ | ||
// +build !linux !cgo | ||
|
||
package archive | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
) | ||
|
||
type wrapperZstdDecoder struct { | ||
} | ||
|
||
func (w *wrapperZstdDecoder) Close() error { | ||
return fmt.Errorf("zstd not supported without cgo") | ||
} | ||
|
||
func (w *wrapperZstdDecoder) DecodeAll(input, dst []byte) ([]byte, error) { | ||
return nil, fmt.Errorf("zstd not supported without cgo") | ||
} | ||
|
||
func (w *wrapperZstdDecoder) Read(p []byte) (int, error) { | ||
return -1, fmt.Errorf("zstd not supported without cgo") | ||
} | ||
|
||
func (w *wrapperZstdDecoder) Reset(r io.Reader) error { | ||
return fmt.Errorf("zstd not supported without cgo") | ||
} | ||
|
||
func (w *wrapperZstdDecoder) WriteTo(wr io.Writer) (int64, error) { | ||
return -1, fmt.Errorf("zstd not supported without cgo") | ||
} | ||
|
||
func zstdReader(buf io.Reader) (io.ReadCloser, error) { | ||
return nil, fmt.Errorf("zstd not supported without cgo") | ||
} | ||
|
||
func zstdWriter(dest io.Writer) (io.WriteCloser, error) { | ||
return nil, fmt.Errorf("zstd not supported without cgo") | ||
} |