summaryrefslogtreecommitdiff
path: root/vendor/github.com/ulikunitz/xz/lzmafilter.go
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2018-07-08 07:55:30 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-07-19 18:43:32 +0000
commit98703eb204923f06555605c648fc165a55214520 (patch)
treea407bae8b3489d4f9b0f0d0f228658bbfe95a38e /vendor/github.com/ulikunitz/xz/lzmafilter.go
parentc020db8cd21cb221cfbe36b264e0ec02999596ed (diff)
downloadpodman-98703eb204923f06555605c648fc165a55214520.tar.gz
podman-98703eb204923f06555605c648fc165a55214520.tar.bz2
podman-98703eb204923f06555605c648fc165a55214520.zip
Vendor in latest code for storage,image, buildah
vendor in containers/storage vendor in containers/image vendor in projectatomic/buildah Signed-off-by: Daniel J Walsh <dwalsh@redhat.com> Closes: #1114 Approved by: mheon
Diffstat (limited to 'vendor/github.com/ulikunitz/xz/lzmafilter.go')
-rw-r--r--vendor/github.com/ulikunitz/xz/lzmafilter.go117
1 files changed, 117 insertions, 0 deletions
diff --git a/vendor/github.com/ulikunitz/xz/lzmafilter.go b/vendor/github.com/ulikunitz/xz/lzmafilter.go
new file mode 100644
index 000000000..69cf5f7c2
--- /dev/null
+++ b/vendor/github.com/ulikunitz/xz/lzmafilter.go
@@ -0,0 +1,117 @@
+// Copyright 2014-2017 Ulrich Kunitz. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package xz
+
+import (
+ "errors"
+ "fmt"
+ "io"
+
+ "github.com/ulikunitz/xz/lzma"
+)
+
+// LZMA filter constants.
+const (
+ lzmaFilterID = 0x21
+ lzmaFilterLen = 3
+)
+
+// lzmaFilter declares the LZMA2 filter information stored in an xz
+// block header.
+type lzmaFilter struct {
+ dictCap int64
+}
+
+// String returns a representation of the LZMA filter.
+func (f lzmaFilter) String() string {
+ return fmt.Sprintf("LZMA dict cap %#x", f.dictCap)
+}
+
+// id returns the ID for the LZMA2 filter.
+func (f lzmaFilter) id() uint64 { return lzmaFilterID }
+
+// MarshalBinary converts the lzmaFilter in its encoded representation.
+func (f lzmaFilter) MarshalBinary() (data []byte, err error) {
+ c := lzma.EncodeDictCap(f.dictCap)
+ return []byte{lzmaFilterID, 1, c}, nil
+}
+
+// UnmarshalBinary unmarshals the given data representation of the LZMA2
+// filter.
+func (f *lzmaFilter) UnmarshalBinary(data []byte) error {
+ if len(data) != lzmaFilterLen {
+ return errors.New("xz: data for LZMA2 filter has wrong length")
+ }
+ if data[0] != lzmaFilterID {
+ return errors.New("xz: wrong LZMA2 filter id")
+ }
+ if data[1] != 1 {
+ return errors.New("xz: wrong LZMA2 filter size")
+ }
+ dc, err := lzma.DecodeDictCap(data[2])
+ if err != nil {
+ return errors.New("xz: wrong LZMA2 dictionary size property")
+ }
+
+ f.dictCap = dc
+ return nil
+}
+
+// reader creates a new reader for the LZMA2 filter.
+func (f lzmaFilter) reader(r io.Reader, c *ReaderConfig) (fr io.Reader,
+ err error) {
+
+ config := new(lzma.Reader2Config)
+ if c != nil {
+ config.DictCap = c.DictCap
+ }
+ dc := int(f.dictCap)
+ if dc < 1 {
+ return nil, errors.New("xz: LZMA2 filter parameter " +
+ "dictionary capacity overflow")
+ }
+ if dc > config.DictCap {
+ config.DictCap = dc
+ }
+
+ fr, err = config.NewReader2(r)
+ if err != nil {
+ return nil, err
+ }
+ return fr, nil
+}
+
+// writeCloser creates a io.WriteCloser for the LZMA2 filter.
+func (f lzmaFilter) writeCloser(w io.WriteCloser, c *WriterConfig,
+) (fw io.WriteCloser, err error) {
+ config := new(lzma.Writer2Config)
+ if c != nil {
+ *config = lzma.Writer2Config{
+ Properties: c.Properties,
+ DictCap: c.DictCap,
+ BufSize: c.BufSize,
+ Matcher: c.Matcher,
+ }
+ }
+
+ dc := int(f.dictCap)
+ if dc < 1 {
+ return nil, errors.New("xz: LZMA2 filter parameter " +
+ "dictionary capacity overflow")
+ }
+ if dc > config.DictCap {
+ config.DictCap = dc
+ }
+
+ fw, err = config.NewWriter2(w)
+ if err != nil {
+ return nil, err
+ }
+ return fw, nil
+}
+
+// last returns true, because an LZMA2 filter must be the last filter in
+// the filter list.
+func (f lzmaFilter) last() bool { return true }