// Uncompress with a known output size. len(out) should be equal to
// the length of the uncompressed out.
511988
func Uncompress(in, out []byte) (error) {
	if int(C.LZ4_decompress_safe(p(in), p(out), clen(in), clen(out))) < 0 {
		return errors.New("Malformed compression stream")
	}

	return nil
}
380105
func UncompressLog(log string) (_ io.ReadCloser, retErr error) {
	if !strings.HasSuffix(log, compressSuffix) {
		return nil, fmt.Errorf("log is not compressed")
	}
	f, err := os.Open(log)
	if err != nil {
		return nil, fmt.Errorf("failed to open log: %v", err)
	}
	defer func() {
		if retErr != nil {
			f.Close()
		}
	}()
	r, err := gzip.NewReader(f)
	if err != nil {
		return nil, fmt.Errorf("failed to create gzip reader: %v", err)
	}
	return &compressReadCloser{f: f, Reader: r}, nil
}
873179
func Truncate(formatter Formatter, length int) Formatter {
	return func(buffer Buffer, event *cue.Event) {
		tmp := GetBuffer()
		defer ReleaseBuffer(tmp)

		formatter(tmp, event)
		bytes := tmp.Bytes()
		if len(bytes) > length {
			bytes = bytes[:length]
		}
		buffer.Append(bytes)
	}
}
536609
func (p *PublicKey) SerializeUncompressed() []byte {
	b := make([]byte, 0, PubKeyBytesLenUncompressed)
	b = append(b, pubkeyUncompressed)
	b = paddedAppend(32, b, p.X.Bytes())
	return paddedAppend(32, b, p.Y.Bytes())
}
1201937
func compress(b []byte, lvl int) []byte {
	var buf bytes.Buffer
	w, err := flate.NewWriter(&buf, lvl)
	if err != nil {
		log.Fatal(err)
	}
	if _, err := io.Copy(w, bytes.NewReader(b)); err != nil {
		log.Fatal(err)
	}
	if err := w.Close(); err != nil {
		log.Fatal(err)
	}
	return buf.Bytes()
}
337019
func Unzip(r io.Reader, destPath string) (string, error) {
	var (
		zr  *zip.Reader
		err error
	)

	if f, ok := r.(*os.File); ok {
		fstat, err := f.Stat()
		if err != nil {
			return "", err
		}
		zr, err = zip.NewReader(f, fstat.Size())
	} else {
		data, err := ioutil.ReadAll(r)
		if err != nil {
			return "", err
		}
		memReader := bytes.NewReader(data)
		zr, err = zip.NewReader(memReader, memReader.Size())
	}

	if err != nil {
		return "", err
	}

	return unpackZip(zr, destPath)
}
1284481
func (bz *Bz2) Decompress(in io.Reader, out io.Writer) error {
	r, err := bzip2.NewReader(in, nil)
	if err != nil {
		return err
	}
	defer r.Close()
	_, err = io.Copy(out, r)
	return err
}
279743
func Out(format string, a ...interface{}) error {
	p := message.NewPrinter(preferredLanguage)
	if outFile == nil {
		if _, err := p.Fprintf(os.Stdout, "(stdout unset)"+format, a...); err != nil {
			return err
		}
		return fmt.Errorf("no output file has been set")
	}
	_, err := p.Fprintf(outFile, format, a...)
	return err
}
147757
func (l *LargeFile) GetSize() int {
	if l == nil || l.Size == nil {
		return 0
	}
	return *l.Size
}
401126
func DetectCompression(source []byte) Compression {
	for compression, m := range map[Compression][]byte{
		Bzip2: {0x42, 0x5A, 0x68},
		Gzip:  {0x1F, 0x8B, 0x08},
		Xz:    {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00},
	} {
		if len(source) < len(m) {
			logrus.Debug("Len too short")
			continue
		}
		if bytes.Equal(m, source[:len(m)]) {
			return compression
		}
	}
	return Uncompressed
}
763829
func (lz *Lz4) Compress(in io.Reader, out io.Writer) error {
	w := lz4.NewWriter(out)
	w.Header.CompressionLevel = lz.CompressionLevel
	defer w.Close()
	_, err := io.Copy(w, in)
	return err
}
312384
func (gz *Gzip) Compress(content []byte) ([]byte, error) {
	if !gz.Options.Compress {
		return content, nil
	}

	// method
	var m int
	switch gz.Options.Method {
	case "NoCompression":
		m = flate.NoCompression
		break
	case "BestSpeed":
		m = flate.BestSpeed
		break
	case "BestCompression":
		m = flate.BestCompression
		break
	default:
		m = flate.DefaultCompression
		break
	}

	// compress
	var b bytes.Buffer
	w, err := gzip.NewWriterLevel(&b, m)
	if err != nil {
		return nil, err
	}

	// insert content
	_, err = w.Write(content)
	if err != nil {
		return nil, err
	}

	err = w.Close()
	if err != nil {
		return nil, err
	}

	// compressed content
	return b.Bytes(), nil
}
877779
func (g *Generator) Out() {
	if len(g.indent) > 0 {
		g.indent = g.indent[1:]
	}
}
1194561
func (s *Scratch) decompress() error {
	br := &s.bits
	br.init(s.br.unread())

	var s1, s2 decoder
	// Initialize and decode first state and symbol.
	s1.init(br, s.decTable, s.actualTableLog)
	s2.init(br, s.decTable, s.actualTableLog)

	// Use temp table to avoid bound checks/append penalty.
	var tmp = s.ct.tableSymbol[:256]
	var off uint8

	// Main part
	if !s.zeroBits {
		for br.off >= 8 {
			br.fillFast()
			tmp[off+0] = s1.nextFast()
			tmp[off+1] = s2.nextFast()
			br.fillFast()
			tmp[off+2] = s1.nextFast()
			tmp[off+3] = s2.nextFast()
			off += 4
			if off == 0 {
				s.Out = append(s.Out, tmp...)
			}
		}
	} else {
		for br.off >= 8 {
			br.fillFast()
			tmp[off+0] = s1.next()
			tmp[off+1] = s2.next()
			br.fillFast()
			tmp[off+2] = s1.next()
			tmp[off+3] = s2.next()
			off += 4
			if off == 0 {
				s.Out = append(s.Out, tmp...)
				off = 0
				if len(s.Out) >= s.DecompressLimit {
					return fmt.Errorf("output size (%d) > DecompressLimit (%d)", len(s.Out), s.DecompressLimit)
				}
			}
		}
	}
	s.Out = append(s.Out, tmp[:off]...)

	// Final bits, a bit more expensive check
	for {
		if s1.finished() {
			s.Out = append(s.Out, s1.final(), s2.final())
			break
		}
		br.fill()
		s.Out = append(s.Out, s1.next())
		if s2.finished() {
			s.Out = append(s.Out, s2.final(), s1.final())
			break
		}
		s.Out = append(s.Out, s2.next())
		if len(s.Out) >= s.DecompressLimit {
			return fmt.Errorf("output size (%d) > DecompressLimit (%d)", len(s.Out), s.DecompressLimit)
		}
	}
	return br.close()
}
855467
func (o *LargeObject) Truncate(size int64) (err error) {
	if o.lo.Has64 {
		_, err = o.lo.fp.CallFn("lo_truncate64", []fpArg{fpIntArg(o.fd), fpInt64Arg(size)})
	} else {
		_, err = o.lo.fp.CallFn("lo_truncate", []fpArg{fpIntArg(o.fd), fpIntArg(int32(size))})
	}
	return
}
979808
func (b *Buffer) Truncate(n int) {
	if n == 0 {
		b.off = 0
		b.buf = b.buf[0:0]
	} else {
		b.buf = b.buf[0 : b.off+n]
	}
}
754806
func (bz *Bz2) Compress(in io.Reader, out io.Writer) error {
	w, err := bzip2.NewWriter(out, &bzip2.WriterConfig{
		Level: bz.CompressionLevel,
	})
	if err != nil {
		return err
	}
	defer w.Close()
	_, err = io.Copy(w, in)
	return err
}